#include<iostream>
using namespace std;
int r,s,a,b;
long long **sum_pr,odp;
long long *dokad;
void inicjuj()
{
if(a>b)
swap(a,b);
odp=a+b;
sum_pr=new long long *[s+1];
for(int i=0;i<=s;++i)
sum_pr[i]=new long long [r+1];
dokad=new long long[r+1];
}
long long sum_prost(int xpd,int ypd,int xlg,int ylg)
{
return sum_pr[xpd][ypd]-sum_pr[xlg-1][ypd]-sum_pr[xpd][ylg-1]+sum_pr[xlg-1][ylg-1];
}
int main()
{
scanf("%d%d%d%d",&r,&s,&a,&b);
inicjuj();
for(int i=1;i<=r;++i)
{
for(int j=1;j<=i;++j)
dokad[j]=1;
for(int j=1;j<=s;++j)
{
scanf("%lld",&sum_pr[j][i]);
sum_pr[j][i]+=sum_pr[j-1][i]+sum_pr[j][i-1]-sum_pr[j-1][i-1];
for(int k=i;k>0;--k)
{
while(dokad[k]<j)
{
if(sum_prost(j,i,dokad[k],k)<=a)
break;
++dokad[k];
}
odp=min(odp,abs(a-sum_prost(j,i,dokad[k],k))+abs(b-sum_prost(j,i,dokad[k],k)));
if(dokad[k]>1)
odp=min(odp,abs(a-sum_prost(j,i,dokad[k]-1,k))+abs(b-sum_prost(j,i,dokad[k]-1,k)));
}
}
}
printf("%lld",odp);
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d%d%d%d",&r,&s,&a,&b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:30:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%lld",&sum_pr[j][i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
468 KB |
Output is correct |
12 |
Correct |
10 ms |
468 KB |
Output is correct |
13 |
Correct |
11 ms |
476 KB |
Output is correct |
14 |
Correct |
2 ms |
248 KB |
Output is correct |
15 |
Correct |
10 ms |
468 KB |
Output is correct |
16 |
Correct |
10 ms |
468 KB |
Output is correct |
17 |
Correct |
9 ms |
480 KB |
Output is correct |
18 |
Correct |
6 ms |
340 KB |
Output is correct |
19 |
Correct |
5 ms |
428 KB |
Output is correct |
20 |
Correct |
7 ms |
428 KB |
Output is correct |
21 |
Correct |
5 ms |
340 KB |
Output is correct |
22 |
Correct |
5 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
468 KB |
Output is correct |
12 |
Correct |
10 ms |
468 KB |
Output is correct |
13 |
Correct |
11 ms |
476 KB |
Output is correct |
14 |
Correct |
2 ms |
248 KB |
Output is correct |
15 |
Correct |
10 ms |
468 KB |
Output is correct |
16 |
Correct |
10 ms |
468 KB |
Output is correct |
17 |
Correct |
9 ms |
480 KB |
Output is correct |
18 |
Correct |
6 ms |
340 KB |
Output is correct |
19 |
Correct |
5 ms |
428 KB |
Output is correct |
20 |
Correct |
7 ms |
428 KB |
Output is correct |
21 |
Correct |
5 ms |
340 KB |
Output is correct |
22 |
Correct |
5 ms |
340 KB |
Output is correct |
23 |
Correct |
727 ms |
4668 KB |
Output is correct |
24 |
Correct |
772 ms |
4680 KB |
Output is correct |
25 |
Correct |
627 ms |
4680 KB |
Output is correct |
26 |
Correct |
662 ms |
4672 KB |
Output is correct |
27 |
Correct |
474 ms |
3252 KB |
Output is correct |
28 |
Correct |
592 ms |
4672 KB |
Output is correct |
29 |
Correct |
604 ms |
4692 KB |
Output is correct |
30 |
Correct |
681 ms |
4668 KB |
Output is correct |
31 |
Correct |
82 ms |
852 KB |
Output is correct |
32 |
Correct |
570 ms |
4796 KB |
Output is correct |
33 |
Correct |
619 ms |
4680 KB |
Output is correct |
34 |
Correct |
616 ms |
4672 KB |
Output is correct |
35 |
Correct |
672 ms |
4556 KB |
Output is correct |
36 |
Correct |
634 ms |
4672 KB |
Output is correct |
37 |
Correct |
592 ms |
4672 KB |
Output is correct |
38 |
Correct |
593 ms |
4676 KB |
Output is correct |
39 |
Correct |
624 ms |
4680 KB |
Output is correct |
40 |
Correct |
639 ms |
4672 KB |
Output is correct |
41 |
Correct |
339 ms |
3396 KB |
Output is correct |
42 |
Correct |
398 ms |
3408 KB |
Output is correct |
43 |
Correct |
397 ms |
3408 KB |
Output is correct |
44 |
Correct |
372 ms |
3404 KB |
Output is correct |