답안 #416363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416363 2021-06-02T10:37:45 Z model_code RPS string (innopolis2021_final_C) C++17
37 / 100
141 ms 11992 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 500000 + 100;
int a[MAXN];
int sum[MAXN][3];
int type_last[MAXN][3];
int type_first[3];
bool can[2][MAXN];
map<char, int> cv = {{'r', 0}, {'s', 1}, {'p', 2}};

string solve_t0(int t, string s) {
    int n = s.size();
    for (int i = 0; i < n; ++i) {
        a[i] = cv[s[i]];
    }
    for (int dir = 0; dir < 2; ++dir) {
        sum[0][0] = sum[0][1] = sum[0][2] = 0;
        type_first[0] = type_first[1] = type_first[2] = -1;
        for (int i = 0; i < n; ++i) {
            for (int k = 0; k < 3; ++k) {
                sum[i + 1][k] = sum[i][k];
            }
            ++sum[i + 1][a[i]];
            if (type_first[a[i]] == -1) {
                type_first[a[i]] = i;
            }
        }
        for (int i = 0; i < n; ++i) {
            can[dir][i] = 1;
            if (sum[i][(a[i] + 2) % 3] > 0 && sum[i][(a[i] + 1) % 3] == 0) {
                can[dir][i] = 0;
            }
        }
        reverse(a, a + n);
    }
    string ans;
    for (int i = 0; i < n; ++i) {
        if (can[0][i] && can[1][n - 1 - i]) {
            ans.push_back('1');
        } else {
            ans.push_back('0');
        }
    }
    return ans;
}


string solve_t1(int t, string s) {
    int n = s.size();
    for (int i = 0; i < n; ++i) {
        a[i] = cv[s[i]];
    }
    for (int dir = 0; dir < 2; ++dir) {
        sum[0][0] = sum[0][1] = sum[0][2] = 0;
        type_first[0] = type_first[1] = type_first[2] = -1;
        type_last[0][0] = type_last[0][1] = type_last[0][2] = -1;
        for (int i = 0; i < n; ++i) {
            for (int k = 0; k < 3; ++k) {
                sum[i + 1][k] = sum[i][k];
                type_last[i + 1][k] = type_last[i][k];
            }
            ++sum[i + 1][a[i]];
            type_last[i + 1][a[i]] = i;
            if (type_first[a[i]] == -1) {
                type_first[a[i]] = i;
            }
        }
        for (int i = 0; i < n; ++i) {
            can[dir][i] = 1;
            int zero = a[i];
            int one = (a[i] + 1) % 3;
            int two = (a[i] + 2) % 3;
            if (sum[i][two] > 0 && sum[i][one] == 0) {
                can[dir][i] = 0;
                continue;
            }
            if (sum[i][zero] > 0 && sum[i][two] == 0) {
                can[dir][i] = 0;
                continue;
            }
            if (type_first[one] == -1 || type_first[one] >= i) {
                if (sum[i][zero] + sum[i][two] > 0) {
                    can[dir][i] = 0;
                }
                continue;
            } else {
                int pos = type_first[one];
                int pos1 = type_last[i][one];
                if (sum[pos][zero] > 0 && sum[pos][two] == 0) {
                    can[dir][i] = 0;
                    continue;
                }
                if ((sum[i][two] - sum[pos + 1][two] > 0)
                        || (sum[i][zero] - sum[pos + 1][zero] == 0)) {
                    //allright
                } else {
                    if ((sum[pos1][two] > 0 || sum[pos1][zero] == 0)
                            && ((sum[i][two] - sum[pos1 + 1][two] > 0)
                                || (sum[i][zero] - sum[pos1 + 1][zero] == 0))) {
                        //allright
                    } else {
                        can[dir][i] = 0;
                        continue;
                    }
                }
            }
        }
    }
    string ans;
    for (int i = 0; i < n; ++i) {
        if (can[0][i] && can[1][n - 1 - i]) {
            ans.push_back('1');
        } else {
            ans.push_back('0');
        }
    }
    return ans;
}

