#include<stdio.h>
#include<memory.h>
int N, M, K, B, Z, chk[1010101], ccn[1010101];
int que[1010101], fr, rr;
int gton(int x, int y){ return (x-1)*M + (y-1); }
void ntog(int v, int &x, int &y){ x=v/M+1, y=v%M+1; }
int main(){
scanf("%d%d%d%d%d", &N, &M, &K, &B, &Z);
for(int i=0; i<N*M; i++) chk[i]=9999999;
for(int i=K; i--;){
int x, y;
scanf("%d%d", &x, &y); que[rr++] = gton(x, y);
chk[gton(x,y)] = 0;
}
for(; fr<rr; fr++){
int x, y, xx[4]={0,0,1,-1}, yy[4]={1,-1,0,0}; ntog(que[fr], x, y);
for(int i=0; i<4; i++){
int x2=x+xx[i], y2=y+yy[i], v=gton(x2,y2);
if(x2<1 || y2<1 || x2>N || y2>M) continue;
if(chk[v] <= chk[que[fr]]+1) continue;
chk[v] = chk[que[fr]]+1;
que[rr++] = v;
}
}
for(int i=0; i<N*M; i++) ccn[chk[i]]++;
for(int ix=0, i=0; i<N*M; i++){
for(int t=ccn[i]; t--;) chk[ix++] = i;
}
int zmi=0, zmx=0;
for(int i=0; i<N*M; i++){
if(chk[i] <= zmx/Z) continue;
zmx++;
}
for(int i=N*M-1; i>=0; i--){
if(chk[i] <= zmi/Z) break;
zmi++;
}
printf("%d %d\n", zmi, zmx);
return 0;
}
Compilation message
padak.cpp: In function 'int main()':
padak.cpp:11:41: 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:15:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y); que[rr++] = gton(x, y);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
12952 KB |
Output is correct |
2 |
Correct |
0 ms |
12952 KB |
Output is correct |
3 |
Correct |
63 ms |
12952 KB |
Output is correct |
4 |
Correct |
33 ms |
12952 KB |
Output is correct |
5 |
Correct |
43 ms |
12952 KB |
Output is correct |
6 |
Correct |
39 ms |
12952 KB |
Output is correct |
7 |
Correct |
39 ms |
12952 KB |
Output is correct |
8 |
Correct |
39 ms |
12952 KB |
Output is correct |
9 |
Correct |
36 ms |
12952 KB |
Output is correct |
10 |
Correct |
53 ms |
12952 KB |
Output is correct |
11 |
Correct |
36 ms |
12952 KB |
Output is correct |
12 |
Correct |
39 ms |
12952 KB |
Output is correct |
13 |
Correct |
43 ms |
12952 KB |
Output is correct |
14 |
Correct |
43 ms |
12952 KB |
Output is correct |
15 |
Correct |
43 ms |
12952 KB |
Output is correct |
16 |
Correct |
46 ms |
12952 KB |
Output is correct |
17 |
Correct |
49 ms |
12952 KB |
Output is correct |
18 |
Correct |
63 ms |
12952 KB |
Output is correct |
19 |
Correct |
49 ms |
12952 KB |
Output is correct |
20 |
Correct |
43 ms |
12952 KB |
Output is correct |
21 |
Correct |
69 ms |
12952 KB |
Output is correct |
22 |
Correct |
59 ms |
12952 KB |
Output is correct |
23 |
Correct |
49 ms |
12952 KB |
Output is correct |
24 |
Correct |
426 ms |
12952 KB |
Output is correct |
25 |
Correct |
406 ms |
12952 KB |
Output is correct |
26 |
Correct |
376 ms |
12952 KB |
Output is correct |
27 |
Correct |
249 ms |
12952 KB |
Output is correct |
28 |
Correct |
409 ms |
12952 KB |
Output is correct |
29 |
Correct |
389 ms |
12952 KB |
Output is correct |
30 |
Correct |
389 ms |
12952 KB |
Output is correct |
31 |
Correct |
43 ms |
12952 KB |
Output is correct |
32 |
Correct |
53 ms |
12952 KB |
Output is correct |