답안 #660253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660253 2022-11-21T10:21:47 Z berr Zemljište (COCI22_zemljiste) C++17
0 / 70
1 ms 468 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<=n) 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -