답안 #227650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
227650 2020-04-28T09:17:04 Z dvdg6566 Dango Maker (JOI18_dango_maker) C++14
13 / 100
5 ms 512 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 3010;
const ll INF = 1e18;
const ll MOD = 1e9+7;

int N,M;
string S;
int G[MAXN][MAXN];
unordered_map<ll,ll> U;
ll a;
pi dp[MAXN];
vi V[MAXN];

void dfs(int x, int p){
	pi out=mp(1,0);
	for (auto v:V[x])if(v!=p){
		if(dp[v].f)assert(0);
		dfs(v,x);
		out.f+=dp[v].s;
		out.s+=max(dp[v].f,dp[v].s);
	}
	dp[x]=out;
}

int main(){
	cin>>N>>M;
	for (int i=1;i<=N;++i){
		cin>>S;
		for (int j=1;j<=N;++j){
			if(S[j-1]=='R')G[i+1][j+1]=1;
			if(S[j-1]=='G')G[i+1][j+1]=2;
			if(S[j-1]=='W')G[i+1][j+1]=3;			
		}
	}
	for (int i=2;i<=N+1;++i)for (int j=1;j<=M+1;++j){
		if (G[i][j]!=2)continue;
		if ((G[i-1][j]==1&&G[i+1][j]==3)){
			U[MOD+i*MAXN+j]=++a; // Adding mod refers to vertical
		}
		if(G[i][j-1]==1&&G[i][j+1]==3){
			U[i*MAXN+j]=++a;
			if(U[MOD+i*MAXN+j]){
				V[a].pb(a-1);
				V[a-1].pb(a);
			}
		}
	}
	for (int i=2;i<=N+1;++i)for (int j=1;j<=M+1;++j){
		if (G[i][j]!=1)continue;
		if(G[i+1][j]!=2||G[i+2][j]!=3)continue;
		if (G[i][j+1]!=2||G[i][j+2]!=3)continue;
		ll a = U[(i+1)*MAXN+j+MOD];
		ll b = U[i*MAXN+j+1];
		V[a].pb(b);V[b].pb(a);
		// cout<<"Edge "<<a<<' '<<b<<'\n';
	}
	for (int i=2;i<=N+1;++i)for (int j=1;j<=M+1;++j){
		if (G[i][j]!=3)continue;
		if(G[i-1][j]!=2||G[i-2][j]!=1)continue;
		if (G[i][j-1]!=2||G[i][j-2]!=1)continue;
		ll a = U[(i-1)*MAXN+j+MOD];
		ll b = U[i*MAXN+j-1];
		V[a].pb(b);V[b].pb(a);
		// cout<<"Edge "<<a<<' '<<b<<'\n';
	}
	ll ans=0;
	for (int i=1;i<=a;++i)if(!dp[i].f){
		dfs(i,-1);
		ans+=max(dp[i].f,dp[i].s);
	}
	cout<<ans<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Incorrect 5 ms 512 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Incorrect 5 ms 512 KB Output isn't correct
20 Halted 0 ms 0 KB -