답안 #802897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
802897 2023-08-02T15:41:52 Z tlnk07 Zemljište (COCI22_zemljiste) C++17
30 / 70
2000 ms 4664 KB
#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;
	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)
		{
			for(int ii = 1; ii <= n; ++ii)
			{
				int jj = 0;
				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];
				}
				mini = min(mini, abs(temp - a) + abs(temp - b));
				--jj;
				temp = pre[i][j] - pre[i][jj - 1] - pre[ii - 1][j] + pre[ii - 1][jj - 1];
				if(jj > 0)	mini = min(mini, abs(temp - a) + abs(temp - b));
			}
		}
	}
	cout << mini;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:28:47: warning: array subscript -1 is below array bounds of 'long long int [501]' [-Warray-bounds]
   28 |     long long temp = pre[i][j] - pre[i][jj - 1] - pre[ii - 1][j] + pre[ii - 1][jj - 1];
      |                                  ~~~~~~~~~~~~~^
Main.cpp:28:86: warning: array subscript -1 is below array bounds of 'long long int [501]' [-Warray-bounds]
   28 |     long long temp = pre[i][j] - pre[i][jj - 1] - pre[ii - 1][j] + pre[ii - 1][jj - 1];
      |                                                                    ~~~~~~~~~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 400 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 400 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 8 ms 628 KB Output is correct
11 Correct 28 ms 716 KB Output is correct
12 Correct 28 ms 724 KB Output is correct
13 Correct 28 ms 724 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 27 ms 792 KB Output is correct
16 Correct 28 ms 724 KB Output is correct
17 Correct 27 ms 792 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 5 ms 700 KB Output is correct
20 Correct 5 ms 724 KB Output is correct
21 Correct 4 ms 724 KB Output is correct
22 Correct 5 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 400 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 8 ms 628 KB Output is correct
11 Correct 28 ms 716 KB Output is correct
12 Correct 28 ms 724 KB Output is correct
13 Correct 28 ms 724 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 27 ms 792 KB Output is correct
16 Correct 28 ms 724 KB Output is correct
17 Correct 27 ms 792 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 5 ms 700 KB Output is correct
20 Correct 5 ms 724 KB Output is correct
21 Correct 4 ms 724 KB Output is correct
22 Correct 5 ms 724 KB Output is correct
23 Correct 480 ms 4564 KB Output is correct
24 Correct 450 ms 4656 KB Output is correct
25 Correct 477 ms 4664 KB Output is correct
26 Correct 451 ms 4656 KB Output is correct
27 Execution timed out 2082 ms 3764 KB Time limit exceeded
28 Halted 0 ms 0 KB -