Submission #902250

# Submission time Handle Problem Language Result Execution time Memory
902250 2024-01-10T07:31:32 Z KienTran Dango Maker (JOI18_dango_maker) C++14
100 / 100
820 ms 71380 KB
#include <bits/stdc++.h>
#define ii pair <int, int>
#define fi first.first
#define se first.second
#define th second

using namespace std;

const int O = 3e3 + 5;
const int base = 500;
const int mod = 998244353;

int n, m, cnt, cal, c[O][O];
bool dd[2][O][O];
string a[O];

vector <pair <ii, int>> g(pair <ii, int> u){
    vector <pair <ii, int>> res;

    int i = u.se;
    int j = u.th;
    if (u.fi == 0){
        if (i > 2 && (c[i - 2][j + 2] & 2)){
            res.push_back(make_pair(make_pair(1, i - 2), j + 2));
        }

        if (i > 1 && (c[i - 1][j + 1] & 2)){
            res.push_back(make_pair(make_pair(1, i - 1), j + 1));
        }

        if (c[i][j] & 2){
            res.push_back(make_pair(make_pair(1, i), j));
        }
    }

    if (u.fi == 1){
        if (j > 2 && (c[i + 2][j - 2] & 1)){
            res.push_back(make_pair(make_pair(0, i + 2), j - 2));
        }

        if (j > 1 && (c[i + 1][j - 1] & 1)){
            res.push_back(make_pair(make_pair(0, i + 1), j - 1));
        }

        if (c[i][j] & 1){
            res.push_back(make_pair(make_pair(0, i), j));
        }
    }

    return res;
}

int dfs(pair <ii, int> u){
    vector <int> f[2], b;

    queue <pair <ii, int>> q;
    q.push(u);

    int turn = u.fi;
    dd[u.fi][u.se][u.th] = 1; cal = 0;
    while (q.size()){
        u = q.front(); q.pop();

        //cout << u.fi << " " << u.se << " " << u.th << endl;

        if (turn != u.fi) b.push_back(cal);

        cal = turn == u.fi ? cal + 1 : 1;
        turn = u.fi;

        auto adj = g(u);
        for (auto v : adj){
            if (!dd[v.fi][v.se][v.th]){
                dd[v.fi][v.se][v.th] = 1;
                q.push(v);
            }
        }
    }

    b.push_back(cal);

    int m = b.size() - 1;

    f[0].resize(m + 1);
    f[1].resize(m + 1); f[1][0] = b[0];
    for (int i = 1; i <= m; ++ i){
        f[1][i] = f[0][i - 1] + b[i];
        f[0][i] = max(f[0][i - 1], f[1][i - 1]);
    }

    return max(f[0][m], f[1][m]);
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++ i){
        cin >> a[i]; a[i] = " " + a[i];
        for (int j = 1; j <= m; ++ j){
            if (a[i][j] == 'W' && j >= 3){
                c[i][j - 2] += (a[i][j - 2] == 'R' && a[i][j - 1] == 'G');
            }

            if (a[i][j] == 'W' && i >= 3){
                c[i - 2][j] += 2 * (a[i - 2][j] == 'R' && a[i - 1][j] == 'G');
            }
        }
    }

    int res = 0;
    for (int i = 1; i <= n; ++ i){
        for (int j = 1; j <= m; ++ j){
            if (c[i][j] > 0){
                cnt = cal = 0;
                //cout << "debug " << i << " " << j << endl;
                if ((c[i][j] & 1) && !dd[0][i][j]){
                    cnt = dfs(make_pair(make_pair(0, i), j));
                }

                if ((c[i][j] & 2) && !dd[1][i][j]){
                    cnt = dfs(make_pair(make_pair(1, i), j));
                }
                //cout << cnt << " " << cal << endl;
                //cout << "end" << endl;

                res += cnt;
            }
        }
    }

    cout << res;
}
/***
5 5
RGWRR
GRRGW
WRGWR
RGWRG
XWRGW
***/

Compilation message

dango_maker.cpp:94:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   94 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2588 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2604 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2588 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2604 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2604 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2600 KB Output is correct
36 Correct 1 ms 2656 KB Output is correct
37 Correct 1 ms 2648 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 1 ms 2656 KB Output is correct
40 Correct 1 ms 2660 KB Output is correct
41 Correct 1 ms 2660 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2660 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2608 KB Output is correct
46 Correct 1 ms 2472 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 1 ms 2600 KB Output is correct
49 Correct 1 ms 2604 KB Output is correct
50 Correct 1 ms 2648 KB Output is correct
51 Correct 1 ms 2648 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2588 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2604 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2604 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2600 KB Output is correct
36 Correct 1 ms 2656 KB Output is correct
37 Correct 1 ms 2648 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 1 ms 2656 KB Output is correct
40 Correct 1 ms 2660 KB Output is correct
41 Correct 1 ms 2660 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2660 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2608 KB Output is correct
46 Correct 1 ms 2472 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 1 ms 2600 KB Output is correct
49 Correct 1 ms 2604 KB Output is correct
50 Correct 1 ms 2648 KB Output is correct
51 Correct 1 ms 2648 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 5 ms 35940 KB Output is correct
56 Correct 1 ms 2652 KB Output is correct
57 Correct 8 ms 35420 KB Output is correct
58 Correct 34 ms 22696 KB Output is correct
59 Correct 174 ms 71076 KB Output is correct
60 Correct 184 ms 71048 KB Output is correct
61 Correct 176 ms 71064 KB Output is correct
62 Correct 1 ms 2396 KB Output is correct
63 Correct 193 ms 70268 KB Output is correct
64 Correct 642 ms 71364 KB Output is correct
65 Correct 634 ms 71380 KB Output is correct
66 Correct 820 ms 71208 KB Output is correct
67 Correct 353 ms 60688 KB Output is correct
68 Correct 334 ms 60868 KB Output is correct
69 Correct 313 ms 67020 KB Output is correct
70 Correct 61 ms 22760 KB Output is correct
71 Correct 60 ms 22848 KB Output is correct
72 Correct 60 ms 22824 KB Output is correct
73 Correct 59 ms 22612 KB Output is correct
74 Correct 82 ms 22844 KB Output is correct
75 Correct 65 ms 22608 KB Output is correct
76 Correct 65 ms 22844 KB Output is correct
77 Correct 69 ms 22632 KB Output is correct
78 Correct 69 ms 22844 KB Output is correct
79 Correct 72 ms 22612 KB Output is correct
80 Correct 63 ms 22840 KB Output is correct
81 Correct 64 ms 22840 KB Output is correct
82 Correct 62 ms 22608 KB Output is correct
83 Correct 63 ms 22840 KB Output is correct
84 Correct 65 ms 22612 KB Output is correct
85 Correct 60 ms 22832 KB Output is correct
86 Correct 61 ms 22356 KB Output is correct
87 Correct 72 ms 22840 KB Output is correct
88 Correct 68 ms 22600 KB Output is correct
89 Correct 71 ms 22844 KB Output is correct
90 Correct 60 ms 22620 KB Output is correct