답안 #704899

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704899 2023-03-03T06:34:46 Z guagua0407 Zemljište (COCI22_zemljiste) C++17
70 / 70
484 ms 3276 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define all(x) x.begin(),x.end()

const ll mxn=505;
ll pre[mxn][mxn];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n,m;
    ll a,b;
    cin>>n>>m>>a>>b;
    if(a>b) swap(a,b);
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            cin>>pre[i][j];
            pre[i][j]+=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1];
        }
    }
    ll ans=1e18;
    for(ll i=1;i<=n;i++){
        for(ll j=i;j<=n;j++){
            vector<ll> vec;
            for(ll k=0;k<=m;k++){
                vec.push_back(pre[j][k]-pre[i-1][k]);
            }
            int r=1;
            for(int l=0;l<m;l++){
                while(r<=m and vec[r]-vec[l]<a){
                    ans=min(ans,abs(vec[r]-vec[l]-a)+abs(vec[r]-vec[l]-b));
                    r++;
                }
                if(l<r and r<=m){
                    ans=min(ans,abs(vec[r]-vec[l]-a)+abs(vec[r]-vec[l]-b));
                }
            }
        }
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 6 ms 724 KB Output is correct
12 Correct 6 ms 724 KB Output is correct
13 Correct 7 ms 724 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 6 ms 724 KB Output is correct
16 Correct 6 ms 724 KB Output is correct
17 Correct 6 ms 724 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 6 ms 724 KB Output is correct
20 Correct 6 ms 724 KB Output is correct
21 Correct 5 ms 724 KB Output is correct
22 Correct 5 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 6 ms 724 KB Output is correct
12 Correct 6 ms 724 KB Output is correct
13 Correct 7 ms 724 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 6 ms 724 KB Output is correct
16 Correct 6 ms 724 KB Output is correct
17 Correct 6 ms 724 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 6 ms 724 KB Output is correct
20 Correct 6 ms 724 KB Output is correct
21 Correct 5 ms 724 KB Output is correct
22 Correct 5 ms 724 KB Output is correct
23 Correct 458 ms 3156 KB Output is correct
24 Correct 459 ms 3272 KB Output is correct
25 Correct 464 ms 3148 KB Output is correct
26 Correct 460 ms 3152 KB Output is correct
27 Correct 330 ms 3020 KB Output is correct
28 Correct 459 ms 3148 KB Output is correct
29 Correct 468 ms 3156 KB Output is correct
30 Correct 468 ms 3192 KB Output is correct
31 Correct 81 ms 2392 KB Output is correct
32 Correct 464 ms 3148 KB Output is correct
33 Correct 484 ms 3196 KB Output is correct
34 Correct 469 ms 3200 KB Output is correct
35 Correct 460 ms 3080 KB Output is correct
36 Correct 465 ms 3200 KB Output is correct
37 Correct 469 ms 3216 KB Output is correct
38 Correct 459 ms 3088 KB Output is correct
39 Correct 466 ms 3276 KB Output is correct
40 Correct 463 ms 3276 KB Output is correct
41 Correct 397 ms 3200 KB Output is correct
42 Correct 386 ms 3276 KB Output is correct
43 Correct 388 ms 3276 KB Output is correct
44 Correct 385 ms 3196 KB Output is correct