Submission #660254

# Submission time Handle Problem Language Result Execution time Memory
660254 2022-11-21T10:22:43 Z berr Zemljište (COCI22_zemljiste) C++17
70 / 70
340 ms 8788 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int val[505][505], pr[505][505], pc[505][505];


int calc(int x, int y, int depth, int length)
{

    return pc[x+length-1][y+depth-1]-pc[x-1][y+depth-1]-pc[x+length-1][y-1]+pc[x-1][y-1];

}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    

    int n, m, a, b; cin>>n>>m>>a>>b;

    int ans=2e18;


    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin>>val[i][j];
        }
    }

    for(int i=1; i<=n+2; i++)
    {
        for(int j=1; j<=m+2; j++)
        {
            pr[i][j]=pr[i][j-1]+val[i][j];
        }
    }

    for(int j=1; j<=m+2; j++)
    {
        for(int i=1; i<=n+2; i++)
        {
            pc[i][j]+=pc[i-1][j]+pr[i][j];
        }
    }
    for(int i=1; i<=n; i++)
    {
        for(int l=i; l<=n; l++)
        {
            int h=0;

            for(int j=1; j<=m; j++)
            {
                while((pc[l][j]-pc[i-1][j])-(pc[l][h]-pc[i-1][h])>b&&h<=m) h++;
                int x=(pc[l][j]-pc[i-1][j])-(pc[l][h]-pc[i-1][h]);
                ans=min(ans, (abs(b-x)+abs(a-x)));

                if(h)
                {
                    int x=(pc[l][j]-pc[i-1][j])-(pc[l][h-1]-pc[i-1][h-1]);
                    ans=min(ans, abs(b-x)+abs(a-x));  
                }
            }   

        }    
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 1108 KB Output is correct
11 Correct 5 ms 1492 KB Output is correct
12 Correct 4 ms 1492 KB Output is correct
13 Correct 5 ms 1492 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 5 ms 1540 KB Output is correct
16 Correct 4 ms 1420 KB Output is correct
17 Correct 6 ms 1536 KB Output is correct
18 Correct 3 ms 1492 KB Output is correct
19 Correct 3 ms 1492 KB Output is correct
20 Correct 3 ms 1492 KB Output is correct
21 Correct 3 ms 1492 KB Output is correct
22 Correct 6 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 1108 KB Output is correct
11 Correct 5 ms 1492 KB Output is correct
12 Correct 4 ms 1492 KB Output is correct
13 Correct 5 ms 1492 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 5 ms 1540 KB Output is correct
16 Correct 4 ms 1420 KB Output is correct
17 Correct 6 ms 1536 KB Output is correct
18 Correct 3 ms 1492 KB Output is correct
19 Correct 3 ms 1492 KB Output is correct
20 Correct 3 ms 1492 KB Output is correct
21 Correct 3 ms 1492 KB Output is correct
22 Correct 6 ms 1492 KB Output is correct
23 Correct 330 ms 6260 KB Output is correct
24 Correct 330 ms 8684 KB Output is correct
25 Correct 336 ms 8780 KB Output is correct
26 Correct 327 ms 8788 KB Output is correct
27 Correct 218 ms 7872 KB Output is correct
28 Correct 323 ms 8616 KB Output is correct
29 Correct 327 ms 8680 KB Output is correct
30 Correct 327 ms 8596 KB Output is correct
31 Correct 46 ms 5972 KB Output is correct
32 Correct 327 ms 8680 KB Output is correct
33 Correct 324 ms 8652 KB Output is correct
34 Correct 340 ms 8684 KB Output is correct
35 Correct 327 ms 8780 KB Output is correct
36 Correct 324 ms 8756 KB Output is correct
37 Correct 328 ms 8688 KB Output is correct
38 Correct 323 ms 8592 KB Output is correct
39 Correct 331 ms 8680 KB Output is correct
40 Correct 328 ms 8652 KB Output is correct
41 Correct 188 ms 7416 KB Output is correct
42 Correct 183 ms 7300 KB Output is correct
43 Correct 183 ms 7420 KB Output is correct
44 Correct 201 ms 7424 KB Output is correct