#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", r1, r2);
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 |
Incorrect |
0 ms |
9836 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |