답안 #827286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827286 2023-08-16T10:34:05 Z vjudge1 Zemljište (COCI22_zemljiste) C++17
30 / 70
2000 ms 6568 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();
 
}
 
 
/*
 
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4288 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 3 ms 4284 KB Output is correct
6 Correct 2 ms 4272 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 2 ms 4288 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4288 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 3 ms 4284 KB Output is correct
6 Correct 2 ms 4272 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 2 ms 4288 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
10 Correct 7 ms 4340 KB Output is correct
11 Correct 15 ms 4388 KB Output is correct
12 Correct 15 ms 4384 KB Output is correct
13 Correct 15 ms 4388 KB Output is correct
14 Correct 3 ms 4304 KB Output is correct
15 Correct 15 ms 4388 KB Output is correct
16 Correct 16 ms 4384 KB Output is correct
17 Correct 15 ms 4308 KB Output is correct
18 Correct 19 ms 4308 KB Output is correct
19 Correct 15 ms 4308 KB Output is correct
20 Correct 15 ms 4332 KB Output is correct
21 Correct 16 ms 4308 KB Output is correct
22 Correct 22 ms 4336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4288 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 3 ms 4284 KB Output is correct
6 Correct 2 ms 4272 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 2 ms 4288 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
10 Correct 7 ms 4340 KB Output is correct
11 Correct 15 ms 4388 KB Output is correct
12 Correct 15 ms 4384 KB Output is correct
13 Correct 15 ms 4388 KB Output is correct
14 Correct 3 ms 4304 KB Output is correct
15 Correct 15 ms 4388 KB Output is correct
16 Correct 16 ms 4384 KB Output is correct
17 Correct 15 ms 4308 KB Output is correct
18 Correct 19 ms 4308 KB Output is correct
19 Correct 15 ms 4308 KB Output is correct
20 Correct 15 ms 4332 KB Output is correct
21 Correct 16 ms 4308 KB Output is correct
22 Correct 22 ms 4336 KB Output is correct
23 Execution timed out 2066 ms 6568 KB Time limit exceeded
24 Halted 0 ms 0 KB -