QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#800582 | #853. Flat Organization | zxcen | WA | 11ms | 5864kb | C++14 | 1.6kb | 2024-12-06 12:54:59 | 2024-12-06 12:55:00 |
Judging History
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<<'|';
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
if(d[i][j]){
cout<<i<<'_'<<j<<'_'<<d[i][j]<<'|';
}
}
}
}
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*(i-1)/2){
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;
}
}
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: 3664kb
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: 5864kb
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|1_2_690|1_7_10|1_16_21|1_17_151|1_18_566|1_20_1461|1_25_1248|1_28_445|1_29_1031|1_30_866|1_31_89|1_34_198|1_36_251|1_37_351|1_39_41|1_40_60|1_47_69|1_48_9|2_20_38|2_25_31|2_29_4|2_30_27|3_1_93|3_2_2340|3_7_257|3_10_56|3_13_18|3_16_146|3_17_862|3_18_2014|3_19_19|3_20_3908|3_25_3469|3_28_1738|3_29_...
result:
wrong answer Test 1: No YES/NO in the output