답안 #1089757

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089757 2024-09-17T05:53:25 Z TrinhKhanhDung Dango Maker (JOI18_dango_maker) C++14
13 / 100
111 ms 212352 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 = 3003;

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 84 ms 212304 KB Output is correct
2 Correct 102 ms 212240 KB Output is correct
3 Correct 96 ms 212308 KB Output is correct
4 Correct 87 ms 212304 KB Output is correct
5 Correct 98 ms 212060 KB Output is correct
6 Correct 88 ms 212304 KB Output is correct
7 Correct 85 ms 212312 KB Output is correct
8 Correct 84 ms 212072 KB Output is correct
9 Correct 83 ms 212264 KB Output is correct
10 Correct 83 ms 212092 KB Output is correct
11 Correct 85 ms 212304 KB Output is correct
12 Correct 94 ms 212252 KB Output is correct
13 Correct 83 ms 212312 KB Output is correct
14 Correct 80 ms 212308 KB Output is correct
15 Correct 83 ms 212216 KB Output is correct
16 Correct 84 ms 212180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 212304 KB Output is correct
2 Correct 102 ms 212240 KB Output is correct
3 Correct 96 ms 212308 KB Output is correct
4 Correct 87 ms 212304 KB Output is correct
5 Correct 98 ms 212060 KB Output is correct
6 Correct 88 ms 212304 KB Output is correct
7 Correct 85 ms 212312 KB Output is correct
8 Correct 84 ms 212072 KB Output is correct
9 Correct 83 ms 212264 KB Output is correct
10 Correct 83 ms 212092 KB Output is correct
11 Correct 85 ms 212304 KB Output is correct
12 Correct 94 ms 212252 KB Output is correct
13 Correct 83 ms 212312 KB Output is correct
14 Correct 80 ms 212308 KB Output is correct
15 Correct 83 ms 212216 KB Output is correct
16 Correct 84 ms 212180 KB Output is correct
17 Correct 82 ms 212304 KB Output is correct
18 Correct 111 ms 212312 KB Output is correct
19 Correct 102 ms 212268 KB Output is correct
20 Correct 87 ms 212220 KB Output is correct
21 Correct 83 ms 212304 KB Output is correct
22 Correct 88 ms 212232 KB Output is correct
23 Correct 84 ms 212308 KB Output is correct
24 Correct 86 ms 212220 KB Output is correct
25 Correct 85 ms 212296 KB Output is correct
26 Correct 86 ms 212164 KB Output is correct
27 Correct 89 ms 212260 KB Output is correct
28 Correct 89 ms 212308 KB Output is correct
29 Correct 84 ms 212304 KB Output is correct
30 Correct 92 ms 212220 KB Output is correct
31 Correct 84 ms 212308 KB Output is correct
32 Correct 86 ms 212304 KB Output is correct
33 Correct 86 ms 212352 KB Output is correct
34 Incorrect 86 ms 212308 KB Output isn't correct
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 212304 KB Output is correct
2 Correct 102 ms 212240 KB Output is correct
3 Correct 96 ms 212308 KB Output is correct
4 Correct 87 ms 212304 KB Output is correct
5 Correct 98 ms 212060 KB Output is correct
6 Correct 88 ms 212304 KB Output is correct
7 Correct 85 ms 212312 KB Output is correct
8 Correct 84 ms 212072 KB Output is correct
9 Correct 83 ms 212264 KB Output is correct
10 Correct 83 ms 212092 KB Output is correct
11 Correct 85 ms 212304 KB Output is correct
12 Correct 94 ms 212252 KB Output is correct
13 Correct 83 ms 212312 KB Output is correct
14 Correct 80 ms 212308 KB Output is correct
15 Correct 83 ms 212216 KB Output is correct
16 Correct 84 ms 212180 KB Output is correct
17 Correct 82 ms 212304 KB Output is correct
18 Correct 111 ms 212312 KB Output is correct
19 Correct 102 ms 212268 KB Output is correct
20 Correct 87 ms 212220 KB Output is correct
21 Correct 83 ms 212304 KB Output is correct
22 Correct 88 ms 212232 KB Output is correct
23 Correct 84 ms 212308 KB Output is correct
24 Correct 86 ms 212220 KB Output is correct
25 Correct 85 ms 212296 KB Output is correct
26 Correct 86 ms 212164 KB Output is correct
27 Correct 89 ms 212260 KB Output is correct
28 Correct 89 ms 212308 KB Output is correct
29 Correct 84 ms 212304 KB Output is correct
30 Correct 92 ms 212220 KB Output is correct
31 Correct 84 ms 212308 KB Output is correct
32 Correct 86 ms 212304 KB Output is correct
33 Correct 86 ms 212352 KB Output is correct
34 Incorrect 86 ms 212308 KB Output isn't correct
35 Halted 0 ms 0 KB -