#include <iostream> #include <vector> #include <set> #include <cstdio> #include <algorithm> using namespace std; bool jest = false; long long tab[1000001]; int n, m; long long j,i; string s; int main() { scanf("%d", &n); for(i = 0;i < n; ++i) scanf("%lld", &tab[i]); scanf("%d", &m); cin >> s; j = 0; i = 0; for(i = 0;i < 10000000; ++i) { if (s[i%m] == 'W') tab[i%n]++; else tab[i%n]--; if(tab[i%n] == 0) { printf("%lld",i + 1); jest = true; break; } } if(jest == false) printf("-1"); return 0; }
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 | #include <iostream> #include <vector> #include <set> #include <cstdio> #include <algorithm> using namespace std; bool jest = false; long long tab[1000001]; int n, m; long long j,i; string s; int main() { scanf("%d", &n); for(i = 0;i < n; ++i) scanf("%lld", &tab[i]); scanf("%d", &m); cin >> s; j = 0; i = 0; for(i = 0;i < 10000000; ++i) { if (s[i%m] == 'W') tab[i%n]++; else tab[i%n]--; if(tab[i%n] == 0) { printf("%lld",i + 1); jest = true; break; } } if(jest == false) printf("-1"); return 0; } |