Submission #967431

# Submission time Handle Problem Language Result Execution time Memory
967431 2024-04-22T05:52:31 Z Isam Zemljište (COCI22_zemljiste) C++17
0 / 70
1 ms 2396 KB
#include<bits/stdc++.h>
using namespace std;

constexpr long long inf = 1e18 + 7;

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){
	if(max(x1,y2)>r||max(y1,y2)>s) return inf;
	long long res = pref[x2][y2] - pref[x1][y2] - pref[x2][y1] + pref[x1][y1];
	if(x1!=x2||y1!=y2) ans = min(ans, abs(a - res) + abs(b - res));
	return res;
}

signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> r >> s >> a >> b;
	if(a>b) swap(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]; 
		}
	}
	
	int xl(0), yl(0), xr(1), yr(1);
	
	long long cur = get_sm(xl, xr, yl, yr);
	
	while(xr <= r && yr <= s){
		
		if(cur <= b){
			
			long long y = get_sm(xl, xr, yr, yr + 1);
			
			long long x = get_sm(xr, xr + 1, yl, yr);
			
			if(x > y && yr < r){
				++yr;
			}else{
				++xr;
			}
			
		}else{
			
			
			long long y = get_sm(xl, xr, yl, yl + 1);
			
			long long x = get_sm(xl, xl + 1, yl, yr);
			
			if(x > y){
				++yl;
			}else{
				++xl;
			}
			
			
		}
		
		
		
		cur = get_sm(xl, xr, yl, yr);
	}
	
	
	cout << ans << '\n';
	
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:21:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   21 |  for(register int i = 1; i <= r; ++i){
      |                   ^
Main.cpp:22:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   22 |   for(register int j = 1; j <= s; ++j){
      |                    ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -