#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}};
vector<vector<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));
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:17: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 |
13820 KB |
Output is correct |
5 |
Correct |
36 ms |
13780 KB |
Output is correct |
6 |
Correct |
33 ms |
18384 KB |
Output is correct |
7 |
Correct |
33 ms |
14032 KB |
Output is correct |
8 |
Correct |
36 ms |
21560 KB |
Output is correct |
9 |
Correct |
93 ms |
64560 KB |
Output is correct |
10 |
Correct |
43 ms |
13796 KB |
Output is correct |
11 |
Correct |
33 ms |
13952 KB |
Output is correct |
12 |
Correct |
39 ms |
13780 KB |
Output is correct |
13 |
Correct |
43 ms |
18516 KB |
Output is correct |
14 |
Correct |
39 ms |
14032 KB |
Output is correct |
15 |
Correct |
29 ms |
21560 KB |
Output is correct |
16 |
Correct |
153 ms |
64560 KB |
Output is correct |
17 |
Correct |
46 ms |
14060 KB |
Output is correct |
18 |
Correct |
86 ms |
14480 KB |
Output is correct |
19 |
Correct |
63 ms |
14044 KB |
Output is correct |
20 |
Correct |
63 ms |
18648 KB |
Output is correct |
21 |
Correct |
89 ms |
14972 KB |
Output is correct |
22 |
Correct |
36 ms |
21560 KB |
Output is correct |
23 |
Correct |
233 ms |
64560 KB |
Output is correct |
24 |
Correct |
399 ms |
22180 KB |
Output is correct |
25 |
Correct |
443 ms |
22132 KB |
Output is correct |
26 |
Correct |
443 ms |
22164 KB |
Output is correct |
27 |
Correct |
623 ms |
26784 KB |
Output is correct |
28 |
Correct |
466 ms |
22204 KB |
Output is correct |
29 |
Correct |
406 ms |
25912 KB |
Output is correct |
30 |
Memory limit exceeded |
113 ms |
65536 KB |
Memory limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |