답안 #1089760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089760 2024-09-17T05:57:57 Z TrinhKhanhDung Dango Maker (JOI18_dango_maker) C++14
13 / 100
103 ms 226412 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

const int MAX = 3100;

int N, M;
string a[MAX];
int pos[MAX][MAX][2], timer;
vector<int> adj[MAX * MAX];
bool vis[MAX * MAX];

void dfs(int u, int &sum, int &num1, int c){
    sum++;
    num1 += c;
    for(int v: adj[u]) if(!vis[v]){
        vis[v] = true;
        dfs(v, sum, num1, !c);
    }
}

void solve(){
    cin >> N >> M;
    for(int i = 1; i <= N; i++){
        cin >> a[i];
        a[i] = "*" + a[i];
    }

    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= M; j++) if(a[i][j] == 'G'){
            bool t1 = i > 1 && i < N && a[i - 1][j] == 'R' && a[i + 1][j] == 'W';
            bool t2 = j > 1 && j < M && a[i][j - 1] == 'R' && a[i][j + 1] == 'W';
            if(t2){
                pos[i][j][0] = ++timer;
                if(pos[i - 1][j + 1][1]){
                    adj[pos[i][j][0]].push_back(pos[i - 1][j + 1][1]);
                    adj[pos[i - 1][j + 1][1]].push_back(pos[i][j][0]);
                }
            }
            if(t1){
                pos[i][j][1] = ++timer;
                if(pos[i - 1][j + 1][0]){
                    adj[pos[i][j][1]].push_back(pos[i - 1][j + 1][0]);
                    adj[pos[i - 1][j + 1][0]].push_back(pos[i][j][1]);
                }
            }
            if(t1 && t2){
                adj[timer].push_back(timer - 1);
                adj[timer - 1].push_back(timer);
            }
        }
    }

    int ans = 0;
    for(int i = 1; i <= timer; i++) if(!vis[i]){
        vis[i] = true;
        int sum = 0, num1 = 0;
        dfs(i, sum, num1, 0);
        ans += max(num1, sum - num1);
    }

    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    //i freopen("order.inp","r",stdin);
    // freopen("order.out","w",stdout);

    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 226128 KB Output is correct
2 Correct 81 ms 225988 KB Output is correct
3 Correct 100 ms 226412 KB Output is correct
4 Correct 81 ms 226112 KB Output is correct
5 Correct 97 ms 226160 KB Output is correct
6 Correct 80 ms 226120 KB Output is correct
7 Correct 96 ms 226128 KB Output is correct
8 Correct 82 ms 226224 KB Output is correct
9 Correct 81 ms 226096 KB Output is correct
10 Correct 103 ms 226132 KB Output is correct
11 Correct 81 ms 226236 KB Output is correct
12 Correct 90 ms 226100 KB Output is correct
13 Correct 83 ms 226128 KB Output is correct
14 Correct 82 ms 226164 KB Output is correct
15 Correct 82 ms 225988 KB Output is correct
16 Correct 88 ms 226020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 226128 KB Output is correct
2 Correct 81 ms 225988 KB Output is correct
3 Correct 100 ms 226412 KB Output is correct
4 Correct 81 ms 226112 KB Output is correct
5 Correct 97 ms 226160 KB Output is correct
6 Correct 80 ms 226120 KB Output is correct
7 Correct 96 ms 226128 KB Output is correct
8 Correct 82 ms 226224 KB Output is correct
9 Correct 81 ms 226096 KB Output is correct
10 Correct 103 ms 226132 KB Output is correct
11 Correct 81 ms 226236 KB Output is correct
12 Correct 90 ms 226100 KB Output is correct
13 Correct 83 ms 226128 KB Output is correct
14 Correct 82 ms 226164 KB Output is correct
15 Correct 82 ms 225988 KB Output is correct
16 Correct 88 ms 226020 KB Output is correct
17 Correct 80 ms 226012 KB Output is correct
18 Correct 82 ms 226100 KB Output is correct
19 Correct 93 ms 226132 KB Output is correct
20 Correct 92 ms 226128 KB Output is correct
21 Correct 97 ms 226216 KB Output is correct
22 Correct 90 ms 226128 KB Output is correct
23 Correct 91 ms 226128 KB Output is correct
24 Correct 88 ms 226128 KB Output is correct
25 Correct 88 ms 226132 KB Output is correct
26 Correct 87 ms 226128 KB Output is correct
27 Correct 87 ms 226136 KB Output is correct
28 Correct 93 ms 226132 KB Output is correct
29 Correct 93 ms 226128 KB Output is correct
30 Correct 87 ms 226132 KB Output is correct
31 Correct 85 ms 225992 KB Output is correct
32 Correct 88 ms 226128 KB Output is correct
33 Correct 89 ms 226044 KB Output is correct
34 Incorrect 87 ms 226052 KB Output isn't correct
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 226128 KB Output is correct
2 Correct 81 ms 225988 KB Output is correct
3 Correct 100 ms 226412 KB Output is correct
4 Correct 81 ms 226112 KB Output is correct
5 Correct 97 ms 226160 KB Output is correct
6 Correct 80 ms 226120 KB Output is correct
7 Correct 96 ms 226128 KB Output is correct
8 Correct 82 ms 226224 KB Output is correct
9 Correct 81 ms 226096 KB Output is correct
10 Correct 103 ms 226132 KB Output is correct
11 Correct 81 ms 226236 KB Output is correct
12 Correct 90 ms 226100 KB Output is correct
13 Correct 83 ms 226128 KB Output is correct
14 Correct 82 ms 226164 KB Output is correct
15 Correct 82 ms 225988 KB Output is correct
16 Correct 88 ms 226020 KB Output is correct
17 Correct 80 ms 226012 KB Output is correct
18 Correct 82 ms 226100 KB Output is correct
19 Correct 93 ms 226132 KB Output is correct
20 Correct 92 ms 226128 KB Output is correct
21 Correct 97 ms 226216 KB Output is correct
22 Correct 90 ms 226128 KB Output is correct
23 Correct 91 ms 226128 KB Output is correct
24 Correct 88 ms 226128 KB Output is correct
25 Correct 88 ms 226132 KB Output is correct
26 Correct 87 ms 226128 KB Output is correct
27 Correct 87 ms 226136 KB Output is correct
28 Correct 93 ms 226132 KB Output is correct
29 Correct 93 ms 226128 KB Output is correct
30 Correct 87 ms 226132 KB Output is correct
31 Correct 85 ms 225992 KB Output is correct
32 Correct 88 ms 226128 KB Output is correct
33 Correct 89 ms 226044 KB Output is correct
34 Incorrect 87 ms 226052 KB Output isn't correct
35 Halted 0 ms 0 KB -