Submission #38075325


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define f(i,j,k) for(register int i=j;i<=k;++i)
#define g(i,j,k) for(register int i=j;i>=k;--i)
int n,m,s,l;
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
const int inf=1e9+7;
struct Dinic{
	struct xyz{int x,y,z;};
	queue<int>p;
	vector<xyz>q[1<<17];
	int now[1<<17],dis[1<<17],n;
	inline int Min(int x,int y){return x<y?x:y;}
	inline void add(int x,int y,int z=1){
		int ix=q[x].size(),iy=q[y].size();
		q[x].push_back((xyz){y,iy,z});if(n<x)n=x;
		q[y].push_back((xyz){x,ix,0});if(n<y)n=y;
	}
	inline int bfs(int s,int t){
		int x,y;
		f(i,1,n)now[i]=0,dis[i]=inf;
		p.push(s),dis[s]=0;
		while(p.size()){
			x=p.front();p.pop();
			f(i,1,q[x].size())if(q[x][i-1].z&&dis[y=q[x][i-1].x]==inf)p.push(y),dis[y]=dis[x]+1;
		}
		return dis[t]<inf;
	}
	int dfs(int x,int t,int v){
		if(!v)return 0;
		if(x==t)return v;
		register int y,z,re=0;
		f(i,now[x]+1,q[x].size())if(dis[x]+1==dis[y=q[x][now[x]=i-1].x]){
			z=dfs(y,t,Min(v,q[x][i-1].z));v-=z;re+=z;
			q[x][i-1].z-=z;q[y][q[x][i-1].y].z+=z;
			if(!v)return re;
		}
		if(!re)dis[x]=inf;
		return re;
	}
	inline int MF(int S,int T,int re=0){while(bfs(S,T))re+=dfs(S,T,inf);return re;}
	inline int de(int x,int y){return dis[x]<inf&&dis[y]>=inf;}
	inline int hf(int x,int y){f(i,1,q[x].size())if(q[x][i-1].x==y)return q[x][i-1].z!=0;return 0;}
}G;
int mst[202020];
char c[303][303];
inline int I(int x,int y){return (x-1)*m+y;} 
signed main(){
	cin>>n>>m;
	s=n*m+4;l=n*m+2;
	f(i,1,n)scanf("%s",c[i]+1);
	f(i,1,n)f(j,2,m)if(c[i][j]!='1'&&c[i][j-1]!='1')((i+j)%2)?G.add(I(i,j),I(i,j-1)):G.add(I(i,j-1),I(i,j));
	f(i,2,n)f(j,1,m)if(c[i][j]!='1'&&c[i-1][j]!='1')((i+j)%2)?G.add(I(i,j),I(i-1,j)):G.add(I(i-1,j),I(i,j));
	f(i,1,n)f(j,1,m)if(c[i][j]=='2')((i+j)%2)?G.add(s,I(i,j)):G.add(I(i,j),l);
	f(i,1,n)f(j,1,m)if(c[i][j]=='?'&&i%2!=j%2)G.add(s,I(i,j));
	if(n%2==0||m%2==0)G.MF(s,l);
	f(i,1,n)f(j,1,m)if(c[i][j]=='?'&&i%2==j%2)G.add(I(i,j),l);G.MF(s,l);
	register int re=0;
	f(i,1,n)f(j,1,m)mst[I(i,j)]=(c[i][j]=='2');
	f(i,1,G.q[s].size())if(mst[G.q[s][i-1].x]&&G.q[s][i-1].z!=0)re=1;
	f(i,1,G.q[l].size())if(mst[G.q[l][i-1].x]&&G.q[l][i-1].z==0)re=1;
//	f(i,1,n){
//		f(j,1,m){
//			if(c[i][j]=='2')cout<<((i+j)%2?G.hf(s,I(i,j)):G.hf(I(i,j),l));
//			else cout<<'0';
//		}
//		cout<<endl;
//	}
	if(re)printf("No\n");
	else printf("Yes\n");
	return 0;
}

Submission Info

Submission Time
Task G - Tatami
User scyxdl
Language C++ (GCC 9.2.1)
Score 600
Code Size 2510 Byte
Status AC
Exec Time 442 ms
Memory 15180 KiB

