QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#102843#5520. Distance Paritiesqawszx#WA 1ms1744kbC++141.2kb2023-05-03 18:43:152023-05-03 18:43:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 18:43:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:1744kb
  • [2023-05-03 18:43:15]
  • 提交

answer

#include<algorithm>
#include<cstring>
#include<cstdio>
#define ll long long
#define qwq 200007
inline int read(){
	char c=getchar();
	int x=0;int flag=0;
	for(;c<'0'||c>'9';c=getchar())flag|=(c=='-');
	for(;c<='9'&&c>='0';c=getchar())x=(x<<1)+(x<<3)+c-'0';
	if(flag)return -x;
	return x;
}
int n,m;
int T;
char s[107][107];
const int inf=1e9+7;
int dis[107][107];
int main(){
	scanf("%d",&T);
	while(T--){
		int n=read();
		for(int i=1;i<=n;++i){
			scanf("%s",s[i]+1);
		}
		for(int i=1;i<=n;++i){
			for(int j=1;j<=n;++j){
				if(i==j){
					if(s[i][j]=='1'){	
						printf("NO\n");
						goto here;
					}
					dis[i][j]=0;
				}
				else if(s[i][j]=='1')dis[i][j]=1;
				else dis[i][j]=inf;
			}
		}
		for(int k=1;k<=n;++k){
			for(int i=1;i<=n;++i){
				for(int j=1;j<=n;++j){
					dis[i][j]=std::min(dis[i][j],dis[i][k]+dis[k][j]);
				}
			}
		}
		for(int i=1;i<=n;++i){
			for(int j=1;j<=n;++j){
				if((dis[i][j]&1)!=(s[i][j]-'0')){
					printf("NO\n");
					goto here;
				}
			}
		}
		printf("YES\n");
		for(int i=1;i<=n;++i){
			for(int j=i+1;j<=n;++j){
				if(s[i][j]=='1')printf("%d %d\n",i,j);
			}
		}
		here:;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 1744kb

input:

3
3
011
101
110
4
0100
1000
0001
0010
5
01010
10101
01010
10101
01010

output:

YES
1 2
1 3
2 3
NO
YES
1 2
1 4
2 3
2 5
3 4
4 5

result:

wrong answer Integer 1 violates the range [2, 3] (test case 1)