#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<int> stary;
vector<int> nowy;
vector<bool> automat;
unsigned long long nww(unsigned long long a, unsigned long long b) {
unsigned long long x = a, y = b, c;
while (y != 0) {
c = x%y;
x = y;
y = c;
}
return((a * b) / x);
}
int main() {
ios_base::sync_with_stdio(false);
int n, k; //n is childs count //k is cycle length
cin >> n;
stary.resize(n);
nowy.resize(n);
for (int i = 0; i < n; i++) {
cin >> stary[i];
nowy[i] = stary[i];
}
scanf("%d", &k);
automat.resize(k);
string cykl;
cin >> cykl;
for (int i = 0; i < k; i++)
if (cykl[i] == 'W') automat[i] = 1;
unsigned long long steps = nww(n, k);
int i = 0, j = 0;
for (int f = 0; f < steps; f++) {
if (automat[j]) nowy[i]++;
else nowy[i]--;
if (nowy[i] == 0) {
cout << f;
return 0;
}
i++; i %= n;
j++; j %= k;
}
int r_max = 0, r = 0, h = 0;
for (int i = 0; i < nowy.size(); i++) {
if (nowy[i] < stary[i]) {
r = stary[i] - nowy[i];
if (r_max > r) {
r_max = r;
h = stary[i];
}
}
}
int o = h;
cout << ((h / r_max)*n) + (h%r_max)*n;
return 0;
}
//I know that it's incomplete ;-;
// max pierwsza < [1 000 000] to
/// [999 983]
/// a potem
/// [999 979]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include <iostream> #include <vector> #include <string> using namespace std; vector<int> stary; vector<int> nowy; vector<bool> automat; unsigned long long nww(unsigned long long a, unsigned long long b) { unsigned long long x = a, y = b, c; while (y != 0) { c = x%y; x = y; y = c; } return((a * b) / x); } int main() { ios_base::sync_with_stdio(false); int n, k; //n is childs count //k is cycle length cin >> n; stary.resize(n); nowy.resize(n); for (int i = 0; i < n; i++) { cin >> stary[i]; nowy[i] = stary[i]; } scanf("%d", &k); automat.resize(k); string cykl; cin >> cykl; for (int i = 0; i < k; i++) if (cykl[i] == 'W') automat[i] = 1; unsigned long long steps = nww(n, k); int i = 0, j = 0; for (int f = 0; f < steps; f++) { if (automat[j]) nowy[i]++; else nowy[i]--; if (nowy[i] == 0) { cout << f; return 0; } i++; i %= n; j++; j %= k; } int r_max = 0, r = 0, h = 0; for (int i = 0; i < nowy.size(); i++) { if (nowy[i] < stary[i]) { r = stary[i] - nowy[i]; if (r_max > r) { r_max = r; h = stary[i]; } } } int o = h; cout << ((h / r_max)*n) + (h%r_max)*n; return 0; } //I know that it's incomplete ;-; // max pierwsza < [1 000 000] to /// [999 983] /// a potem /// [999 979] |
English