QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#800583 | #853. Flat Organization | zxcen | WA | 12ms | 5872kb | C++14 | 1.6kb | 2024-12-06 12:55:36 | 2024-12-06 12:55:38 |
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=(0&&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(fl&&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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5824kb
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: 12ms
memory: 5872kb
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:
YES 2 10 2 4 4 5 YES 0 0 NO NO YES 0 0 YES 1 4 1 2 YES 1 3 3 2 YES 2 9 2 3 3 1 YES 1 1999999999 1 3 YES 3 602 4 33 11 47 34 39 YES 3 649 27 12 32 45 17 29 YES 5 1209 1 18 14 35 35 4 4 25 25 12 YES 3 844 3 8 1 41 14 21 YES 3 866 17 35 35 44 46 26 YES 4 1066 10 28 36 24 24 2 37 8 YES 3 1122 4 17 43 19...
result:
wrong answer Test 48: The solution is not optimal