Submission #1272925

#TimeUsernameProblemLanguageResultExecution timeMemory
1272925ken7236Zemljište (COCI22_zemljiste)C++20
0 / 70
1 ms568 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int r, s, pp, qq; cin>>r>>s>>pp>>qq; int p = min(pp,qq); int q = max(pp,qq); vector<vector<int> > arr(r+1, vector<int>(s+1)); for(int a=1; a<=r; a++) { for(int b=1; b<=s; b++) { cin>>arr[a][b]; } } int ans = INT_MAX; vector<vector<int> > pref(r+1, vector<int>(s+1, 0)); for(int a=1; a<=s; a++) { for(int b=1; b<=r; b++) { pref[b][a] = pref[b-1][a] + arr[b][a]; } } for(int a=1; a<=r; a++) { for(int b=1; b<=s; b++) { //cout<<pref[a][b]<<" "; } //cout<<endl; } for(int a=1; a<=r; a++) { for(int b=a; b<=r; b++) { //cout<<a<<" "<<b<<endl; vector<int> temp(s+1, 0); for(int c=1; c<=s; c++) { temp[c] = pref[b][c] - pref[a-1][c]; //cout<<temp[c]<<" "; } for(int c=1; c<=s; c++) { temp[c]+=temp[c-1]; } //cout<<endl; int l = 1; for(int rr = 1; rr<=s; rr++) { while(l <= rr && temp[rr] - temp[l-1] > q) l++; if(l <= rr) { int sv = temp[rr] - temp[l-1]; int res = abs(sv - p) + abs(sv - q); ans = min(ans, res); } } } } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...