This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <string.h>
#define N 500000
int main() {
int t;
scanf("%d", &t);
while (t--) {
static char cc[N + 1], win[N + 1];
int d, n, i, u, v, w, c;
scanf("%d%s", &d, cc), n = strlen(cc);
for (i = 0; i < n; i++)
if (cc[i] == 'r')
cc[i] = 0;
else if (cc[i] == 'p')
cc[i] = 1;
else
cc[i] = 2;
memset(win, '1', n * sizeof *win), win[n] = 0;
if (d == 1) {
u = 0;
for (i = 0; i < n; i++) {
c = cc[i];
if ((u & 1 << (c + 1) % 3) != 0 && (u & 1 << (c + 2) % 3) == 0)
win[i] = '0';
u |= 1 << c;
}
u = 0;
for (i = n - 1; i >= 0; i--) {
c = cc[i];
if ((u & 1 << (c + 1) % 3) != 0 && (u & 1 << (c + 2) % 3) == 0)
win[i] = '0';
u |= 1 << c;
}
} else {
u = 0, v = 0, w = 0;
for (i = 0; i < n; i++) {
c = cc[i];
if ((u & 1 << c) == 0) {
if ((u & 1 << (c + 1) % 3) != 0 && (u & 1 << (c + 2) % 3) == 0)
win[i] = '0';
} else {
if ((u & 1 << (c + 1) % 3) == 0)
win[i] = '0';
else if (cc[i - 1] != (c + 2) % 3 && (w & 1 << (c + 2) % 3) == 0)
win[i] = '0';
}
if ((v & 1 << (c + 1) % 3) != 0)
w |= 1 << (c + 1) % 3;
if (i == 0 || (u & 1 << (c + 2) % 3) != 0)
v |= 1 << c;
u |= 1 << c;
}
u = 0, v = 0, w = 0;
for (i = n - 1; i >= 0; i--) {
c = cc[i];
if ((u & 1 << c) == 0) {
if ((u & 1 << (c + 1) % 3) != 0 && (u & 1 << (c + 2) % 3) == 0)
win[i] = '0';
} else {
if ((u & 1 << (c + 1) % 3) == 0)
win[i] = '0';
else if (cc[i + 1] != (c + 2) % 3 && (w & 1 << (c + 2) % 3) == 0)
win[i] = '0';
}
if ((v & 1 << (c + 1) % 3) != 0)
w |= 1 << (c + 1) % 3;
if (i == n - 1 || (u & 1 << (c + 2) % 3) != 0)
v |= 1 << c;
u |= 1 << c;
}
}
printf("%s\n", win);
}
return 0;
}
Compilation message (stderr)
Main.c: In function 'main':
Main.c:9:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | scanf("%d", &t);
| ^~~~~~~~~~~~~~~
Main.c:14:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d%s", &d, cc), n = strlen(cc);
| ^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |