Submission #1110580

# Submission time Handle Problem Language Result Execution time Memory
1110580 2024-11-10T02:07:08 Z Zero_OP Dango Maker (JOI18_dango_maker) C++14
100 / 100
241 ms 18424 KB
#include <bits/stdc++.h>

using namespace std;

template<typename T>
bool maximize(T& a, const T& b){
    if(a < b) return a = b, true;
    return false;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N, M;
    cin >> N >> M;

    vector<vector<char>> a(N, vector<char>(M));
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < M; ++j){
            cin >> a[i][j];
        }
    }

    auto check_vertical = [&](int i, int j){
        return i - 1 >= 0 && i + 1 < N && a[i - 1][j] == 'R' && a[i][j] == 'G' && a[i + 1][j] == 'W';
    };

    auto check_horizontal = [&](int i, int j){
        return j - 1 >= 0 && j + 1 < M && a[i][j - 1] == 'R' && a[i][j] == 'G' && a[i][j + 1] == 'W';
    };

    int ans = 0;
    for(int s = 0; s <= N + M - 1; ++s){
        vector<tuple<int, int, int, int>> cells; //[x, y, v, h]
        for(int i = max(0, s - M + 1), j = s - i; 0 <= i && i < N && 0 <= j && j < M; ++i, --j){
            cells.emplace_back(i, j, check_vertical(i, j), check_horizontal(i, j));
        }

        int k = (int)cells.size();
        vector<array<int, 3>> dp(k + 1, {0, 0, 0});
        for(int j = 0; j < k; ++j){
            int x, y, v, h; tie(x, y, v, h) = cells[j];
            maximize(dp[j + 1][0], dp[j][0]);
            maximize(dp[j + 1][0], dp[j][1]);
            maximize(dp[j + 1][0], dp[j][2]);

            maximize(dp[j + 1][1], dp[j][0]);
            maximize(dp[j + 1][1], dp[j][1]);

            maximize(dp[j + 1][2], dp[j][0]);
            maximize(dp[j + 1][2], dp[j][2]);

            if(v) maximize(dp[j + 1][1], max(dp[j][0], dp[j][1]) + 1);
            if(h) maximize(dp[j + 1][2], max(dp[j][0], dp[j][2]) + 1);
        }

        ans += max({dp[k][0], dp[k][1], dp[k][2]});
    }

    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 508 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
50 Correct 1 ms 336 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 508 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
50 Correct 1 ms 336 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 1 ms 336 KB Output is correct
55 Correct 1 ms 592 KB Output is correct
56 Correct 1 ms 336 KB Output is correct
57 Correct 2 ms 592 KB Output is correct
58 Correct 28 ms 2384 KB Output is correct
59 Correct 224 ms 18164 KB Output is correct
60 Correct 233 ms 18256 KB Output is correct
61 Correct 241 ms 18424 KB Output is correct
62 Correct 1 ms 336 KB Output is correct
63 Correct 224 ms 17500 KB Output is correct
64 Correct 181 ms 18040 KB Output is correct
65 Correct 195 ms 18036 KB Output is correct
66 Correct 161 ms 18248 KB Output is correct
67 Correct 167 ms 18236 KB Output is correct
68 Correct 166 ms 18252 KB Output is correct
69 Correct 178 ms 17992 KB Output is correct
70 Correct 19 ms 2504 KB Output is correct
71 Correct 22 ms 2384 KB Output is correct
72 Correct 19 ms 2384 KB Output is correct
73 Correct 19 ms 2384 KB Output is correct
74 Correct 22 ms 2400 KB Output is correct
75 Correct 19 ms 2384 KB Output is correct
76 Correct 19 ms 2384 KB Output is correct
77 Correct 19 ms 2384 KB Output is correct
78 Correct 19 ms 2352 KB Output is correct
79 Correct 19 ms 2384 KB Output is correct
80 Correct 19 ms 2384 KB Output is correct
81 Correct 19 ms 2384 KB Output is correct
82 Correct 19 ms 2476 KB Output is correct
83 Correct 20 ms 2348 KB Output is correct
84 Correct 19 ms 2552 KB Output is correct
85 Correct 25 ms 2384 KB Output is correct
86 Correct 20 ms 2512 KB Output is correct
87 Correct 19 ms 2384 KB Output is correct
88 Correct 21 ms 2384 KB Output is correct
89 Correct 22 ms 2384 KB Output is correct
90 Correct 20 ms 2384 KB Output is correct