Submission #38071367


Source Code Expand

#include<bits/stdc++.h>
#define N 90009
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
inline ll rd(){
	ll x=0;char c=getchar();bool f=0;
	while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
	while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return f?-x:x;
}
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
queue<int>q;
int deep[N],head[N],cur[N],n,m,tot=1,tag[N];
char s[309][309];
int id[309][309],tt;
struct edge{
	int n,to,l;
}e[N*20];
inline void add(int u,int v,int l){
	e[++tot].n=head[u];e[tot].to=v;head[u]=tot;e[tot].l=l;
	e[++tot].n=head[v];e[tot].to=u;head[v]=tot;e[tot].l=0;
}
bool bfs(int s,int t){
	memset(deep,0x3f,sizeof(deep));
	deep[s]=0;
	for(int i=0;i<=t;++i)cur[i]=head[i];
	q.push(s);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i;i=e[i].n){
			int v=e[i].to;
			if(e[i].l&&deep[v]==inf){
				deep[v]=deep[u]+1;
				q.push(v);
			} 
		}
	}
	return deep[t]!=inf;
}
int dfs(int s,int t,int l){
	if(s==t||!l)return l;
	int flow=0,f;
	for(int i=cur[s];i;i=e[i].n){
		int v=e[i].to;cur[s]=i;
		if(deep[v]==deep[s]+1&&(f=dfs(v,t,min(e[i].l,l)))){
			flow+=f;l-=f;
			e[i].l-=f;e[i^1].l+=f;
			if(!l)break;
		}
	}
	return flow;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		cin>>(s[i]+1);
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j)id[i][j]=++tt;
	}
	int pp=0;
	int S=tt+1,T=tt+2;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j)if(s[i][j]!='1'){
			if((i+j)&1){
				add(S,id[i][j],1);
				if(s[i][j]=='2')tag[id[i][j]]=1;
				for(int k=0;k<4;++k){
					int xx=i+dx[k];
					int yy=j+dy[k];
					if(xx<1||xx>n||yy<1||yy>m)continue;
					if(s[xx][yy]!='1')add(id[i][j],id[xx][yy],1);
				}
			//	if(s[i][j]=='?')add(id[i][j],T,1);
			}
			else{
				if(s[i][j]=='2')tag[id[i][j]]=2;
				add(id[i][j],T,1);
			//	if(s[i][j]=='?')add(S,id[i][j],1);
			}
		}
	} 
	int ans=0;
	while(bfs(S,T))ans+=dfs(S,T,inf);
	int gg=0;
	for(int i=head[S];i;i=e[i].n){
		int v=e[i].to;
	//	cout<<v<<" ? "<<e[i].l<<" "<<tag[v]<<endl;
		if(tag[v]==1&&e[i].l)gg=1;
	}
	for(int i=head[T];i;i=e[i].n){
		int v=e[i].to;
//		cout<<v<<" "<<e[i].l<<" "<<tag[v]<<endl;
		if(tag[v]==2&&e[i].l==0)gg=1;
	}
	if(gg==0)cout<<"Yes";
	else cout<<"No";
    return 0;
}

Submission Info

Submission Time
Task G - Tatami
User comld
Language C++ (GCC 9.2.1)
Score 600
Code Size 2371 Byte
Status AC
Exec Time 395 ms
Memory 10076 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:65:6: warning: unused variable ‘pp’ [-Wunused-variable]
   65 |  int pp=0;
      |      ^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 42
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 7 ms 3856 KiB
hand_02.txt AC 2 ms 3924 KiB
hand_03.txt AC 6 ms 3928 KiB
hand_04.txt AC 2 ms 3912 KiB
hand_05.txt AC 2 ms 4004 KiB
hand_06.txt AC 2 ms 3864 KiB
hand_07.txt AC 2 ms 3924 KiB
random_01.txt AC 395 ms 9880 KiB
random_02.txt AC 266 ms 8364 KiB
random_03.txt AC 18 ms 4984 KiB
random_04.txt AC 186 ms 7904 KiB
random_05.txt AC 360 ms 9932 KiB
random_06.txt AC 262 ms 8544 KiB
random_07.txt AC 37 ms 5356 KiB
random_08.txt AC 41 ms 5328 KiB
random_09.txt AC 367 ms 10076 KiB
random_10.txt AC 40 ms 5056 KiB
random_11.txt AC 55 ms 5780 KiB
random_12.txt AC 31 ms 4852 KiB
random_13.txt AC 373 ms 9944 KiB
random_14.txt AC 73 ms 5676 KiB
random_15.txt AC 88 ms 6524 KiB
random_16.txt AC 59 ms 5948 KiB
random_17.txt AC 358 ms 9900 KiB
random_18.txt AC 24 ms 4632 KiB
random_19.txt AC 382 ms 9784 KiB
random_20.txt AC 30 ms 4852 KiB
random_21.txt AC 361 ms 9920 KiB
random_22.txt AC 141 ms 6728 KiB
random_23.txt AC 57 ms 5900 KiB
random_24.txt AC 13 ms 4652 KiB
random_25.txt AC 80 ms 5768 KiB
random_26.txt AC 24 ms 4664 KiB
random_27.txt AC 238 ms 8360 KiB
random_28.txt AC 9 ms 4344 KiB
random_29.txt AC 17 ms 4888 KiB
random_30.txt AC 27 ms 4944 KiB
random_31.txt AC 14 ms 4684 KiB
random_32.txt AC 171 ms 6924 KiB
sample_01.txt AC 3 ms 3928 KiB
sample_02.txt AC 2 ms 3956 KiB
sample_03.txt AC 3 ms 3932 KiB