Submission #801049

#TimeUsernameProblemLanguageResultExecution timeMemory
801049tlnk07Zemljište (COCI22_zemljiste)C++17
30 / 70
2063 ms4616 KiB
#include<bits/stdc++.h> using namespace std; long long n, m, x, a, b, pre[501][501], mini = INT_MAX; int main() { cin >> n >> m >> a >> b; pre[0][0] = 0; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { cin >> x; if(i == 1) pre[i][j] = pre[i][j - 1] + x; else if(j == 1) pre[i][j] = pre[i - 1][j] + x; else pre[i][j] = pre[i][j - 1] + pre[i - 1][j] - pre[i - 1][j - 1] + x; } } for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { for(int ii = 1; ii <= i; ++ii) { for(int jj = 1; jj <= j; ++jj) { long long temp = pre[i][j] - pre[i][jj - 1] - pre[ii - 1][j] + pre[ii - 1][jj - 1]; mini = min(mini, abs(temp - a) + abs(temp - b)); } } } } cout << mini; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...