답안 #463938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
463938 2021-08-12T04:39:03 Z amunduzbaev Game (eJOI20_game) C++14
20 / 100
17 ms 24048 KB
#include "bits/stdc++.h"
using namespace std;

const int N = 1e3 + 5;
vector<int> edges[N*N], cmp;
int used[N*N], block[N*N]	;

void dfs(int u){
	cmp.push_back(u);
	used[u] = 1;
	for(auto x : edges[u]){
		if(used[x]) continue;
		dfs(x);
	}
}

void solve(){
	int n, m; cin>>n>>m;
	for(int i=0;i<=n;i++){
		for(int j=1;j<=m;j++){
			char state; cin>>state;
			if(state == '0'){
				if(i && i < n){
					int a = (i - 1) * m + j, b = i * m + j;
					edges[a].push_back(b);
					edges[b].push_back(a);
				}
			} else {
				if(i) block[(i - 1) * m + j]++;
				if(i < n) block[i * m + j]++;
			}
		}
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<=m;j++){
			char state; cin>>state;
			if(state == '0'){
				if(j && j < m){
					int a = i * m + j, b = i * m + j + 1;
					edges[a].push_back(b);
					edges[b].push_back(a);
				}
			} else {
				block[i * m + j]++;
				block[i * m + j + 1]++;
			}
		}
	}
	
	vector<int> tt;
	for(int i=0;i<n;i++){
		for(int j=1;j<=m;j++){
			if(used[i * m + j]) continue;
			if(block[i * m + j] == 4) continue;
			cmp.clear();
			dfs(i * m + j);
			
			tt.push_back((int)cmp.size());
		}
	}

	sort(tt.begin(), tt.end());
	array<int, 2> res = {0, 0};
	for(int i=0;i<(int)tt.size();i++){
		res[i&1] += tt[i];
	}
	
	cout<<res[1] - res[0]<<"\n";
}

/*

3 3
111
111
111
111
1111
1111
1111

*/

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t = 1;
	//~ cin>>t;
	while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 24012 KB Output is correct
2 Correct 16 ms 23980 KB Output is correct
3 Correct 16 ms 24012 KB Output is correct
4 Correct 16 ms 24012 KB Output is correct
5 Correct 16 ms 24012 KB Output is correct
6 Correct 15 ms 24036 KB Output is correct
7 Correct 16 ms 24044 KB Output is correct
8 Correct 16 ms 24032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 24024 KB Output is correct
2 Correct 15 ms 24012 KB Output is correct
3 Correct 15 ms 23964 KB Output is correct
4 Correct 17 ms 24048 KB Output is correct
5 Incorrect 15 ms 23952 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 24044 KB Output is correct
2 Correct 16 ms 23944 KB Output is correct
3 Correct 15 ms 24024 KB Output is correct
4 Correct 17 ms 24048 KB Output is correct
5 Incorrect 15 ms 23940 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 24024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 24012 KB Output is correct
2 Correct 16 ms 23980 KB Output is correct
3 Correct 16 ms 24012 KB Output is correct
4 Correct 16 ms 24012 KB Output is correct
5 Correct 15 ms 24024 KB Output is correct
6 Correct 15 ms 24012 KB Output is correct
7 Correct 15 ms 23964 KB Output is correct
8 Correct 17 ms 24048 KB Output is correct
9 Correct 16 ms 24012 KB Output is correct
10 Correct 15 ms 24036 KB Output is correct
11 Correct 16 ms 24044 KB Output is correct
12 Correct 16 ms 24032 KB Output is correct
13 Incorrect 15 ms 23952 KB Output isn't correct
14 Halted 0 ms 0 KB -