답안 #1089754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089754 2024-09-17T05:42:45 Z TrinhKhanhDung Dango Maker (JOI18_dango_maker) C++14
0 / 100
96 ms 212320 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 += abs(sum - num1 * 2);
    }

    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 96 ms 212136 KB Output is correct
2 Correct 87 ms 212308 KB Output is correct
3 Correct 85 ms 212072 KB Output is correct
4 Correct 83 ms 212240 KB Output is correct
5 Correct 83 ms 212240 KB Output is correct
6 Incorrect 90 ms 212320 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 212136 KB Output is correct
2 Correct 87 ms 212308 KB Output is correct
3 Correct 85 ms 212072 KB Output is correct
4 Correct 83 ms 212240 KB Output is correct
5 Correct 83 ms 212240 KB Output is correct
6 Incorrect 90 ms 212320 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 212136 KB Output is correct
2 Correct 87 ms 212308 KB Output is correct
3 Correct 85 ms 212072 KB Output is correct
4 Correct 83 ms 212240 KB Output is correct
5 Correct 83 ms 212240 KB Output is correct
6 Incorrect 90 ms 212320 KB Output isn't correct
7 Halted 0 ms 0 KB -