#include <cstdio> #include <vector> #include <cstring> using namespace std; int collisions[100000007]; bool directions[1000000]; int n; void check(int left){ if(left == n-1){ return; } if(directions[left] && !directions[left+1]){ collisions[left]++; collisions[left+1]++; directions[left] = false; directions[left+1] = true; check(left+1); if(left-1 < 0){ return; } check(left-1); } } int main() { scanf("%d", &n); getchar(); for(int i = 0; i < n; ++i) { char ch = getchar(); directions[i] = (ch == 'P'); } for (int i = 0; i < n - 1; ++i) { check(i); } for (int i = 0; i < n; ++i) { printf("%d ", collisions[i]); } printf("\n"); }
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 | #include <cstdio> #include <vector> #include <cstring> using namespace std; int collisions[100000007]; bool directions[1000000]; int n; void check(int left){ if(left == n-1){ return; } if(directions[left] && !directions[left+1]){ collisions[left]++; collisions[left+1]++; directions[left] = false; directions[left+1] = true; check(left+1); if(left-1 < 0){ return; } check(left-1); } } int main() { scanf("%d", &n); getchar(); for(int i = 0; i < n; ++i) { char ch = getchar(); directions[i] = (ch == 'P'); } for (int i = 0; i < n - 1; ++i) { check(i); } for (int i = 0; i < n; ++i) { printf("%d ", collisions[i]); } printf("\n"); } |