Submission #893073

# Submission time Handle Problem Language Result Execution time Memory
893073 2023-12-26T13:18:19 Z Alihan_8 Dango Maker (JOI18_dango_maker) C++17
33 / 100
617 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m; cin >> n >> m;
    vector <string> s(n);
    for ( auto &u: s ) cin >> u;
    vector <vector<ar<int,2>>> p(n, vector <ar<int,2>> (m, {-1, -1}));
    // 0 -> horizontal, 1 - vertical
    vector <char> mp =  {'R', 'G', 'W'};
    vector <vector<int>> G;
    int ct = 0;
    auto ok = [&](int u, int v, char x){
        return min(u, v) >= 0 && u < n && v < m && s[u][v] == x;
    };
    auto add = [&](int u, int v){
        G[u].pb(v), G[v].pb(u);
    };
    vector <ar<int,2>> Add;
    int tot = 0;
    for ( int i = 0; i < n; i++ ){
        for ( int j = 0; j < m; j++ ){
            vector <int> H;
            bool h = false;
            if ( j + 3 <= m && vector <char> {s[i][j], s[i][j + 1], s[i][j + 2]} == mp ){
                p[i][j][0] = ct++; h = true;
                if ( ok(i - 1, j + 1, 'R') && ok(i + 1, j + 1, 'W') ){
                    H.pb(p[i - 1][j + 1][1]);
                }
                if ( ok(i - 1, j + 2, 'G') && ok(i - 2, j + 2, 'R') ){
                    H.pb(p[i - 2][j + 2][1]);
                }
            }
            if ( i + 3 <= n && vector <char> {s[i][j], s[i + 1][j], s[i + 2][j]} == mp ){
                p[i][j][1] = ct++;
                H.pb(p[i][j][1]);
            }
            if ( h > 0 ){
                for ( auto &x: H ){
                    Add.pb({x, p[i][j][0]});
                }
            }
        }
    }
    G.resize(ct);
    for ( auto &[u, v]: Add ) add(u, v);
    vector <int> us(ct);
    vector <ar<int,2>> dp(ct, {1, 0});
    auto dfs = [&](auto dfs, int u) -> void{
        us[u] = true;
        for ( auto &v: G[u] ){
            if ( !us[v] ){
                dfs(dfs, v);
                dp[u][0] += dp[v][1];
                dp[u][1] += dp[v][0];
            }
        }
        chmax(dp[u][0], dp[u][1]);
    };
    int ans = 0;
    for ( int i = 0; i < ct; i++ ){
        if ( !us[i] ){
            dfs(dfs, i);
            ans += dp[i][0];
        }
    }
    cout << ans;

    cout << '\n';
}

Compilation message

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:50:9: warning: unused variable 'tot' [-Wunused-variable]
   50 |     int tot = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 448 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 448 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 600 KB Output is correct
27 Correct 0 ms 456 KB Output is correct
28 Correct 0 ms 456 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 460 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 456 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 448 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 600 KB Output is correct
27 Correct 0 ms 456 KB Output is correct
28 Correct 0 ms 456 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 460 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 456 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 724 KB Output is correct
57 Correct 1 ms 792 KB Output is correct
58 Correct 50 ms 13944 KB Output is correct
59 Correct 456 ms 120288 KB Output is correct
60 Correct 437 ms 120344 KB Output is correct
61 Correct 442 ms 120088 KB Output is correct
62 Correct 0 ms 600 KB Output is correct
63 Correct 432 ms 116600 KB Output is correct
64 Runtime error 617 ms 262144 KB Execution killed with signal 9
65 Halted 0 ms 0 KB -