Submission #67748610
Source Code Expand
#include <bits/stdc++.h>
#define _F(x,y,z) for(int x=y;x<=z;x++)
#define F_(x,z,y) for(int x=z;x>=y;x--)
#define TF(x,y,z) for(int x=head[y],z;x;x=nex[x])
#define GF(x,y,z) for(int x:z[y])
using namespace std;
typedef long long ll;
typedef double dou;
typedef const int ci;
typedef pair<int,int> pii;
ci maxn=2e6+10;
int n,m,p[maxn];
vector<ll> dp[maxn],a[maxn];
queue<pii> qu;
int check(ll x)
{
_F(i,1,n)
{
_F(j,1,m)
{
dp[i][j]=-100000000000000000ll;
}
}
dp[1][1]=x;
_F(i,1,n)
{
_F(j,1,m)
{
dp[i][j]+=a[i][j]-p[i+j-1];
// printf("%d ",dp[i][j]);
if(dp[i][j]<0) continue;
dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
}
// puts("");
}
// puts("");
return dp[n][m]>=0;
}
int main()
{
scanf("%d%d",&n,&m);
_F(i,0,n+2)
{
dp[i].resize(m+10);
a[i].resize(m+10);
}
_F(i,1,n)
{
_F(j,1,m)
{
scanf("%lld",&a[i][j]);
}
}
ll l=0,r=0,ans=0;
_F(i,1,n+m-1)
scanf("%d",&p[i]),r+=1ll*p[i];
while(l<=r)
{
ll mid=(l+r)>>1;
if(check(mid))
r=mid-1,ans=mid;
else
l=mid+1;
}
printf("%lld",ans);
return 0;
}
Submission Info
| Submission Time |
|
| Task |
E - Hungry Takahashi |
| User |
adolphshi |
| Language |
C++ 20 (gcc 12.2) |
| Score |
450 |
| Code Size |
1166 Byte |
| Status |
AC |
| Exec Time |
268 ms |
| Memory |
51488 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:46:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:56:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
56 | scanf("%lld",&a[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:61:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
61 | scanf("%d",&p[i]),r+=1ll*p[i];
| ~~~~~^~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
450 / 450 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
16 ms |
3772 KiB |
| 00_sample_01.txt |
AC |
16 ms |
3892 KiB |
| 00_sample_02.txt |
AC |
16 ms |
3708 KiB |
| 01_random_00.txt |
AC |
104 ms |
16704 KiB |
| 01_random_01.txt |
AC |
96 ms |
16672 KiB |
| 01_random_02.txt |
AC |
101 ms |
16708 KiB |
| 01_random_03.txt |
AC |
81 ms |
16740 KiB |
| 01_random_04.txt |
AC |
66 ms |
7616 KiB |
| 01_random_05.txt |
AC |
75 ms |
7760 KiB |
| 01_random_06.txt |
AC |
75 ms |
7624 KiB |
| 01_random_07.txt |
AC |
59 ms |
7640 KiB |
| 01_random_08.txt |
AC |
71 ms |
6876 KiB |
| 01_random_09.txt |
AC |
69 ms |
6884 KiB |
| 01_random_10.txt |
AC |
68 ms |
7020 KiB |
| 01_random_11.txt |
AC |
65 ms |
7076 KiB |
| 01_random_12.txt |
AC |
72 ms |
7000 KiB |
| 01_random_13.txt |
AC |
64 ms |
7068 KiB |
| 01_random_14.txt |
AC |
68 ms |
7064 KiB |
| 01_random_15.txt |
AC |
60 ms |
7060 KiB |
| 01_random_16.txt |
AC |
64 ms |
9340 KiB |
| 01_random_17.txt |
AC |
65 ms |
9200 KiB |
| 01_random_18.txt |
AC |
64 ms |
9048 KiB |
| 01_random_19.txt |
AC |
54 ms |
9200 KiB |
| 01_random_20.txt |
AC |
131 ms |
30652 KiB |
| 01_random_21.txt |
AC |
128 ms |
30540 KiB |
| 01_random_22.txt |
AC |
128 ms |
30784 KiB |
| 01_random_23.txt |
AC |
126 ms |
30720 KiB |
| 01_random_24.txt |
AC |
265 ms |
51340 KiB |
| 01_random_25.txt |
AC |
261 ms |
51344 KiB |
| 01_random_26.txt |
AC |
268 ms |
51488 KiB |
| 01_random_27.txt |
AC |
255 ms |
51292 KiB |
| 02_random2_00.txt |
AC |
62 ms |
7136 KiB |
| 02_random2_01.txt |
AC |
64 ms |
7068 KiB |
| 02_random2_02.txt |
AC |
67 ms |
6936 KiB |
| 02_random2_03.txt |
AC |
42 ms |
7084 KiB |
| 02_random2_04.txt |
AC |
49 ms |
6884 KiB |
| 02_random2_05.txt |
AC |
57 ms |
6960 KiB |
| 03_handmade_00.txt |
AC |
16 ms |
3636 KiB |
| 03_handmade_01.txt |
AC |
16 ms |
3636 KiB |
| 03_handmade_02.txt |
AC |
16 ms |
3692 KiB |
| 03_handmade_03.txt |
AC |
61 ms |
7076 KiB |
| 03_handmade_04.txt |
AC |
39 ms |
7140 KiB |
| 03_handmade_05.txt |
AC |
65 ms |
7144 KiB |
| 03_handmade_06.txt |
AC |
87 ms |
16824 KiB |
| 03_handmade_07.txt |
AC |
60 ms |
16660 KiB |
| 03_handmade_08.txt |
AC |
92 ms |
16656 KiB |