답안 #718259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718259 2023-04-03T18:55:43 Z Augustyn Zemljište (COCI22_zemljiste) C++17
30 / 70
2000 ms 4152 KB
#include<iostream>
using namespace std;
int r,s,a,b;
long long **sum_pr,odp;
long long sumzkwr(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];
}
void bs(int j,int i,int k)
{
    int pocz=1,kon=i+1,sr=(pocz+kon)>>1;
    while(pocz!=sr)
    {
        if(sumzkwr(j,i,k,sr)>=b)
            pocz=sr;
        else
            kon=sr;
        sr=(pocz+kon)>>1;
    }
    odp=min(odp,abs(a-sumzkwr(j,i,k,sr))+abs(b-sumzkwr(j,i,k,sr)));
    if(sumzkwr(j,i,k,sr)>b&&sr<i)
    {
        ++sr;
        odp=min(odp,abs(a-sumzkwr(j,i,k,sr))+abs(b-sumzkwr(j,i,k,sr)));
    }
}
int main()
{
    scanf("%d%d%d%d",&r,&s,&a,&b);
    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];
    for(int i=1;i<=r;++i)
    {
        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=j;k>=1;--k)
                bs(j,i,k);
        }
    }
    printf("%lld",odp);
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d%d%d%d",&r,&s,&a,&b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:40:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |             scanf("%lld",&sum_pr[j][i]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 0 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 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 18 ms 468 KB Output is correct
12 Correct 17 ms 468 KB Output is correct
13 Correct 21 ms 468 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 19 ms 468 KB Output is correct
16 Correct 17 ms 516 KB Output is correct
17 Correct 18 ms 468 KB Output is correct
18 Correct 14 ms 316 KB Output is correct
19 Correct 14 ms 424 KB Output is correct
20 Correct 19 ms 340 KB Output is correct
21 Correct 15 ms 420 KB Output is correct
22 Correct 14 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 18 ms 468 KB Output is correct
12 Correct 17 ms 468 KB Output is correct
13 Correct 21 ms 468 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 19 ms 468 KB Output is correct
16 Correct 17 ms 516 KB Output is correct
17 Correct 18 ms 468 KB Output is correct
18 Correct 14 ms 316 KB Output is correct
19 Correct 14 ms 424 KB Output is correct
20 Correct 19 ms 340 KB Output is correct
21 Correct 15 ms 420 KB Output is correct
22 Correct 14 ms 420 KB Output is correct
23 Execution timed out 2071 ms 4152 KB Time limit exceeded
24 Halted 0 ms 0 KB -