QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733566#9473. Puzzle GameEMTzWA 0ms3620kbC++203.0kb2024-11-10 19:52:152024-11-10 19:52:17

Judging History

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

  • [2024-11-10 19:52:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3620kb
  • [2024-11-10 19:52:15]
  • 提交

answer

#include<bits/stdc++.h>
//#define int long long
#define ull unsigned long long
using namespace std;
typedef pair<int,int>PII;
typedef pair<int,PII>PPI;
typedef array<int,3>ar;
typedef __int128 i28; 
const int N=200+7;
const int N1=1e9+9;
const int M=998244353;
const ull mask = std::chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 rng(time(0));
const int M1=19260817;
const int base=233;
const int base1=131;
const int INF = 0x3f3f3f3f;
int sum[N][N],u[N],d[N],l[N],r[N];
int a[N][N];
int dp[N];
int n,m;
void get1()
{
	for(int i=1;i<=m;i++)
	{
		sum[i][0]=0;
		for(int j=1;j<=n;j++)
		{
			sum[i][j]=sum[i][j-1]+a[j][i];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			for(int k=1;k<=m;k++) dp[k]=-1e9;
			dp[0]=0;
			int tmp=-1e9;
			for(int k=1;k<=m;k++)
			{
				int w=sum[k][j]-sum[k][j-i];
				dp[k]=max(dp[k-1]+w,w);
				tmp=max(tmp,dp[k]);
			}
			for(int k=j;k<=n;k++)u[k]=max(u[k],tmp);
		}
	}
	for(int i=1;i<=m;i++)
	{
		sum[i][m+1]=0;
		for(int j=n;j>=1;j--)
		{
			sum[i][j]=sum[i][j+1]+a[j][i];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=n-i+1;j>=1;j--)
		{
			for(int k=1;k<=m;k++) dp[k]=-1e9;
			dp[0]=0;
			int tmp=-1e9;
			for(int k=1;k<=m;k++)
			{
				int w=sum[k][j]-sum[k][j+i];
				dp[k]=max(dp[k-1]+w,w);
				tmp=max(tmp,dp[k]);
			}
			for(int k=j;k>=1;k--)d[k]=max(d[k],tmp);
		}
	}
}
void get2()
{
	for(int i=1;i<=n;i++)
	{
		sum[i][0]=0;
		for(int j=1;j<=m;j++)
		{
			sum[i][j]=sum[i][j-1]+a[i][j];
		}
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=i;j<=m;j++)
		{
			for(int k=1;k<=n;k++) dp[k]=-1e9;
			dp[0]=0;
			int tmp=-1e9;
			for(int k=1;k<=n;k++)
			{
				int w=sum[k][j]-sum[k][j-i];
				dp[k]=max(dp[k-1]+w,w);
				tmp=max(tmp,dp[k]);

			}
			for(int k=j;k<=m;k++)r[k]=max(r[k],tmp);
		}
	}
	for(int i=1;i<=n;i++)
	{
		sum[i][n+1]=0;
		for(int j=m;j>=1;j--)
		{
			sum[i][j]=sum[i][j+1]+a[i][j];
		}
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=m-i+1;j>=1;j--)
		{
			for(int k=1;k<=n;k++) dp[k]=-1e9;
			dp[0]=0;
			int tmp=-1e9;
			for(int k=1;k<=n;k++)
			{
				int w=sum[k][j]-sum[k][j+i];
				dp[k]=max(dp[k-1]+w,w);
				tmp=max(tmp,dp[k]);
			}
			for(int k=j;k>=1;k--)l[k]=max(l[k],tmp);
		}
	}
}
void solve()
{
	int p;
	while(cin>>n>>m>>p)
	{
		for(int i=1;i<=m;i++)l[i]=r[i]=-1e9;
		for(int i=1;i<=n;i++)d[i]=u[i]=-1e9;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				cin>>a[i][j];
			}
		}
		get1();
		get2();
//		cout<<u[1]<<"\n";
		int ans1=1e9;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				int ans=1e9;
				ans=max({u[i-1],d[i+1],l[j-1],r[j+1]});
				ans=max(ans,u[n]-a[i][j]+p);
				ans1=min(ans1,ans);
			}
		}
		cout<<ans1<<"\n";
	}
}	
//3 3 -10
//-100 4 4
//4 -10 4
//4 4 1
//3 3 -1
//-2 -2 -2
//-2 -2 -2
//-2 -2 -2
signed main()
{
	std::ios::sync_with_stdio(false);
	cout.tie(0);cin.tie(0);
	int _=1;
//	cin>>_;
	while(_--)
	{
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3620kb

input:

3 3 -10
-100 4 4
4 -10 4
4 4 1
3 3 -1
-2 -2 -2
-2 -2 -2
-2 -2 -2

output:

8
-1

result:

wrong answer 2nd lines differ - expected: '-2', found: '-1'