QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#812246#4282. IntervalshicgnliawWA 1ms5764kbC++141.1kb2024-12-13 13:22:302024-12-13 13:22:35

Judging History

This is the latest submission verdict.

  • [2024-12-13 13:22:35]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5764kb
  • [2024-12-13 13:22:30]
  • Submitted

answer

#include<bits/stdc++.h>
#define its(x,y) (max(0,L-abs(x-y)))
using namespace std;
const int N = 1005,L = 1e6;
inline int read(){
	int s = 0;char ch = getchar();
	while(!isdigit(ch))ch = getchar();
	while(isdigit(ch)){s = (s<<1)+(s<<3)+ch-'0';ch = getchar();}
	return s;
}
int vis[N],tot,e[N][N],pos[N],n,fa[N];
void dfs(int p){
	vis[p] = tot;
	for(int v = 1;v<=n;v++){
		if(vis[v]||!e[p][v])continue;
		fa[v] = p;
		pos[v] = pos[p]+L-e[p][v];
		if(its(pos[v],pos[fa[p]])!=e[fa[p]][v]){
			pos[v] = (pos[p]<<1)-pos[v];
		}
		if(its(pos[v],pos[fa[p]])!=e[fa[p]][v]){
			printf("No\n");
			exit(0);
		}
		dfs(v);
	}
}
int main(){
	n = read();
	for(int i = 1;i<=n;i++)
		for(int j = 1;j<=n;j++)e[i][j] = read();
	for(int i = 1,v;i<=n;i++){
		if(!vis[i]){
			v = 0;
			for(int j = i+1;j<=n;j++)if(e[i][j])v = j;
			if(!v)continue;
			pos[v] = L-e[i][v];
			fa[v] = i;fa[i] = v;
			vis[v] = vis[i] = ++tot;
			dfs(i);dfs(v);
		}
	}
	for(int i = 1;i<n;i++){
		for(int j = i+1;j<=n;j++){
			if(vis[i]==vis[j]&&its(pos[i],pos[j])!=e[i][j]){
				printf("No\n");
				return 0;
			}
		} 
	}
	printf("Yes\n");
	return 0;
}

詳細信息

Test #1:

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

input:

3
1000000 500000 0
500000 1000000 500000
0 500000 1000000

output:

Yes

result:

ok answer is YES

Test #2:

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

input:

3
1000000 500000 500000
500000 1000000 500000
500000 500000 1000000

output:

No

result:

ok answer is NO

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5764kb

input:

10
1000000 0 0 0 451708 0 0 0 0 0
0 1000000 123857 854215 0 789032 115663 874764 0 0
0 123857 1000000 269642 0 334825 0 249093 0 0
0 854215 269642 1000000 0 934817 0 979451 0 0
451708 0 0 0 1000000 0 0 0 0 0
0 789032 334825 934817 0 1000000 0 914268 0 0
0 115663 0 0 0 0 1000000 0 0 0
0 874764 249093...

output:

No

result:

wrong answer expected YES, found NO