Submission #901355

# Submission time Handle Problem Language Result Execution time Memory
901355 2024-01-09T11:03:34 Z KienTran Dango Maker (JOI18_dango_maker) C++14
0 / 100
61 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

const int O = 3e3 + 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];

struct triple{
    int k, u, v;

    bool operator ==(const triple &x) const{
        return (x.k == k && x.u == u && x.v == v);
    }

    bool operator !=(const triple &x) const{
        return !(x.k == k && x.u == u && x.v == v);
    }
};

vector <triple> g[2][O][O];

void dfs(triple u, triple par = {0, 0, 0}){
    cnt += u.k == 0; cal += 1;
    dd[u.k][u.u][u.v] = 1;
    for (auto v : g[u.k][u.u][u.v]){
        if (!dd[v.k][v.u][v.v]) dfs(v, u);
    }
}

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({1, i - 2, j + 2});
                    g[1][i - 2][j + 2].push_back({0, i, j});
                }

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

                if (c[i][j] & 2){
                    g[0][i][j].push_back({1, i, j});
                    g[1][i][j].push_back({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;
                if (c[i][j] & 1 && !dd[0][i][j]){
                    dfs({0, i, j});
                }
                else if (!dd[1][i][j]){
                    dfs({1, i, j});
                }

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

    cout << res;
}

Compilation message

dango_maker.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 61 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 61 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 61 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -