답안 #704856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704856 2023-03-03T05:48:45 Z guagua0407 Zemljište (COCI22_zemljiste) C++17
0 / 70
1 ms 340 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=1;k<=m;k++){
                vec.push_back(pre[j][k]-pre[i-1][0]);
            }
            for(ll k=0;k<m;k++){
                ll sum=pre[j][k]-pre[i-1][0];
                ll aa=sum+a;
                ll bb=sum+b;
                auto it1=lower_bound(all(vec),aa);
                auto it2=upper_bound(all(vec),bb);
                it2--;
                if(it1<=it2){
                    cout<<b-a;
                    return 0;
                }
                if(it1-vec.begin()>=0 and it1-vec.begin()<n){
                    ans=min(ans,abs((*it1)-a)+abs((*it1)-b));
                }  
                if(it2-vec.begin()>=0 and it2-vec.begin()<n){
                    ans=min(ans,abs((*it2)-a)+abs((*it2)-b));
                }  
            }
        }
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -