Submission #852259

#TimeUsernameProblemLanguageResultExecution timeMemory
852259Trisanu_DasZemljište (COCI22_zemljiste)C++17
70 / 70
241 ms4948 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int arr[505][505]; signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); int r, s, a, b; cin >> r >> s >> a >> b; if(a > b) swap(a, b); for(int i = 1; i <= r; i++) for(int j = 1;j <= s; j++) cin >> arr[i][j]; for(int j = 1; j <= s; j++) for(int i = 1; i <= r;i++) arr[i][j] += arr[i - 1][j]; int ans = INT_MAX; for(int i = 1; i <= r; i++){ for(int j = i; j <= r; j++){ int pos = 0, sum = 0; for(int k = 1; k <= s; k++){ sum += arr[j][k] - arr[i - 1][k]; while(sum > b && pos <= k){ ans = min(abs(a - sum) + abs(b - sum), ans); sum -= arr[j][pos] - arr[i - 1][pos]; pos++; } if(a <= sum && b >= sum){ cout << b - a << '\n'; return 0; } ans = min(abs(a - sum) + abs(b - sum), ans); } } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...