QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#733604 | #9473. Puzzle Game | EMTz | AC ✓ | 11ms | 3948kb | C++20 | 3.0kb | 2024-11-10 20:04:19 | 2024-11-10 20:04:23 |
Judging History
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][n+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++)l[k]=max(l[k],tmp);
}
}
for(int i=1;i<=n;i++)
{
sum[i][m+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--)
{
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--)r[k]=max(r[k],tmp);
}
}
}
void solve()
{
int p;
while(cin>>n>>m>>p)
{
for(int i=0;i<=m+1;i++)l[i]=r[i]=-1e9;
for(int i=0;i<=n+1;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=u[n];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j]<=p) continue;
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: 100
Accepted
time: 0ms
memory: 3876kb
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 -2
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 11ms
memory: 3948kb
input:
150 150 -1000 43 -832 286 960 955 -713 387 -6 -542 -664 618 473 -628 225 -682 -223 219 -28 269 -799 -658 -263 791 736 32 33 -652 613 -676 153 223 -615 -495 -742 -529 -365 -531 674 764 546 926 815 -691 240 -98 -183 -306 -914 263 -714 -632 364 948 462 75 -724 143 -736 236 169 342 974 -412 -535 -468 27...
output:
78124 1319 3276 5931 1109 6509 238 3559 2751 2030 3302 4653 2141 1932 6174 844 6719 6732 1886 2656 3430 4020 893 790 585 2635 3772 6120 9976 3000 3557 20 1460 2173 50 657 1932 2406 2689 2248 1229 288 1640 3763 2613 731 3075 21 2297 1022 49 1147 1886 8002 2554 2263 1506 1710 896 2514 1120 4863 -693 2...
result:
ok 114 lines