Submission #1104538

# Submission time Handle Problem Language Result Execution time Memory
1104538 2024-10-24T02:20:48 Z hickwhither Zemljište (COCI22_zemljiste) C++17
0 / 70
1 ms 336 KB
#include <iostream>
#include <algorithm>

using namespace std;

#define int int64_t

#define minimize(a,b) a=min(a,b)

int64_t ans = 1e18;
int n, m, a, b;
int x;
int64_t ps[503][503];
int64_t s[503];

int64_t toQ(int64_t x){
    // cout << x << '\n';
    return abs(x-a) + abs(x-b);
}

signed main()
{
    cin.tie(0) -> sync_with_stdio(0);
    // if(fopen("DAUTU.inp", "r")){
    //     freopen("DAUTU.inp", "r",stdin);
    //     freopen("DAUTU.out", "w",stdout);
    // }
    
    cin >> n >> m >> a >> b; if(a>b)swap(a,b);
    for(int i=1; i<=n; ++i)
    for(int j=1; j<=m; ++j){
        cin >> x;
        ps[i][j] = ps[i][j-1]+x;
    }
    // cout << ps[3][1] << '\n';

    for(int l=1; l<=n; ++l)
    for(int r=l; r<=n; ++r){
        for(int i=1; i<=n; ++i) s[i] = ps[i][r]-ps[i][l-1];

        int64_t sum=0;
        // cout << l << ' ' << r << "*\n";
        for(int i=1, j=1; i<=n; ++i){
            sum += s[i];
            // cout << sum << ' ';
            while(sum>b){
                minimize(ans, toQ(sum));
                sum-=s[j++];
            }
            minimize(ans, toQ(sum));
        }
        // cout << '\n';

    }
    cout << ans;
    

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -