QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#733555 | #9473. Puzzle Game | EMTz | WA | 11ms | 3972kb | C++20 | 3.0kb | 2024-11-10 19:49:24 | 2024-11-10 19:49:25 |
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],dp[m]);
}
}
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],dp[m]);
}
}
}
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],dp[n]);
}
}
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],dp[n]);
}
}
}
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: 3788kb
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: 11ms
memory: 3972kb
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:
10151 414 3300 5126 1109 3099 8007 3058 2078 1813 3222 4653 1732 1352 965 1030 3973 6449 1763 2104 3083 4084 893 790 585 2042 2393 2359 10006 367 3822 20 929 0 3325 788 2472 2662 2711 1009 416 846 1640 3360 1949 0 439 21 975 1204 1022 729 2054 8002 1408 2263 3149 2028 2841 2450 109 4863 0 2208 4363 ...
result:
wrong answer 1st lines differ - expected: '78124', found: '10151'