Submission #967411

# Submission time Handle Problem Language Result Execution time Memory
967411 2024-04-22T05:12:30 Z Isam Zemljište (COCI22_zemljiste) C++17
30 / 70
2000 ms 5972 KB
#include<bits/stdc++.h>
using namespace std;

int r, s, a, b, c[501][501];

long long pref[501][501], ans;

inline long long get_sm(int x1, int x2, int y1, int y2){
	return pref[x2][y2] - pref[x1][y2] - pref[x2][y1] + pref[x1][y1];
}

signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> r >> s >> a >> b;
	for(register int i = 1; i <= r; ++i){
		for(register int j = 1; j <= s; ++j){
			cin >> c[i][j];
			ans += c[i][j];
			pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1] + c[i][j]; 
		}
	}
	
	for(register int x1 = 0; x1 <= r; ++x1){
		
		for(register int y1 = 0; y1 <= s; ++y1){
			
			for(register int x2 = x1; x2 <= r; ++x2){
				
				for(register int y2 = y1; y2 <= s; ++y2){
					
					if(x1==x2 && y1==y2) continue;
					
					long long cur = get_sm(x1, x2, y1, y2);
					
					ans = min(ans, abs(cur - a) + abs(cur - b));
					
					if(cur >= max(a, b)) break;
					
				}
				
			}
			
			
		}
		
	}
	
	
	cout << ans << '\n';
	
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:15:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   15 |  for(register int i = 1; i <= r; ++i){
      |                   ^
Main.cpp:16:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   16 |   for(register int j = 1; j <= s; ++j){
      |                    ^
Main.cpp:23:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   23 |  for(register int x1 = 0; x1 <= r; ++x1){
      |                   ^~
Main.cpp:25:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   25 |   for(register int y1 = 0; y1 <= s; ++y1){
      |                    ^~
Main.cpp:27:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   27 |    for(register int x2 = x1; x2 <= r; ++x2){
      |                     ^~
Main.cpp:29:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   29 |     for(register int y2 = y1; y2 <= s; ++y2){
      |                      ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 5 ms 2652 KB Output is correct
12 Correct 5 ms 2652 KB Output is correct
13 Correct 5 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 5 ms 2652 KB Output is correct
16 Correct 5 ms 2652 KB Output is correct
17 Correct 5 ms 2904 KB Output is correct
18 Correct 59 ms 2652 KB Output is correct
19 Correct 60 ms 2676 KB Output is correct
20 Correct 59 ms 2652 KB Output is correct
21 Correct 59 ms 2676 KB Output is correct
22 Correct 60 ms 2676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 5 ms 2652 KB Output is correct
12 Correct 5 ms 2652 KB Output is correct
13 Correct 5 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 5 ms 2652 KB Output is correct
16 Correct 5 ms 2652 KB Output is correct
17 Correct 5 ms 2904 KB Output is correct
18 Correct 59 ms 2652 KB Output is correct
19 Correct 60 ms 2676 KB Output is correct
20 Correct 59 ms 2652 KB Output is correct
21 Correct 59 ms 2676 KB Output is correct
22 Correct 60 ms 2676 KB Output is correct
23 Correct 485 ms 3408 KB Output is correct
24 Correct 484 ms 5808 KB Output is correct
25 Correct 489 ms 5752 KB Output is correct
26 Correct 513 ms 5812 KB Output is correct
27 Correct 284 ms 4988 KB Output is correct
28 Correct 487 ms 5808 KB Output is correct
29 Correct 513 ms 5912 KB Output is correct
30 Correct 481 ms 5812 KB Output is correct
31 Correct 48 ms 3416 KB Output is correct
32 Correct 488 ms 5852 KB Output is correct
33 Correct 491 ms 5968 KB Output is correct
34 Correct 499 ms 5812 KB Output is correct
35 Correct 487 ms 5804 KB Output is correct
36 Correct 523 ms 5808 KB Output is correct
37 Correct 497 ms 5808 KB Output is correct
38 Correct 488 ms 5972 KB Output is correct
39 Correct 496 ms 5972 KB Output is correct
40 Correct 484 ms 5812 KB Output is correct
41 Execution timed out 2025 ms 4396 KB Time limit exceeded
42 Halted 0 ms 0 KB -