제출 #1272047

#제출 시각아이디문제언어결과실행 시간메모리
1272047picradZemljište (COCI22_zemljiste)C++20
0 / 70
1 ms576 KiB
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; typedef long long ll; typedef double dbl; typedef pair<ll,ll> pii; const int maxn = 5e2+5,MOD = 1e8,INF = 2e9; ll ARR[maxn][maxn],pref[maxn][maxn],N,M,A,B,ans = INF; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> N >> M >> A >> B; if(A > B) swap(A,B); for(int i =1; i <= N; i++){ for(int j = 1; j <= M; j++) { cin >> ARR[i][j]; pref[i][j] = ARR[i][j] + pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1]; } } for(int i = 1; i <= N; i++){ for(int j =i; j <= N; j++){ int l =1, r = 1, sum = pref[j][1] - pref[i-1][1]; while(l <= M && r <= M){ ans = min(ans, abs(A-sum) + abs(B-sum)); if(sum < B || abs(A-sum) + abs(B-sum) == ans){ r++; sum += pref[j][r] - pref[j][r-1] - pref[i-1][r] + pref[i-1][r-1]; }else{ sum -=( pref[j][l] - pref[j][l-1] - pref[i-1][l] + pref[i-1][l-1] ); l++; if(l > r){ r++; sum += pref[j][r] - pref[j][r-1] - pref[i-1][r] + pref[i-1][r-1]; } } } } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...