Submission #1088934

# Submission time Handle Problem Language Result Execution time Memory
1088934 2024-09-15T14:52:32 Z vjudge1 Game (eJOI20_game) C++17
20 / 100
1 ms 600 KB
#include <bits/stdc++.h>
using namespace std;
#define fastinput cin.tie(nullptr)->sync_with_stdio(false);
#define endl '\n'
#define ll long long
const ll mOd=1e9+7;
const int mAx=INT_MAX;
const int nUm=1e3+3;
int n,m,k=0;
int a[22][22],b[22][22],c[22][22];
void dfs(int i, int j){
	if(i<0 || i>=n || j<0 || j>=m || c[i][j])return;
	c[i][j]=k;
	// cout<<i<<" "<<j<<".. "<<a[i][j]<<" "<<a[i+1][j]<<" "<<b[i][j]<<" "<<b[i][j+1]<<endl;
	if(a[i][j]==0)   dfs(i-1,j);
	if(a[i+1][j]==0) dfs(i+1,j);
	if(b[i][j]==0)   dfs(i,j-1);
	if(b[i][j+1]==0) dfs(i,j+1);
}
int main()
{
    fastinput;
    cin>>n>>m;
	for(int i=0 ; i<n+1 ; i++){
		string s; cin>>s;
		for(int j=0 ; j<m ; j++){
			a[i][j]=s[j]-'0';
		}
	}
	for(int i=0 ; i<n ; i++){
		string s; cin>>s;
		for(int j=0 ; j<m+1 ; j++){
			b[i][j]=s[j]-'0';
		}
	}
	for(int i=0 ; i<n ; i++){
		for(int j=0 ; j<m ; j++){
			if(a[i][j] && a[i+1][j] && b[i][j] && b[i][j+1])continue;
			if(!c[i][j])
			{
				k++;
				dfs(i,j);
			}
		}
	}
	int a[k+5]={},ans=0,l=-1;
	for(int i=0 ; i<n ; i++){
		for(int j=0 ; j<m ; j++){
			if(c[i][j]!=0)
				a[c[i][j]]++;
			// cout<<c[i][j]<<" ";
		}
		// cout<<endl;
	}
	// cout<<k<<endl;
	sort(a,a+k+5);
	for(int i=0 ; i<k+5 ; i++){
		// cout<<a[i]<<" ";
		if(!a[i])continue;
		ans+=l*a[i];
		l*=-1;
	}
	cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 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 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 600 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 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 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -