Submission #678556

# Submission time Handle Problem Language Result Execution time Memory
678556 2023-01-06T07:27:45 Z tranxuanbach Dango Maker (JOI18_dango_maker) C++17
100 / 100
244 ms 9856 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define FordE(i, l, r) for (int i = l; i >= r; i--)
#define Fora(v, a) for (auto v: a)
#define bend(a) a.begin(), a.end()
#define isz(a) ((signed)a.size())

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vpii;
typedef vector <vi> vvi;

const int N = 3e3 + 5;

int n, m;
char a[N][N];

vpii b;
int dp[N][2];
int ans;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("KEK.inp", "r", stdin);
    // freopen("KEK.out", "w", stdout);
    cin >> n >> m;
    ForE(i, 1, n){
        ForE(j, 1, m){
            cin >> a[i][j];
        }
    }
    ForE(dia, 2, n + m - 2){
        b.resize(1);
        memset(dp, 0, sizeof(dp));
        ForE(i, 1, n){
            int j = dia - i;
            if (m < j or j < 1){
                continue;
            }
            b.emplace_back(i, j);
        }
        For(i, 1, isz(b)){
            dp[i][0] = max(dp[i][0], dp[i - 1][0]);
            if (i >= 2) dp[i][0] = max(dp[i][0], dp[i - 2][1]);
            if (b[i].se + 2 <= m and a[b[i].fi][b[i].se] == 'R' and a[b[i].fi][b[i].se + 1] == 'G' and a[b[i].fi][b[i].se + 2] == 'W'){
                dp[i][0] = max(dp[i][0], dp[i - 1][0] + 1);
            }
            dp[i][1] = max(dp[i][1], dp[i][0]);
            dp[i][1] = max(dp[i][1], dp[i - 1][1]);
            if (b[i].fi + 2 <= n and a[b[i].fi][b[i].se] == 'R' and a[b[i].fi + 1][b[i].se] == 'G' and a[b[i].fi + 2][b[i].se] == 'W'){
                dp[i][1] = max(dp[i][1], dp[i - 1][1] + 1);
            }
        }
        ans += dp[isz(b) - 1][1];
    }
    cout << ans << endl;
}

/*
==================================================+
INPUT:                                            |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
OUTPUT:                                           |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 264 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 264 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 376 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 340 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 336 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 332 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 264 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 376 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 340 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 336 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 332 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 3 ms 340 KB Output is correct
55 Correct 13 ms 9180 KB Output is correct
56 Correct 3 ms 340 KB Output is correct
57 Correct 7 ms 6236 KB Output is correct
58 Correct 29 ms 3676 KB Output is correct
59 Correct 243 ms 9740 KB Output is correct
60 Correct 239 ms 9768 KB Output is correct
61 Correct 244 ms 9788 KB Output is correct
62 Correct 2 ms 340 KB Output is correct
63 Correct 228 ms 9856 KB Output is correct
64 Correct 191 ms 9800 KB Output is correct
65 Correct 187 ms 9732 KB Output is correct
66 Correct 181 ms 9756 KB Output is correct
67 Correct 203 ms 9632 KB Output is correct
68 Correct 212 ms 9692 KB Output is correct
69 Correct 204 ms 9640 KB Output is correct
70 Correct 23 ms 3836 KB Output is correct
71 Correct 21 ms 3932 KB Output is correct
72 Correct 24 ms 3888 KB Output is correct
73 Correct 24 ms 3932 KB Output is correct
74 Correct 21 ms 3932 KB Output is correct
75 Correct 22 ms 3924 KB Output is correct
76 Correct 24 ms 3848 KB Output is correct
77 Correct 25 ms 3884 KB Output is correct
78 Correct 23 ms 3912 KB Output is correct
79 Correct 24 ms 3916 KB Output is correct
80 Correct 22 ms 3840 KB Output is correct
81 Correct 24 ms 3812 KB Output is correct
82 Correct 22 ms 3888 KB Output is correct
83 Correct 23 ms 3916 KB Output is correct
84 Correct 30 ms 3928 KB Output is correct
85 Correct 23 ms 3820 KB Output is correct
86 Correct 22 ms 3812 KB Output is correct
87 Correct 22 ms 3916 KB Output is correct
88 Correct 23 ms 3856 KB Output is correct
89 Correct 24 ms 3840 KB Output is correct
90 Correct 21 ms 3792 KB Output is correct