Submission #902174

# Submission time Handle Problem Language Result Execution time Memory
902174 2024-01-10T06:44:57 Z KienTran Dango Maker (JOI18_dango_maker) C++14
13 / 100
2 ms 4956 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 = 3e2 + 5;
const int base = 500;
const int mod = 998244353;

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

vector <pair <ii, int>> g[2][O][O];

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

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

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

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

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++ i){
        for (int j = 1; j <= m; ++ j){
            cin >> a[i][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');
            }
        }
    }

    for (int i = 1; i <= n; ++ i){
        for (int j = 1; j <= m - 2; ++ j){
            if (c[i][j] & 1){
                if (i > 2 && (c[i - 2][j + 2] & 2)){
                    g[0][i][j].push_back(make_pair(make_pair(1, i - 2), j + 2));
                    g[1][i - 2][j + 2].push_back(make_pair(make_pair(0, i), j));
                }

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

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

    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]){
                    dfs(make_pair(make_pair(0, i), j));
                }

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

                res += max(cnt, cal - cnt);
            }
        }
    }

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

Compilation message

dango_maker.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4704 KB Output is correct
9 Correct 1 ms 4708 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4704 KB Output is correct
13 Correct 2 ms 4708 KB Output is correct
14 Correct 2 ms 4836 KB Output is correct
15 Correct 1 ms 4696 KB Output is correct
16 Correct 2 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4704 KB Output is correct
9 Correct 1 ms 4708 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4704 KB Output is correct
13 Correct 2 ms 4708 KB Output is correct
14 Correct 2 ms 4836 KB Output is correct
15 Correct 1 ms 4696 KB Output is correct
16 Correct 2 ms 4700 KB Output is correct
17 Correct 2 ms 4696 KB Output is correct
18 Correct 2 ms 4704 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 2 ms 4708 KB Output is correct
21 Correct 2 ms 4708 KB Output is correct
22 Correct 1 ms 4712 KB Output is correct
23 Correct 2 ms 4704 KB Output is correct
24 Correct 2 ms 4712 KB Output is correct
25 Correct 2 ms 4712 KB Output is correct
26 Correct 1 ms 4712 KB Output is correct
27 Correct 1 ms 4844 KB Output is correct
28 Correct 2 ms 4712 KB Output is correct
29 Correct 2 ms 4712 KB Output is correct
30 Correct 1 ms 4712 KB Output is correct
31 Correct 1 ms 4708 KB Output is correct
32 Correct 1 ms 4712 KB Output is correct
33 Correct 2 ms 4712 KB Output is correct
34 Incorrect 1 ms 4712 KB Output isn't correct
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4704 KB Output is correct
9 Correct 1 ms 4708 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4704 KB Output is correct
13 Correct 2 ms 4708 KB Output is correct
14 Correct 2 ms 4836 KB Output is correct
15 Correct 1 ms 4696 KB Output is correct
16 Correct 2 ms 4700 KB Output is correct
17 Correct 2 ms 4696 KB Output is correct
18 Correct 2 ms 4704 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 2 ms 4708 KB Output is correct
21 Correct 2 ms 4708 KB Output is correct
22 Correct 1 ms 4712 KB Output is correct
23 Correct 2 ms 4704 KB Output is correct
24 Correct 2 ms 4712 KB Output is correct
25 Correct 2 ms 4712 KB Output is correct
26 Correct 1 ms 4712 KB Output is correct
27 Correct 1 ms 4844 KB Output is correct
28 Correct 2 ms 4712 KB Output is correct
29 Correct 2 ms 4712 KB Output is correct
30 Correct 1 ms 4712 KB Output is correct
31 Correct 1 ms 4708 KB Output is correct
32 Correct 1 ms 4712 KB Output is correct
33 Correct 2 ms 4712 KB Output is correct
34 Incorrect 1 ms 4712 KB Output isn't correct
35 Halted 0 ms 0 KB -