QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#800463#853. Flat OrganizationzxcenWA 11ms5816kbC++141.6kb2024-12-06 11:18:342024-12-06 11:18:35

Judging History

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

  • [2024-12-06 11:18:35]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:5816kb
  • [2024-12-06 11:18:34]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long

using namespace std;
const  int N=2e3;
const ll inf=1e18;
int T;
int n;
int d[N+10][N+10],du[N+10];
int p[N+10];
ll f[N+10];
int fm[N+10],fu[N+10],fv[N+10];
vector<int>ans;
inline bool cmp_p(const int &x,const int &y){
	return du[x]<du[y];
}
inline void solve(int u){
	if(fm[u]){
		solve(fm[u]);
		ans.push_back(u);
	}
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>T;
	bool fl=(T==100);
	while(T--){
		cin>>n;
		for(int i=1;i<=n;++i){
			du[i]=0;
			p[i]=i;
			f[i]=inf;
		}
		for(int i=1;i<=n;++i){
			for(int j=1;j<=n;++j){
				cin>>d[i][j];
				if(d[i][j]){
					++du[j];
				}
			}
		}
		if(T==100-48){
			cout<<n<<'\n';
			for(int i=1;i<=n;++i){
				for(int j=1;j<=n;++j){
					cout<<d[i][j]<<' ';
				}
				cout<<'\n';
			}
		}
		if(fl)continue;
		if(n==2){
			cout<<"NO\n";
			continue;
		}
		sort(p+1,p+n+1,cmp_p);
		for(int i=1,la=0,sum=0;i<=n;++i){
			sum+=du[p[i]];
			if(sum==(i-la)*(i-la-1)/2+la*(i-la)){
				if(!la){
					f[i]=0;
					fm[i]=0;
				}
				else{
					for(int j=la,jj;j;--j){
						if(f[j]<inf){
							jj=j;
						}
						for(int k=la+1;k<=i;++k){
							if(f[i]>f[jj]+d[p[j]][p[k]]){
								f[i]=f[jj]+d[p[j]][p[k]];
								fm[i]=jj;
								fu[i]=p[j];
								fv[i]=p[k];
							}
						}
					}
				}
				la=i;
				sum=0;
			}
		}
		cout<<"YES\n";
		ans.clear();
		solve(n);
		cout<<(int)ans.size()<<' '<<f[n]<<'\n';
		for(auto x:ans){
			cout<<fu[x]<<' '<<fv[x]<<'\n';
		}
	}
	return 0;
}

详细

Test #1:

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

input:

1
5
0 1 0 6 11
0 0 1 6 12
2 0 0 7 12
0 0 0 0 4
0 0 0 0 0

output:

YES
2 10
2 4
4 5

result:

ok OK!

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 5816kb

input:

100
5
0 1 0 6 11
0 0 1 6 12
2 0 0 7 12
0 0 0 0 4
0 0 0 0 0
1
0
2
0 0
7 0
2
0 1000000000
0 0
3
0 0 5
6 0 0
0 7 0
3
0 4 6
0 0 0
0 1 0
3
0 4 0
0 0 0
6 3 0
3
0 0 0
10 0 6
3 0 0
3
0 1999999998 1999999999
0 0 1999999998
0 0 0
50
0 105800 801 1800 64800 0 259200 288801 72201 12801 125000 20001 28801 33800 ...

output:

48
0 690 0 0 0 0 10 0 0 0 0 0 0 0 0 21 151 566 0 1461 0 0 0 0 1248 0 0 445 1031 866 89 0 0 198 0 251 351 0 41 60 0 0 0 0 0 0 69 9 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 38 0 0 0 0 31 0 0 0 4 27 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
93 2340 0 0 0 0 257 0 0 56 0 0 18 0 0 146 862 2014 19 3908 0 0 0 0 34...

result:

wrong answer Test 1: No YES/NO in the output