#include<iostream> using namespace std; int main() { long long n, m, counter, odd, i; int cash[1000000]; int game[1000000]; char a; counter = 0; cin >> n; for( i = 0; i < n; i++) { cin >> cash[i]; } cin >> m; for( i = 0; i < m; i++) { cin >> a; if (a == 'W') game[i] = 1; else game[i] = -1; } odd = 1; do { for( i = 0; i < m; i++) { cash[counter % n] += game[i]; counter++; if (cash[(counter-1) % n] == 0) { cout << counter; odd = 0; break; } } if (counter > 223372036854775807) { counter = -1; cout << counter; odd = 0; break; } }while(odd != 0); 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 38 39 40 41 42 43 44 45 46 47 48 49 | #include<iostream> using namespace std; int main() { long long n, m, counter, odd, i; int cash[1000000]; int game[1000000]; char a; counter = 0; cin >> n; for( i = 0; i < n; i++) { cin >> cash[i]; } cin >> m; for( i = 0; i < m; i++) { cin >> a; if (a == 'W') game[i] = 1; else game[i] = -1; } odd = 1; do { for( i = 0; i < m; i++) { cash[counter % n] += game[i]; counter++; if (cash[(counter-1) % n] == 0) { cout << counter; odd = 0; break; } } if (counter > 223372036854775807) { counter = -1; cout << counter; odd = 0; break; } }while(odd != 0); return 0; } |