Submission #801256

# Submission time Handle Problem Language Result Execution time Memory
801256 2023-08-02T05:16:00 Z Tunglam07 Zemljište (COCI22_zemljiste) C++17
70 / 70
301 ms 6664 KB
#include<bits/stdc++.h>
using namespace std;
 
long long n, m, a, b, c[501][501], price[501][501];

long long val(int x, int y, int u, int v)
{
	return price[u][v] - price[x - 1][v] - price[u][y - 1] + price[x - 1][y - 1];
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);
    cin >> n >> m >> a >> b;
    for(int i = 1; i <= n; i++)
	{
        for(int j = 1; j <= m; j++)
		{
            cin >> c[i][j];
        }
    }    
 
    for(int i = 1; i <= n; i++)
	{
        for(int j = 1; j <= m; j++)
		{
            price[i][j] = price[i - 1][j] + price[i][j - 1] - price[i - 1][j - 1] + c[i][j]; 
        }
    }
 
    long long ans = INT_MAX;
    if(a > b) 
	{
		swap(a, b);
	}
 
    for(int i = 1; i <= n; i++)
	{
         for(int j = i; j <= n; j++)
		 {
            long long p = 0;
 
            for(int k = 1; k <= m; k++)
			{
				while(p < k && val(i, 1, j, k) - val(i, 1, j, p) >= a) 
				{
					p++;
				}
                if(p < k) 
				{
					ans = min(ans, abs(val(i, 1, j, k) - val(i, 1, j, p) - a) + abs(val(i, 1, j, k) - val(i, 1, j, p) - b));
				}
                if(p >= 1) 
				{
					ans = min(ans, abs(val(i, 1, j, k) - val(i, 1, j, p - 1) - a) + abs(val(i, 1, j, k) - val(i, 1, j, p - 1) - b));
				}
            }
            
         }
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 6 ms 1216 KB Output is correct
12 Correct 5 ms 1112 KB Output is correct
13 Correct 4 ms 1108 KB Output is correct
14 Correct 1 ms 496 KB Output is correct
15 Correct 4 ms 1112 KB Output is correct
16 Correct 4 ms 1108 KB Output is correct
17 Correct 4 ms 1216 KB Output is correct
18 Correct 3 ms 1112 KB Output is correct
19 Correct 3 ms 1092 KB Output is correct
20 Correct 3 ms 1108 KB Output is correct
21 Correct 3 ms 1172 KB Output is correct
22 Correct 3 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 6 ms 1216 KB Output is correct
12 Correct 5 ms 1112 KB Output is correct
13 Correct 4 ms 1108 KB Output is correct
14 Correct 1 ms 496 KB Output is correct
15 Correct 4 ms 1112 KB Output is correct
16 Correct 4 ms 1108 KB Output is correct
17 Correct 4 ms 1216 KB Output is correct
18 Correct 3 ms 1112 KB Output is correct
19 Correct 3 ms 1092 KB Output is correct
20 Correct 3 ms 1108 KB Output is correct
21 Correct 3 ms 1172 KB Output is correct
22 Correct 3 ms 1108 KB Output is correct
23 Correct 279 ms 4616 KB Output is correct
24 Correct 253 ms 6652 KB Output is correct
25 Correct 245 ms 6656 KB Output is correct
26 Correct 262 ms 6652 KB Output is correct
27 Correct 178 ms 5812 KB Output is correct
28 Correct 301 ms 6660 KB Output is correct
29 Correct 263 ms 6656 KB Output is correct
30 Correct 296 ms 6656 KB Output is correct
31 Correct 48 ms 4212 KB Output is correct
32 Correct 250 ms 6652 KB Output is correct
33 Correct 257 ms 6652 KB Output is correct
34 Correct 262 ms 6632 KB Output is correct
35 Correct 263 ms 6652 KB Output is correct
36 Correct 246 ms 6664 KB Output is correct
37 Correct 246 ms 6652 KB Output is correct
38 Correct 261 ms 6636 KB Output is correct
39 Correct 253 ms 6656 KB Output is correct
40 Correct 244 ms 6656 KB Output is correct
41 Correct 159 ms 5400 KB Output is correct
42 Correct 170 ms 5392 KB Output is correct
43 Correct 196 ms 5388 KB Output is correct
44 Correct 179 ms 5392 KB Output is correct