Submission #799301

# Submission time Handle Problem Language Result Execution time Memory
799301 2023-07-31T12:17:34 Z MercubytheFirst Zemljište (COCI22_zemljiste) C++14
30 / 70
2000 ms 4916 KB
/*


*/
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#pragma GCC optimize("O3","unroll-loops")
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<set>
#include<climits>
#include<numeric>
#include<queue>
#include<unordered_map>
#include<string>
#include<climits>
#include<unordered_set>
#include<bitset>
#include<cstring>
#include<cmath>
#include<stack>
#if 1
#define pb push_back
#define st first
#define nd second
#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define N ((int)(2e5+5))
#define int long long int
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vi> vivi;
typedef pair<char,int> pci;
const int inf = 1e18 + 5;
#endif


vivi pref(501, vi(501)), g(501, vi(501));
int r, s, a, b;

int get(int x, int y, int xx, int yy){
    int sum = pref[xx][yy];
    sum -= pref[xx][y];
    sum -= pref[x][yy];
    sum += pref[x][y];
    return sum;
}

void build(){
    for(int i = 1; i <= r; ++i){
        for(int j = 1; j <= s; ++j){
            pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1] + g[i][j];
        }
    }
}

void solve(){
    cin >> r >> s >> a >> b;
    for(int i = 1; i <= r; ++i){
        for(int j = 1; j <= s; ++j){
            cin >> g[i][j];
        }
    }
    build();
    int ans = inf;
    for(int li = 1; li <= r; ++li){
        for(int ri = li; ri <= r; ++ri){
            for(int lj = 1; lj <= s; ++lj){
                for(int rj = lj; rj <= s; ++rj){
                    int cur = get(li - 1, lj - 1, ri, rj);
                    ans = min(ans, abs(cur - a) + abs(cur - b));
                    //cout << li << ' ' << lj << ' ' << ri << ' ' << rj << ' ' << cur << endl;
                }
            }
        }
    }
    cout << ans << endl;

}

signed main(){
    //fileio("test"); // Don't forget to comment out
    fio; 
    //int t;cin >> t;while(t--)
        solve();

}


/*

*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 4 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 6 ms 4204 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 2 ms 4288 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 3 ms 4180 KB Output is correct
9 Correct 2 ms 4244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 4 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 6 ms 4204 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 2 ms 4288 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 3 ms 4180 KB Output is correct
9 Correct 2 ms 4244 KB Output is correct
10 Correct 7 ms 4340 KB Output is correct
11 Correct 15 ms 4304 KB Output is correct
12 Correct 15 ms 4308 KB Output is correct
13 Correct 16 ms 4308 KB Output is correct
14 Correct 3 ms 4180 KB Output is correct
15 Correct 19 ms 4416 KB Output is correct
16 Correct 15 ms 4308 KB Output is correct
17 Correct 15 ms 4308 KB Output is correct
18 Correct 15 ms 4208 KB Output is correct
19 Correct 15 ms 4308 KB Output is correct
20 Correct 15 ms 4332 KB Output is correct
21 Correct 15 ms 4296 KB Output is correct
22 Correct 15 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 4 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 6 ms 4204 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 2 ms 4288 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 3 ms 4180 KB Output is correct
9 Correct 2 ms 4244 KB Output is correct
10 Correct 7 ms 4340 KB Output is correct
11 Correct 15 ms 4304 KB Output is correct
12 Correct 15 ms 4308 KB Output is correct
13 Correct 16 ms 4308 KB Output is correct
14 Correct 3 ms 4180 KB Output is correct
15 Correct 19 ms 4416 KB Output is correct
16 Correct 15 ms 4308 KB Output is correct
17 Correct 15 ms 4308 KB Output is correct
18 Correct 15 ms 4208 KB Output is correct
19 Correct 15 ms 4308 KB Output is correct
20 Correct 15 ms 4332 KB Output is correct
21 Correct 15 ms 4296 KB Output is correct
22 Correct 15 ms 4308 KB Output is correct
23 Execution timed out 2037 ms 4916 KB Time limit exceeded
24 Halted 0 ms 0 KB -