QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#67727#4786. BalanceA_zjzjWA 2ms3420kbC++141.3kb2022-12-11 15:26:022022-12-11 15:26:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-11 15:26:03]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3420kb
  • [2022-12-11 15:26:02]
  • 提交

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;
}

详细

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