Submission #284263

# Submission time Handle Problem Language Result Execution time Memory
284263 2020-08-27T06:03:41 Z YJU Dango Maker (JOI18_dango_maker) C++14
13 / 100
1 ms 512 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=3e3+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()

map<ll,vector<ll> > v;
map<ll,ll> col;
ll cnt[3],n,m,ans;
vector<ll> point;
char c[N][N];


bool valid(ll xa,ll ya,ll xb,ll yb){
	if(xa>xb)swap(xa,xb);
	if(ya>yb)swap(ya,yb);
	ll xm=(xa+xb)/2,ym=(ya+yb)/2;
	if(xa<0||xb>=n||ya<0||yb>=m||c[xm][ym]!='G')return 0;
	if(ya==yb){
		return ((c[xa][ym]=='R'&&c[xb][ym]=='W'));
	}else{
		return ((c[xm][ya]=='R'&&c[xm][yb]=='W'));
	}
}

void DFS(ll nd){
	++cnt[col[nd]];
	for(auto i:v[nd]){
		if(col[i]==0){
			col[i]=3-col[nd];
			DFS(i);
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	REP(i,n)REP(j,m){
		cin>>c[i][j];
	}
	REP(i,n)REP(j,m){
		ll nd=i*m+j;
		if(c[i][j]=='G'){
			if(valid(i-1,j,i+1,j)&&valid(i,j-1,i,j+1)){
				v[nd*2].pb(nd*2+1);
				v[nd*2+1].pb(nd*2);
			}
			if(valid(i-1,j,i+1,j))point.pb(nd*2);
			if(valid(i,j-1,i,j+1))point.pb(nd*2+1);
		}else{
			vector<ll> tmp;
			if(valid(i-2,j,i,j))tmp.pb(2*((i-1)*m+j));
			if(valid(i,j,i+2,j))tmp.pb(2*((i+1)*m+j));
			if(valid(i,j-2,i,j))tmp.pb(2*(i*m+(j-1))+1);
			if(valid(i,j,i,j+2))tmp.pb(2*(i*m+(j+1))+1);
			for(auto ii:tmp)for(auto jj:tmp){
				if(ii==jj)continue;
				v[ii].pb(jj);v[jj].pb(ii);
			}
		}
	}
	for(auto i:point){
		cnt[1]=cnt[2]=0;
		if(col[i]==0){
			col[i]=1;
			DFS(i);
			ans+=max(cnt[1],cnt[2]);
		}
	}
	cout<<ans<<"\n";
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Incorrect 1 ms 384 KB Output isn't correct
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Incorrect 1 ms 384 KB Output isn't correct
35 Halted 0 ms 0 KB -