Submission #441256

# Submission time Handle Problem Language Result Execution time Memory
441256 2021-07-04T18:37:57 Z Aryan_Raina Dango Maker (JOI18_dango_maker) C++17
100 / 100
210 ms 10200 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int int64_t
#define ld long double
#define ar array
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1e9+7;
const int INF = 1e15+5;

void amax(int &a, int b) { a = max(a, b); }

void solve() {
    int N, M; cin >> N >> M;
    string s[N];
    for (string &i : s) cin >> i;

    auto right = [&](int i, int j) {
        if (j + 2 >= M) return false;
        return s[i][j] == 'R' && s[i][j+1] == 'G' && s[i][j+2] == 'W';
    };
    auto down = [&](int i, int j) {
        if (i + 2 >= N) return false;
        return s[i][j] == 'R' && s[i+1][j] == 'G' && s[i+2][j] == 'W';
    };

    int ans = 0;
    for (int x = 0; x < N; x++) {
        vector<ar<int,3>> dp(M, {0,0,0});

        if (down(x, 0)) dp[0][1] = dp[0][0] = 1;
        if (right(x, 0)) dp[0][2] = 1;

        int mx = max({dp[0][0], dp[0][1], dp[0][2]});

        for (int i = x-1, j = 1; j < M && i >= 0; i--, j++) {
            if (down(i, j))
                amax(dp[j][1], dp[j-1][0] + 1);

            if (right(i, j)) {
                amax(dp[j][2], max(dp[j-1][0], dp[j-1][2]) + 1);
                if (j - 2 >= 0) amax(dp[j][2], dp[j-2][2] + 1);
            }
            
            amax(dp[j][0], max(dp[j-1][0], dp[j][1]));
            if (j - 2 >= 0) amax(dp[j][0], dp[j-2][2]);

            amax(mx, max({dp[j][0], dp[j][1], dp[j][2]}));
        }

        ans += mx;
    }

    for (int x = 1; x < M; x++) {
        vector<ar<int,3>> dp(M, {0,0,0});

        if (down(N-1, x)) dp[x][1] = dp[x][0] = 1;
        if (right(N-1, x)) dp[x][2] = 1;

        int mx = max({dp[x][0], dp[x][1], dp[x][2]});

        for (int i = N-2, j = x + 1; j < M && i >= 0; i--, j++) {
            if (down(i, j))
                amax(dp[j][1], dp[j-1][0] + 1);

            if (right(i, j)) {
                amax(dp[j][2], max(dp[j-1][0], dp[j-1][2]) + 1);
                if (j - 2 >= 0) amax(dp[j][2], dp[j-2][2] + 1);
            }
            
            amax(dp[j][0], max(dp[j-1][0], dp[j][1]));
            if (j - 2 >= 0) amax(dp[j][0], dp[j-2][2]);

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

    cout << ans << '\n';
}
 
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); 
 
    int t = 1; //cin >> t;
    while (t--) solve();   
}  
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 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 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 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 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 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 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 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 0 ms 204 KB Output is correct
16 Correct 0 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 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 280 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 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 0 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 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 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 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 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 0 ms 204 KB Output is correct
16 Correct 0 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 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 280 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 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 0 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 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 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 13 ms 388 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 13 ms 408 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 19 ms 1432 KB Output is correct
59 Correct 205 ms 10188 KB Output is correct
60 Correct 204 ms 10188 KB Output is correct
61 Correct 210 ms 10184 KB Output is correct
62 Correct 11 ms 332 KB Output is correct
63 Correct 192 ms 9804 KB Output is correct
64 Correct 160 ms 10188 KB Output is correct
65 Correct 152 ms 10180 KB Output is correct
66 Correct 150 ms 10100 KB Output is correct
67 Correct 149 ms 10188 KB Output is correct
68 Correct 155 ms 10200 KB Output is correct
69 Correct 152 ms 10188 KB Output is correct
70 Correct 13 ms 1432 KB Output is correct
71 Correct 12 ms 1424 KB Output is correct
72 Correct 12 ms 1428 KB Output is correct
73 Correct 13 ms 1428 KB Output is correct
74 Correct 13 ms 1356 KB Output is correct
75 Correct 13 ms 1356 KB Output is correct
76 Correct 13 ms 1432 KB Output is correct
77 Correct 13 ms 1356 KB Output is correct
78 Correct 15 ms 1432 KB Output is correct
79 Correct 13 ms 1432 KB Output is correct
80 Correct 12 ms 1428 KB Output is correct
81 Correct 13 ms 1424 KB Output is correct
82 Correct 12 ms 1356 KB Output is correct
83 Correct 13 ms 1424 KB Output is correct
84 Correct 13 ms 1432 KB Output is correct
85 Correct 13 ms 1432 KB Output is correct
86 Correct 13 ms 1424 KB Output is correct
87 Correct 12 ms 1356 KB Output is correct
88 Correct 13 ms 1428 KB Output is correct
89 Correct 13 ms 1432 KB Output is correct
90 Correct 13 ms 1428 KB Output is correct