QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#503215#2563. Curly RacetrackdzhearminsWA 0ms3880kbC++142.8kb2024-08-03 16:59:412024-08-03 16:59:42

Judging History

你现在查看的是最新测评结果

  • [2024-08-03 16:59:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3880kb
  • [2024-08-03 16:59:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ff(i,l,r) for(int i=l;i<=r;++i)
#define fi(l,r) ff(i,l,r)
#define ll long long
#define P 998244353
#define N 105
#define R 10005
#define M 20005
#define N1(x) {printf("-1");exit(0);}
bool inc(char ch){
	return ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='.'||ch=='o'||ch=='x';
}
int mp[N][N],n,m,tim,ans;
int tot,nxt[M],to[M],fir[N],pip[N],cnt,cl[N],cr[N],ci[N],cntx;
bool vis[N]={0};
void add(int x,int y){
	nxt[++tot]=fir[x];
	fir[x]=tot;
	to[tot]=y;
}
bool hungary(int x){
	if(vis[x])return false;
	for(int e=fir[x];e;e=nxt[e]){
		int u=to[e];
		if(vis[u]==tim)continue;
		vis[x]=vis[u]=tim;
		if(pip[u]==0||hungary(pip[u])){;
			pip[x]=u;
			pip[u]=x;
			return true;
		}
	}
	return false;
}
void dealX(int y,int l,int r){
	int len=r-l+1;
	bool fg=0;
	if(mp[y][l-1]=='3'||mp[y][l-1]=='4')--len;
	if(mp[y][r+1]=='1'||mp[y][r+1]=='2')--len;
	if(len&1){
		ff(x,l,r){
			if(mp[y][x]!='o')fg=1;
			if(mp[y][x]=='x')return;
		}
		if(fg==0)N1("k");
		cl[++cnt]=l;
		cr[cnt]=r;
		ci[cnt]=y;
//		printf("%d:dealX(%d,%d,%d)\n",cnt,y,l,r);
	}
	return;
}
void dealY(int x,int u,int d){
	int len=d-u+1;
	bool fg=0;
	if(mp[u-1][x]=='2'||mp[u-1][x]=='4')--len;
	if(mp[d+1][x]=='1'||mp[d+1][x]=='3')--len;
	if(len&1){
		ff(y,u,d){
			if(mp[y][x]!='o')fg=1;
			if(mp[y][x]=='x')return;
		}
		if(fg==0)N1("j")
		cl[++cnt]=u;
		cr[cnt]=d;
//		printf("%d:dealY(%d,%d,%d)\n",cnt,x,u,d);
		fi(1,cntx)if(cl[i]<=x&&cr[i]>=x&&ci[i]>=u&&ci[i]<=d&&
			(mp[ci[i]][x]=='.'||mp[ci[i]][x]=='x'))add(i,cnt),add(cnt,i);
	}
	return;
}
int main(){
//	freopen("c.in","r",stdin);
//	freopen("c.out","w",stdout);
	scanf("%d %d",&n,&m);
	ff(y,1,n){
		char ch=getchar();
		while(not inc(ch))ch=getchar();
		ff(x,1,m){
			mp[y][x]=ch;
			ch=getchar();
		}
	}
	ff(y,1,n){
		if(mp[y][1]=='1'||mp[y][1]=='2')N1("i");
		if(mp[y][m]=='3'||mp[y][m]=='4')N1("h");
		int l=0,r=1;
		for(;r<=m+1;++r){
			if(mp[y][r]=='1'||mp[y][r]=='2'||mp[y][r]=='3'||mp[y][r]=='4'||r==m+1){
				if(l==r-1){
					if(mp[y][r]=='1'||mp[y][r]=='2'){
						if(mp[y][l]=='1'||mp[y][l]=='1')N1("g");
					}else if(mp[y][l]=='3'||mp[y][l]=='4')N1("f");
				}else dealX(y,l+1,r-1);
				l=r;
			}
		}
	}
	cntx=cnt;
	ff(x,1,m){
		if(mp[1][x]=='1'||mp[1][x]=='3')N1("e");
		if(mp[n][x]=='2'||mp[n][x]=='4')N1("d");
		int u=0,d=1;
		for(;d<=n+1;++d){
			if(mp[d][x]=='1'||mp[d][x]=='2'||mp[d][x]=='3'||mp[d][x]=='4'||d==n+1){
				if(u==d-1){
					if(mp[d][x]=='1'||mp[d][x]=='3'){
						if(mp[u][x]=='1'||mp[u][x]=='3')N1("b");
					}else if(mp[u][x]=='2'||mp[u][x]=='4')N1("a");
				}else dealY(x,u+1,d-1);
				u=d;
			}
		}
	}
	ans=n*m-cnt;
	fi(1,cntx){
		++tim;
		if(pip[i]==0)hungary(i);
	}
	fi(1,cntx)if(pip[i]!=0)++ans;
	ff(y,1,n)ff(x,1,m)ans-=(mp[y][x]=='x');
	printf("%d\n",ans);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3880kb

input:

4 5
4...x
.2..2
.o1x.
3..3o

output:

12

result:

ok 1 number(s): "12"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

2 3
4o2
3x1

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3836kb

input:

100 47
.....4.42..4.2....4242........o242424....o4....
3...3........31...1......2..3...o1313.......13.
.o..........2...14...........2..4........2..2..
..................2....232.......4..13..x.41...
42...1.4....3..3...1.2.32...1...4...424..2...4.
.1.3.2...242...4...4..............23...........
..x.....

output:

4650

result:

wrong answer 1st numbers differ - expected: '4166', found: '4650'