QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#32062#1461. Greedy AlgorithmWu_RenWA 2ms3808kbC++14986b2022-05-16 21:32:412022-05-16 21:32:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-16 21:32:43]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3808kb
  • [2022-05-16 21:32:41]
  • 提交

answer

#include <bits/stdc++.h>
const int w=500;
using namespace std;
int n,m,a[60][60],b[60][60],*c[60],C[60][1010],*f[2],F[2][50010],p,o;
void qmx(int &x,int y){
	if(y>x) x=y;
}
int work(){
	int res=0,mn=2e9;
	for(int i=0;i<n;i++){
		c[i]=C[i]+w+5;
		for(int j=-w;j<=w;j++) C[i][j]=0;
	}
	for(int i=0;i<n;i++){
		int mx=0;
		for(int j=0;j<m;j++) mx=max(mx,++C[i][a[i][j]-a[(i+1)%n][j]]);
		mn=min(mn,mx),res+=mx;
	}
	res-=mn;
	for(int i=0;i<2;i++) f[i]=F[i]+n*w+5;
	for(int i=-n*w;i<=n*w;i++) f[0][i]=f[1][i]=0;
	p=0,o=1;
	for(int i=0;i<n;i++){
		for(int j=-i*w;j<=i*w;j++){
			for(int k=0;k<m;k++) qmx(f[o][j+a[i][k]-a[(i+1)%n][k]],f[p][j]+C[i][a[i][k]-a[(i+1)%n][k]]);
		}
		p^=1,o^=1;
	}
	return max(res,f[p][0]);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&a[i][j]);
	int ans=work();
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) b[j][i]=a[i][j];
	swap(a,b),swap(n,m);
	ans+=work();
	printf("%d\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3808kb

input:

2 3
1 2 3
4 5 99

output:

44030

result:

wrong answer 1st numbers differ - expected: '8', found: '44030'