QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#769945#7857. (-1,1)-SumpleteTom22lWA 7ms13872kbC++232.7kb2024-11-21 20:00:292024-11-21 20:00:29

Judging History

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

  • [2024-11-21 20:00:29]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:13872kb
  • [2024-11-21 20:00:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int Read(){
	int x=0;
	char ch=getchar();bool f=0;
	while(ch<'0'||ch>'9') if(ch=='-')f=1,ch=getchar(); else if(ch==EOF)return 0; else ch=getchar();
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
bool f[4005][4005];
int c[4005][2];
int r[4005][2];
int dc[4005];
int dr[4005];
int cs[4005];
int rs[4005];
bool ans[4005][4005];
bool isans[4005][4005];
bool visc[4005];
bool visr[4005];
signed main(){
//	freopen("1.in","r",stdin);
//	freopen(".out","w",stdout);
	int n=Read();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			char ch=getchar();
			while(ch!='+'&&ch!='-') ch=getchar();
			if(ch=='+') f[i][j]=1,c[i][1]++,r[j][1]++;
			else c[i][0]++,r[j][0]++;
		}
	}
//	for(int i=1;i<=n;i++) cout<<r[i][0]<<' '<<r[i][1]<<endl;
	int suma=0;
	for(int i=1;i<=n;i++){
		cs[i]=Read();
		suma+=cs[i];
	}for(int i=1;i<=n;i++){
		rs[i]=Read();
		suma-=rs[i];
	}if(suma){
		printf("No\n");
		return 0;
	}
	int fin=0;
	while(fin<2*n){
		bool flag=0;
		int nfin=0;
		for(int i=1;i<=n;i++){
			if(visc[i]) continue;
			if(dc[i]+c[i][1]<cs[i]){
				printf("No\n");
				return 0;
			}else if(dc[i]+c[i][1]==cs[i]){
				flag=1;
				fin++;visc[i]=1;
				for(int j=1;j<=n;j++){
					if(!isans[i][j]) isans[i][j]=1,ans[i][j]=f[i][j],r[j][f[i][j]]--,dr[j]+=f[i][j];
				}
			}else if(dc[i]-c[i][0]>cs[i]){
				printf("No\n");
				return 0;
			}else if(dc[i]-c[i][0]==cs[i]){
				flag=1;
				fin++;visc[i]=1;
				for(int j=1;j<=n;j++){
					if(!isans[i][j]) isans[i][j]=1,ans[i][j]=(!f[i][j]),r[j][f[i][j]]--,dr[j]-=(!f[i][j]);
				}
			}else nfin=i;
		}for(int j=1;j<=n;j++){
			if(visr[j]) continue;
			if(dr[j]+r[j][1]<rs[j]){
				printf("No\n");
				return 0;
			}else if(dr[j]+r[j][1]==rs[j]){
				flag=1;
				fin++;visr[j]=1;
				for(int i=1;i<=n;i++){
					if(!isans[i][j]) isans[i][j]=1,ans[i][j]=f[i][j],c[i][f[i][j]]--,dc[i]+=f[i][j];
				}
			}else if(dr[j]-r[j][0]>rs[j]){
				printf("No\n");
				return 0;
			}else if(dr[j]-r[j][0]==rs[j]){
				flag=1;
				fin++;visr[j]=1;
				for(int i=1;i<=n;i++){
					if(!isans[i][j]) isans[i][j]=1,ans[i][j]=(!f[i][j]),c[i][f[i][j]]--,dc[i]-=(!f[i][j]);
				}
			}
		}if(!flag){
			int i=nfin;
			visc[i]=1;fin++;
			for(int j=1;j<=n;j++){
				if(isans[i][j]) continue;
				if(cs[i]>dc[i]) isans[i][j]=1,ans[i][j]=f[i][j],r[j][f[i][j]]--,dr[j]+=f[i][j],dc[i]+=f[i][j];
				else if(cs[i]<dc[i]) isans[i][j]=1,ans[i][j]=(!f[i][j]),r[j][f[i][j]]--,dr[j]-=(!f[i][j]),dc[i]-=(!f[i][j]);
				else isans[i][j]=1,ans[i][j]=0,r[j][f[i][j]]--;
			}
		}
	}
	printf("Yes\n");
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++) printf("%d",ans[i][j]);
		printf("\n");
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7832kb

input:

3
+-+
-++
+-+
1 1 1
1 -1 3

output:

Yes
111
001
001

result:

ok n=3

Test #2:

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

input:

3
---
-++
+++
-2 -1 0
-2 -1 0

output:

Yes
110
100
000

result:

ok n=3

Test #3:

score: 0
Accepted
time: 1ms
memory: 7732kb

input:

3
+-+
-++
++-
1 0 2
2 2 -1

output:

No

result:

ok n=3

Test #4:

score: 0
Accepted
time: 1ms
memory: 5612kb

input:

1
-
-1
1

output:

No

result:

ok n=1

Test #5:

score: 0
Accepted
time: 1ms
memory: 7856kb

input:

1
-
0
0

output:

Yes
0

result:

ok n=1

Test #6:

score: 0
Accepted
time: 1ms
memory: 7936kb

input:

20
+-------+-----+++-++
-+-++++----++-++-++-
-+++--+---+--+-++---
-+++-+--+----++---+-
+++-+-++++++-+-+---+
-++-----+----++++++-
+-++--+++++-++-+----
+-+----+---+-+++--+-
+++++-+++++----+--+-
------++++---+--++--
++++--------++++--+-
-+-+-++++-+-++-++--+
---+-++---+-++-++---
+-++++-++----+-+++--
+-+...

output:

Yes
00010101111100111110
11011101011010110011
10100001010101011101
10000011111101100111
11101010100001000100
10000000010101001011
01000100000111000100
01010000000001000110
10000000000000000100
11111000000000001000
00001111110000000000
00000000000000001000
00010100000000000000
10110000000000000000
01...

result:

ok n=20

Test #7:

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

input:

100
++++-+-+--++++++-+--+--++-+-+--+++++-+++---+-+-+-++-+-+++-------+-++--+-++--+--+++++-++-+---+--+--++
-++--++-+-++++-+---++-+-+-+-+-+-+-+-+--+-+--+--+++---+--+-----+-----+-++-++-+-++++++--+-+++-+++-++++
--+---++-++--++-+++-------+--+-++------+-----+--+----++++++++-+--+++++--++--+-+-+++---+--+++-+...

output:

Yes
0000101011100010100101110110101111110111000101010110101110000000101100101100100111110110100010010011
1101000100100001110100001110100010101001010010011100010010000010000010110110101111110010111011101111
1001110011111011000110101110011110000001000001001000011111111010011111001100101011100010011101...

result:

ok n=100

Test #8:

score: -100
Wrong Answer
time: 7ms
memory: 13872kb

input:

500
--+-+-+-++-----+++--+-+++-+---+-+-------+++--++++++-+--++--+-+-++++-++++--++--+---++--++----++--+---++-++--+-----+-+---++-++++-+++++++---++-++--+-++++-+----++-+++-+++---+--+++-+--++-++--+++++++-+++--+---+---+-+---++-+-+--+-+++-++-----+++-++-+++-+-++--++++++-+-++-+++---++-+++-++----+--+++----++++...

output:

No

result:

wrong answer Jury has the answer but participant has not