#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#define DEBUG
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while(T--)
{
int d; cin >> d;
string s; cin >> s;
int n = s.size();
int A[n];
for(int i = 0; i < n; ++i)
{
if(s[i] == 'r') A[i] = 0;
if(s[i] == 'p') A[i] = 1;
if(s[i] == 's') A[i] = 2;
}
if(d == 1)
{
bool B[n]{};
int C[3]{};
for(int i = 0; i < n; ++i)
{
int x = A[i];
int y = (A[i] + 1) % 3;
int z = (A[i] + 2) % 3;
if(C[y] != 0 && C[z] == 0) B[i] = true;
++C[x];
}
for(int i = 0; i < 3; ++i) C[i] = 0;
for(int i = n - 1; i >= 0; --i)
{
int x = A[i];
int y = (A[i] + 1) % 3;
int z = (A[i] + 2) % 3;
if(C[y] != 0 && C[z] == 0) B[i] = true;
++C[x];
}
for(int i = 0; i < n; ++i) cout << (B[i] ? '0' : '1');
}
else
{
bool B[n]{};
int C[3]{};
for(int i = 0; i < n; ++i)
{
int x = A[i];
int y = (A[i] + 1) % 3;
int z = (A[i] + 2) % 3;
if(C[y] != 0 && C[z] == 0 || C[x] != 0 && C[y] == 0) B[i] = true;
++C[x];
}
for(int i = 0; i < 3; ++i) C[i] = 0;
for(int i = n - 1; i >= 0; --i)
{
int x = A[i];
int y = (A[i] + 1) % 3;
int z = (A[i] + 2) % 3;
if(C[y] != 0 && C[z] == 0 || C[x] != 0 && C[y] == 0) B[i] = true;
++C[x];
}
for(int i = 0; i < n; ++i) cout << (B[i] ? '0' : '1');
}
cout << '\n';
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:71:30: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
71 | if(C[y] != 0 && C[z] == 0 || C[x] != 0 && C[y] == 0) B[i] = true;
| ~~~~~~~~~~^~~~~~~~~~~~
Main.cpp:80:30: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
80 | if(C[y] != 0 && C[z] == 0 || C[x] != 0 && C[y] == 0) B[i] = true;
| ~~~~~~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |