# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
799290 | 2023-07-31T11:59:47 Z | MercubytheFirst | Zemljište (COCI22_zemljiste) | C++17 | 2000 ms | 6348 KB |
/* */ #include<iostream> #include<vector> #include<iomanip> #include<algorithm> #include<map> #include<set> #include<climits> #include<numeric> #include<queue> #include<unordered_map> #include<string> #include<climits> #include<unordered_set> #include<bitset> #include<cstring> #include<cmath> #include<stack> #if 1 #define pb push_back #define st first #define nd second #define endl '\n' #define fio ios_base::sync_with_stdio(false);cin.tie(NULL); #define N ((int)(2e5+5)) #define int long long int using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<vi> vivi; typedef pair<char,int> pci; const int inf = 1e18 + 5; #endif void fileio(string s){ #ifndef ONLINE_JUDGE freopen((s+string(".in")).c_str(),"r",stdin); freopen((s+string(".out")).c_str(),"w",stdout); #endif } /* 1. CHECK IF THE ANSWER IS MODULO M 2. Edge cases 3. Check for overflow (maybe before edge cases idk) 23. Use the number 23 (it automatically makes everything turn to ac) */ bool valid(string& a){ stack<char> s; for(char c : a){ if(c == ')'){ if(s.empty()){ return false; } s.pop(); } else{ s.push(c); } } if(s.size())return false; return true; } vivi pref(501, vi(501)), g(501, vi(501)); int r, s, a, b; int get(int x, int y, int xx, int yy){ int sum = pref[xx][yy]; sum -= pref[xx][y]; sum -= pref[x][yy]; sum += pref[x][y]; return sum; } void build(){ for(int i = 1; i <= r; ++i){ for(int j = 1; j <= s; ++j){ pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1] + g[i][j]; } } } void solve(){ cin >> r >> s >> a >> b; for(int i = 1; i <= r; ++i){ for(int j = 1; j <= s; ++j){ cin >> g[i][j]; } } build(); int ans = inf; for(int li = 1; li <= r; ++li){ for(int ri = li; ri <= r; ++ri){ for(int lj = 1; lj <= s; ++lj){ for(int rj = lj; rj <= s; ++rj){ int cur = get(li - 1, lj - 1, ri, rj); ans = min(ans, abs(cur - a) + abs(cur - b)); //cout << li << ' ' << lj << ' ' << ri << ' ' << rj << ' ' << cur << endl; } } } } cout << ans << endl; } signed main(){ //fileio("test"); // Don't forget to comment out fio; //int t;cin >> t;while(t--) solve(); } /* */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4180 KB | Output is correct |
2 | Correct | 3 ms | 4284 KB | Output is correct |
3 | Correct | 3 ms | 4180 KB | Output is correct |
4 | Correct | 2 ms | 4180 KB | Output is correct |
5 | Correct | 2 ms | 4288 KB | Output is correct |
6 | Correct | 2 ms | 4180 KB | Output is correct |
7 | Correct | 3 ms | 4180 KB | Output is correct |
8 | Correct | 2 ms | 4292 KB | Output is correct |
9 | Correct | 2 ms | 4284 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4180 KB | Output is correct |
2 | Correct | 3 ms | 4284 KB | Output is correct |
3 | Correct | 3 ms | 4180 KB | Output is correct |
4 | Correct | 2 ms | 4180 KB | Output is correct |
5 | Correct | 2 ms | 4288 KB | Output is correct |
6 | Correct | 2 ms | 4180 KB | Output is correct |
7 | Correct | 3 ms | 4180 KB | Output is correct |
8 | Correct | 2 ms | 4292 KB | Output is correct |
9 | Correct | 2 ms | 4284 KB | Output is correct |
10 | Correct | 15 ms | 4300 KB | Output is correct |
11 | Correct | 59 ms | 4364 KB | Output is correct |
12 | Correct | 50 ms | 4368 KB | Output is correct |
13 | Correct | 49 ms | 4300 KB | Output is correct |
14 | Correct | 3 ms | 4180 KB | Output is correct |
15 | Correct | 49 ms | 4308 KB | Output is correct |
16 | Correct | 49 ms | 4308 KB | Output is correct |
17 | Correct | 57 ms | 4368 KB | Output is correct |
18 | Correct | 49 ms | 4316 KB | Output is correct |
19 | Correct | 60 ms | 4428 KB | Output is correct |
20 | Correct | 49 ms | 4312 KB | Output is correct |
21 | Correct | 49 ms | 4308 KB | Output is correct |
22 | Correct | 49 ms | 4316 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4180 KB | Output is correct |
2 | Correct | 3 ms | 4284 KB | Output is correct |
3 | Correct | 3 ms | 4180 KB | Output is correct |
4 | Correct | 2 ms | 4180 KB | Output is correct |
5 | Correct | 2 ms | 4288 KB | Output is correct |
6 | Correct | 2 ms | 4180 KB | Output is correct |
7 | Correct | 3 ms | 4180 KB | Output is correct |
8 | Correct | 2 ms | 4292 KB | Output is correct |
9 | Correct | 2 ms | 4284 KB | Output is correct |
10 | Correct | 15 ms | 4300 KB | Output is correct |
11 | Correct | 59 ms | 4364 KB | Output is correct |
12 | Correct | 50 ms | 4368 KB | Output is correct |
13 | Correct | 49 ms | 4300 KB | Output is correct |
14 | Correct | 3 ms | 4180 KB | Output is correct |
15 | Correct | 49 ms | 4308 KB | Output is correct |
16 | Correct | 49 ms | 4308 KB | Output is correct |
17 | Correct | 57 ms | 4368 KB | Output is correct |
18 | Correct | 49 ms | 4316 KB | Output is correct |
19 | Correct | 60 ms | 4428 KB | Output is correct |
20 | Correct | 49 ms | 4312 KB | Output is correct |
21 | Correct | 49 ms | 4308 KB | Output is correct |
22 | Correct | 49 ms | 4316 KB | Output is correct |
23 | Execution timed out | 2044 ms | 6348 KB | Time limit exceeded |
24 | Halted | 0 ms | 0 KB | - |