답안 #521968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521968 2022-02-03T14:16:21 Z fallingstar Dango Maker (JOI18_dango_maker) C++17
100 / 100
168 ms 20264 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>

using namespace std;

int solve(const vector<int>& a)
{
    int n = a.size();
    vector<array<int, 2>> f(n, {-1, -1});
    if (a[0] & 1) f[0][0] = 1;
    if (a[0] & 2) f[0][1] = 1;
    for (int i = 0; i + 1 < n; ++i)
        for (int j = 0; j < 2; ++j)
            f[i + 1][j] = max(f[i][1 - j], f[i][j] + !!(a[i + 1] & (j + 1)));
    return max(f.back()[0], f.back()[1]);
}

int main()
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<string> tab(n);
    for (int i = 0; i < n; ++i) cin >> tab[i];

    int res = 0;
    vector<vector<bool>> vst(n, vector<bool>(m));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            if (tab[i][j] == 'G' && !vst[i][j]) {
                vector<int> seq;
                int u = i, v = j;
                while (true) {
                    int x = 0;
                    x |= (u > 0 && u + 1 < n && tab[u - 1][v] == 'R' && tab[u + 1][v] == 'W');
                    x |= (v > 0 && v + 1 < m && tab[u][v - 1] == 'R' && tab[u][v + 1] == 'W') * 2;
                    if (!x) break;
                    vst[u][v] = true;
                    seq.push_back(x);
                    ++u, --v;
                    if (u >= n || v < 0 || tab[u][v] != 'G') break;
                }
                if (!seq.empty()) res += solve(seq);
            }
    cout << res;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 0 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 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 0 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 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 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 292 KB Output is correct
31 Correct 1 ms 312 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 308 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 0 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 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 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 292 KB Output is correct
31 Correct 1 ms 312 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 308 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 0 ms 204 KB Output is correct
55 Correct 1 ms 588 KB Output is correct
56 Correct 1 ms 328 KB Output is correct
57 Correct 1 ms 448 KB Output is correct
58 Correct 29 ms 2500 KB Output is correct
59 Correct 168 ms 20256 KB Output is correct
60 Correct 151 ms 20160 KB Output is correct
61 Correct 141 ms 20160 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 139 ms 19452 KB Output is correct
64 Correct 82 ms 20264 KB Output is correct
65 Correct 76 ms 20216 KB Output is correct
66 Correct 87 ms 20216 KB Output is correct
67 Correct 148 ms 20164 KB Output is correct
68 Correct 148 ms 20168 KB Output is correct
69 Correct 155 ms 20160 KB Output is correct
70 Correct 10 ms 2500 KB Output is correct
71 Correct 9 ms 2500 KB Output is correct
72 Correct 8 ms 2480 KB Output is correct
73 Correct 8 ms 2500 KB Output is correct
74 Correct 8 ms 2508 KB Output is correct
75 Correct 8 ms 2584 KB Output is correct
76 Correct 8 ms 2504 KB Output is correct
77 Correct 11 ms 2564 KB Output is correct
78 Correct 8 ms 2520 KB Output is correct
79 Correct 8 ms 2492 KB Output is correct
80 Correct 10 ms 2480 KB Output is correct
81 Correct 9 ms 2484 KB Output is correct
82 Correct 10 ms 2480 KB Output is correct
83 Correct 9 ms 2492 KB Output is correct
84 Correct 11 ms 2500 KB Output is correct
85 Correct 8 ms 2520 KB Output is correct
86 Correct 10 ms 2500 KB Output is correct
87 Correct 8 ms 2508 KB Output is correct
88 Correct 8 ms 2508 KB Output is correct
89 Correct 9 ms 2488 KB Output is correct
90 Correct 11 ms 2500 KB Output is correct