답안 #704852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704852 2023-03-03T05:35:15 Z browntoad Zemljište (COCI22_zemljiste) C++14
70 / 70
544 ms 6728 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i=(n)-1; i>=0; i--)
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())

const ll maxn = 505;
const ll inf = (1ll<<60);

int r, c, a, b;
int arr[maxn][maxn];
int spf[maxn][maxn];
void inp(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>r>>c>>a>>b;
    if (a>b) swap(a, b);
    REP1(i, r){
        REP1(j, c){
            cin>>arr[i][j];
            spf[i][j] = spf[i-1][j] + arr[i][j];
        }
    }
}
int ans = inf;
vector<int> tmp;
int cval = 0;
void check(){
    ans = min(ans, abs(a-cval)+abs(b-cval));
}
void run(){
    int R=0;
    cval = 0;
    check();
    REP(i, c){
        while(R<c && cval < a){
            check();
            cval+=tmp[R];
            R++;
        }
        check();
        cval-=tmp[i];
        check();
    }
}
void solve(){
    REP1(i, r){
        FOR(j, i, r+1){
            tmp.clear();
            REP1(k, c){
                tmp.pb(spf[j][k] - spf[i-1][k]);
            }
            run();
        }
    }
}
signed main(){
    inp();
    solve();
    cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 7 ms 1224 KB Output is correct
12 Correct 6 ms 1112 KB Output is correct
13 Correct 6 ms 1148 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 7 ms 1212 KB Output is correct
16 Correct 6 ms 1140 KB Output is correct
17 Correct 6 ms 1108 KB Output is correct
18 Correct 6 ms 1108 KB Output is correct
19 Correct 6 ms 1108 KB Output is correct
20 Correct 5 ms 1108 KB Output is correct
21 Correct 6 ms 1176 KB Output is correct
22 Correct 6 ms 1056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 7 ms 1224 KB Output is correct
12 Correct 6 ms 1112 KB Output is correct
13 Correct 6 ms 1148 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 7 ms 1212 KB Output is correct
16 Correct 6 ms 1140 KB Output is correct
17 Correct 6 ms 1108 KB Output is correct
18 Correct 6 ms 1108 KB Output is correct
19 Correct 6 ms 1108 KB Output is correct
20 Correct 5 ms 1108 KB Output is correct
21 Correct 6 ms 1176 KB Output is correct
22 Correct 6 ms 1056 KB Output is correct
23 Correct 525 ms 6692 KB Output is correct
24 Correct 521 ms 6688 KB Output is correct
25 Correct 524 ms 6688 KB Output is correct
26 Correct 520 ms 6684 KB Output is correct
27 Correct 364 ms 5836 KB Output is correct
28 Correct 522 ms 6688 KB Output is correct
29 Correct 513 ms 6684 KB Output is correct
30 Correct 526 ms 6684 KB Output is correct
31 Correct 70 ms 4180 KB Output is correct
32 Correct 544 ms 6688 KB Output is correct
33 Correct 525 ms 6688 KB Output is correct
34 Correct 518 ms 6728 KB Output is correct
35 Correct 520 ms 6688 KB Output is correct
36 Correct 528 ms 6728 KB Output is correct
37 Correct 543 ms 6688 KB Output is correct
38 Correct 531 ms 6688 KB Output is correct
39 Correct 518 ms 6696 KB Output is correct
40 Correct 517 ms 6688 KB Output is correct
41 Correct 504 ms 5432 KB Output is correct
42 Correct 509 ms 5528 KB Output is correct
43 Correct 504 ms 5432 KB Output is correct
44 Correct 501 ms 5452 KB Output is correct