#include <cstdio> #include <map> #include <vector> #include <cmath> using namespace std; long long n, m, t[1000111], i1, i2, zlicz; char c[1000111]; int main() { scanf("%d", &n); for(int i=1; i<=n; i++) { scanf("%d", &t[i]); } scanf("%d", &m); scanf("%s", c+1); i1=1, i2=1; while(true) { if(c[i2]=='W')t[i1]++; else t[i1]--; zlicz++; if(t[i1]==0){printf("%d", zlicz); return 0;} if(zlicz>10000000){printf("-1"); return 0;} i1++, i2++; if(i1>n)i1=1; if(i2>m)i2=1; } getchar(); getchar(); 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 | #include <cstdio> #include <map> #include <vector> #include <cmath> using namespace std; long long n, m, t[1000111], i1, i2, zlicz; char c[1000111]; int main() { scanf("%d", &n); for(int i=1; i<=n; i++) { scanf("%d", &t[i]); } scanf("%d", &m); scanf("%s", c+1); i1=1, i2=1; while(true) { if(c[i2]=='W')t[i1]++; else t[i1]--; zlicz++; if(t[i1]==0){printf("%d", zlicz); return 0;} if(zlicz>10000000){printf("-1"); return 0;} i1++, i2++; if(i1>n)i1=1; if(i2>m)i2=1; } getchar(); getchar(); return 0; } |