string solve(int t, string s) {
    if (t == 0) {
        return solve_t0(t, s);
    } else {
        return solve_t1(t, s);
    }
}

int main() {
    int tests;
    cin >> tests;
    for (int i = 0; i < tests; ++i) {
        int t;
        cin >> t;
        string s;
        cin >> s;
        cout << solve(t - 1, s) << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 2 ms 204 KB Output is correct
35 Correct 2 ms 204 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 2 ms 204 KB Output is correct
35 Correct 2 ms 204 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 432 KB Output is correct
48 Correct 111 ms 728 KB Output is correct
49 Correct 125 ms 832 KB Output is correct
50 Correct 113 ms 848 KB Output is correct
51 Correct 116 ms 820 KB Output is correct
52 Correct 119 ms 816 KB Output is correct
53 Correct 141 ms 832 KB Output is correct
54 Correct 114 ms 748 KB Output is correct
55 Correct 116 ms 836 KB Output is correct
56 Correct 121 ms 800 KB Output is correct
57 Correct 125 ms 764 KB Output is correct
58 Correct 123 ms 804 KB Output is correct
59 Correct 118 ms 780 KB Output is correct
60 Correct 116 ms 736 KB Output is correct
61 Correct 122 ms 780 KB Output is correct
62 Correct 120 ms 836 KB Output is correct
63 Correct 32 ms 2976 KB Output is correct
64 Correct 38 ms 11992 KB Output is correct
65 Correct 39 ms 3048 KB Output is correct
66 Correct 37 ms 11960 KB Output is correct
67 Correct 41 ms 3036 KB Output is correct
68 Correct 33 ms 1892 KB Output is correct
69 Correct 49 ms 912 KB Output is correct
70 Correct 39 ms 708 KB Output is correct
71 Correct 31 ms 3076 KB Output is correct
72 Correct 41 ms 1872 KB Output is correct
73 Correct 37 ms 920 KB Output is correct
74 Correct 33 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Incorrect 0 ms 332 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Incorrect 0 ms 332 KB Output isn't correct
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 2 ms 204 KB Output is correct
35 Correct 2 ms 204 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 432 KB Output is correct
48 Incorrect 0 ms 332 KB Output isn't correct
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 2 ms 204 KB Output is correct
35 Correct 2 ms 204 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 432 KB Output is correct
48 Correct 111 ms 728 KB Output is correct
49 Correct 125 ms 832 KB Output is correct
50 Correct 113 ms 848 KB Output is correct
51 Correct 116 ms 820 KB Output is correct
52 Correct 119 ms 816 KB Output is correct
53 Correct 141 ms 832 KB Output is correct
54 Correct 114 ms 748 KB Output is correct
55 Correct 116 ms 836 KB Output is correct
56 Correct 121 ms 800 KB Output is correct
57 Correct 125 ms 764 KB Output is correct
58 Correct 123 ms 804 KB Output is correct
59 Correct 118 ms 780 KB Output is correct
60 Correct 116 ms 736 KB Output is correct
61 Correct 122 ms 780 KB Output is correct
62 Correct 120 ms 836 KB Output is correct
63 Correct 32 ms 2976 KB Output is correct
64 Correct 38 ms 11992 KB Output is correct
65 Correct 39 ms 3048 KB Output is correct
66 Correct 37 ms 11960 KB Output is correct
67 Correct 41 ms 3036 KB Output is correct
68 Correct 33 ms 1892 KB Output is correct
69 Correct 49 ms 912 KB Output is correct
70 Correct 39 ms 708 KB Output is correct
71 Correct 31 ms 3076 KB Output is correct
72 Correct 41 ms 1872 KB Output is correct
73 Correct 37 ms 920 KB Output is correct
74 Correct 33 ms 716 KB Output is correct
75 Incorrect 0 ms 332 KB Output isn't correct
76 Halted 0 ms 0 KB -