#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int n, m, k, b, z, c1[1000010], c2[1000010];
int dir[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
int** T;
bool is_valid(int x, int y) {
return x >= 1 && y >= 1 && x <= m && y <= n;
}
int main() {
scanf("%d%d%d%d%d", &n, &m, &k, &b, &z);
//T = vector<vector<int> >(n + 1, vector<int>(m + 1, -1));
T = new int*[n + 1];
for(int i = 1; i <= n; ++i) {
T[i] = new int[m + 1];
for(int j = 1; j <= m; ++j) T[i][j] = -1;
}
queue<pair<int, int> > q;
for(int i = 0, r, c; i < k; ++i) {
scanf("%d%d", &r, &c);
T[r][c] = 0;
q.push({c, r});
}
while(!q.empty()) {
int x = q.front().first;
int y = q.front().second; q.pop();
for(int i = 0; i < 4; ++i) {
int tx = x + dir[i][0];
int ty = y + dir[i][1];
if(!is_valid(tx, ty) || T[ty][tx] >= 0) continue;
T[ty][tx] = T[y][x] + 1;
q.push({tx, ty});
}
}
int mx = 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
c1[T[i][j]]++, c2[T[i][j]]++, mx = max(mx, T[i][j]);
int r1 = 0, r2 = 0;
for(int t = 1, last = 1; ; ++t) {
if(last > mx) break;
int rem = z;
while(rem > 0) {
if(last > mx) break;
int eat = min(c1[last], rem);
c1[last] -= eat;
rem -= eat;
r1 += eat;
if(!c1[last]) last++;
}
if(last == t) last++;
}
for(int t = 1, last = mx; ; ++t) {
int rem = z;
while(rem > 0) {
if(t > last) break;
int eat = min(c2[last], rem);
c2[last] -= eat;
rem -= eat;
r2 += eat;
if(!c2[last]) last--;
}
if(t > last) break;
}
printf("%d %d", r2, r1);
return 0;
}
/*
3 4 3 2 3
1 1
2 4
3 2
*/
Compilation message
padak.cpp: In function 'int main()':
padak.cpp:13:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d%d", &n, &m, &k, &b, &z);
^
padak.cpp:22:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &r, &c);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
9836 KB |
Output is correct |
2 |
Correct |
0 ms |
9836 KB |
Output is correct |
3 |
Correct |
36 ms |
13796 KB |
Output is correct |
4 |
Correct |
33 ms |
13824 KB |
Output is correct |
5 |
Correct |
33 ms |
13776 KB |
Output is correct |
6 |
Correct |
26 ms |
16824 KB |
Output is correct |
7 |
Correct |
33 ms |
13820 KB |
Output is correct |
8 |
Correct |
29 ms |
13744 KB |
Output is correct |
9 |
Correct |
69 ms |
48936 KB |
Output is correct |
10 |
Correct |
39 ms |
13796 KB |
Output is correct |
11 |
Correct |
39 ms |
13956 KB |
Output is correct |
12 |
Correct |
36 ms |
13776 KB |
Output is correct |
13 |
Correct |
43 ms |
16956 KB |
Output is correct |
14 |
Correct |
33 ms |
13820 KB |
Output is correct |
15 |
Correct |
29 ms |
13744 KB |
Output is correct |
16 |
Correct |
109 ms |
48936 KB |
Output is correct |
17 |
Correct |
56 ms |
14060 KB |
Output is correct |
18 |
Correct |
79 ms |
14492 KB |
Output is correct |
19 |
Correct |
53 ms |
14040 KB |
Output is correct |
20 |
Correct |
46 ms |
17088 KB |
Output is correct |
21 |
Correct |
76 ms |
14744 KB |
Output is correct |
22 |
Correct |
29 ms |
13744 KB |
Output is correct |
23 |
Correct |
163 ms |
48936 KB |
Output is correct |
24 |
Correct |
406 ms |
22172 KB |
Output is correct |
25 |
Correct |
396 ms |
22116 KB |
Output is correct |
26 |
Correct |
323 ms |
22152 KB |
Output is correct |
27 |
Correct |
626 ms |
25224 KB |
Output is correct |
28 |
Correct |
406 ms |
22096 KB |
Output is correct |
29 |
Correct |
413 ms |
21988 KB |
Output is correct |
30 |
Correct |
806 ms |
57256 KB |
Output is correct |
31 |
Correct |
36 ms |
13796 KB |
Output is correct |
32 |
Correct |
66 ms |
48936 KB |
Output is correct |