QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67727 | #4786. Balance | A_zjzj | WA | 2ms | 3420kb | C++14 | 1.3kb | 2022-12-11 15:26:02 | 2022-12-11 15:26:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;const int N=55,INF=1e9;
int n,a[N][N],b[N][N],A[N],B[N],tag[N][N];
int calc(int x){
b[1][1]=x;for(int i=2;i<=n;i++)b[i][1]=a[i][1],b[1][i]=a[1][i];
for(int i=1;i<=n;i++)A[i]=B[i]=0;memset(tag,0,sizeof tag);
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)tag[i][j]=b[i][1]+b[1][j]<x+a[i][j],A[i]+=tag[i][j],B[j]+=tag[i][j];
for(;;){
int p=1,q=1;for(int i=2;i<=n;i++)if(A[i]>A[p])p=i;for(int i=2;i<=n;i++)if(B[i]>B[q])q=i;
if(!A[p]&&!B[q])break;
if(A[p]>B[q]){
int mn=INF;for(int i=1;i<=n;i++)if(tag[p][i])mn=min(mn,x+a[p][i]-b[p][1]-b[1][i]);
b[p][1]+=mn;for(int i=1;i<=n;i++)if(tag[p][i]&&b[p][1]+b[1][i]>=x+a[p][i])tag[p][i]=0,A[p]--,B[i]--;
}else{
int mn=INF;for(int i=1;i<=n;i++)if(tag[i][q])mn=min(mn,x+a[i][q]-b[i][1]-b[1][q]);
b[1][q]+=mn;for(int i=1;i<=n;i++)if(tag[i][q]&&b[i][1]+b[1][q]>=x+a[i][q])tag[i][q]=0,A[i]--,B[q]--;
}
}int sum=0;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)sum+=b[i][1]+b[1][j]-x;return sum;
}
int main(){
scanf("%d",&n);for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)scanf("%d",&a[i][j]);
int l=a[1][1],r=3.5e4,ml,mr;for(;l+10<r;)ml=(l+l+r)/3,mr=(l+r+r)/3,calc(ml)<calc(mr)?r=mr:l=ml;
int ans=INF;for(int i=l;i<=r;i++)ans=min(ans,calc(i));cout<<ans;return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3420kb
input:
4 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1
output:
16
result:
wrong output format Unexpected end of file - int32 expected