Compile Error

./Main.cpp: In member function ‘int Dinic::bfs(int, int)’:
./Main.cpp:25:5: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   25 |   f(i,1,n)now[i]=0,dis[i]=inf;
      |     ^
./Main.cpp:4:35: note: in definition of macro ‘f’
    4 | #define f(i,j,k) for(register int i=j;i<=k;++i)
      |                                   ^
./Main.cpp:29:6: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   29 |    f(i,1,q[x].size())if(q[x][i-1].z&&dis[y=q[x][i-1].x]==inf)p.push(y),dis[y]=dis[x]+1;
      |      ^
./Main.cpp:4:35: note: in definition of macro ‘f’
    4 | #define f(i,j,k) for(register int i=j;i<=k;++i)
      |                                   ^
./Main.cpp:4:40: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<Dinic::xyz>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    4 | #define f(i,j,k) for(register int i=j;i<=k;++i)
......
   29 |    f(i,1,q[x].size())if(q[x][i-1].z&&dis[y=q[x][i-1].x]==inf)p.push(y),dis[y]=dis[x]+1;
      |      ~~~~~~~~~~~~~~~                    
./Main.cpp:29:4: note: in expansion of macro ‘f’
   29 |    f(i,1,q[x].size())if(q[x][i-1].z&&dis[y=q[x][i-1].x]==inf)p.push(y),dis[y]=dis[x]+1;
      |    ^
./Main.cpp: In member function ‘int Dinic::dfs(int, int, int)’:
./Main.cpp:36:16: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   36 |   register int y,z,re=0;
      |                ^
./Main.cpp:36:18: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   36 |   register int y,z,re=0;
      |                  ^
./Main.cpp:36:20: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   36 |   register int y,z,re=0;
      |                    ^~
./Main.cpp:37:5: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   37 |   f(i,now[x]+1,q[x].size())if(dis[x]+1==dis[y=q[x][now[x]=i-1].x]){
      |   ...

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 8 ms 6648 KiB
hand_02.txt AC 3 ms 6696 KiB
hand_03.txt AC 4 ms 6720 KiB
hand_04.txt AC 6 ms 6760 KiB
hand_05.txt AC 5 ms 6732 KiB
hand_06.txt AC 6 ms 6720 KiB
hand_07.txt AC 6 ms 6584 KiB
random_01.txt AC 404 ms 14948 KiB
random_02.txt AC 287 ms 12648 KiB
random_03.txt AC 21 ms 7740 KiB
random_04.txt AC 225 ms 12028 KiB
random_05.txt AC 389 ms 14956 KiB
random_06.txt AC 281 ms 13052 KiB
random_07.txt AC 42 ms 8388 KiB
random_08.txt AC 45 ms 8524 KiB
random_09.txt AC 442 ms 14892 KiB
random_10.txt AC 51 ms 8292 KiB
random_11.txt AC 81 ms 8920 KiB
random_12.txt AC 31 ms 7988 KiB
random_13.txt AC 412 ms 15108 KiB
random_14.txt AC 75 ms 8880 KiB
random_15.txt AC 128 ms 9832 KiB
random_16.txt AC 84 ms 9148 KiB
random_17.txt AC 394 ms 15180 KiB
random_18.txt AC 31 ms 7860 KiB
random_19.txt AC 376 ms 14716 KiB
random_20.txt AC 40 ms 7992 KiB
random_21.txt AC 389 ms 15152 KiB
random_22.txt AC 136 ms 10340 KiB
random_23.txt AC 75 ms 8868 KiB
random_24.txt AC 15 ms 7280 KiB
random_25.txt AC 89 ms 9148 KiB
random_26.txt AC 39 ms 7700 KiB
random_27.txt AC 255 ms 12744 KiB
random_28.txt AC 12 ms 7020 KiB
random_29.txt AC 22 ms 7568 KiB
random_30.txt AC 28 ms 7944 KiB
random_31.txt AC 16 ms 7404 KiB
random_32.txt AC 157 ms 10808 KiB
sample_01.txt AC 9 ms 6700 KiB
sample_02.txt AC 5 ms 6600 KiB
sample_03.txt AC 5 ms 6576 KiB