답안 #802912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
802912 2023-08-02T15:47:17 Z tlnk07 Zemljište (COCI22_zemljiste) C++17
0 / 70
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
 
long long n, m, x, a, b, pre[501][501], mini = INT_MAX;
 
int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);	cout.tie(0);
	cin >> n >> m >> a >> b;
	if(a > b)	swap(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)
		{
			int jj = 0;
			for(int ii = 1; ii <= n; ++ii)
			{
				long long temp = pre[i][j] - pre[i][jj - 1] - pre[ii - 1][j] + pre[ii - 1][jj - 1];
				while(jj < j && temp >= a)
				{
					++jj;
					temp = pre[i][j] - pre[i][jj - 1] - pre[ii - 1][j] + pre[ii - 1][jj - 1];
				}
				if(jj < j)	mini = min(mini, abs(temp - a) + abs(temp - b));
				temp = pre[i][j] - pre[i][jj - 2] - pre[ii - 1][j] + pre[ii - 1][jj - 2];
				if(jj >= 1)	mini = min(mini, abs(temp - a) + abs(temp - b));
			}
		}
	}
	cout << mini;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -