QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#733559 | #9473. Puzzle Game | EMTz | WA | 12ms | 4112kb | C++20 | 3.0kb | 2024-11-10 19:50:16 | 2024-11-10 19:50:17 |
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][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++)u[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: 100
Accepted
time: 0ms
memory: 3656kb
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: -100
Wrong Answer
time: 12ms
memory: 4112kb
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:
29106 1319 3300 5947 1366 4930 8007 3058 2078 1899 3222 4653 1732 1619 1393 1030 3973 6784 2539 2104 3328 4084 893 790 585 2494 2393 4439 10006 3288 3822 20 929 852 3325 947 2472 2662 2770 1009 972 1123 1640 3360 1949 731 530 21 975 1204 1022 1147 2054 8002 1408 2853 3149 2028 2841 2501 1324 4863 0 ...
result:
wrong answer 1st lines differ - expected: '78124', found: '29106'