Submission #1104492

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

using namespace std;

#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){
    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<=n; ++j){
        cin >> x;
        ps[i][j] = ps[i][j-1]+x;
    }
    for(int l=1; l<=n; ++l)
    for(int r=l; r<=n; ++r){
        for(int i=1; i<=n; ++i) s[i] = s[i-1]+ps[i][r] - ps[i][l-1];

        // a <= s[i]-s[j] <= b
        // a-s[i] <= s[j] <= b-s[i]
        for(int i=1; i<=n; ++i){
            int c = lower_bound(s+1,s+1+n,a-s[i]) - s,
                d = upper_bound(s+1,s+1+n,b-s[i]) - s;
            minimize(ans, toQ(s[i]-s[c]));
            minimize(ans, toQ(s[i]-s[d]));
            
            // if(c>0) minimize(ans, toQ(s[i]-s[c-1]));
            // if(c<i) minimize(ans, toQ(s[i]-s[c+1]));
            // if(d>0) minimize(ans, toQ(s[i]-s[d-1]));
            // if(d<i) minimize(ans, toQ(s[i]-s[d+1]));
        }
    }
    cout << ans;
    

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen("DAUTU.inp", "r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen("DAUTU.out", "w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -