#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, pi> plp;
typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
int N, M, K, B, Z;
vector<vector<int>> When;
int main() {
cin >> N >> M >> K >> B >> Z;
When = vector<vector<int>>(N, vector<int>(M, -1));
queue<pair<pi, int> > Q;
for(int k=0; k<K; k++) {
int x, y; scanf("%d%d", &x, &y); x--; y--;
Q.push(make_pair(pi(x, y), 0));
When[x][y] = 0;
}
int maxK = -1;
vector<int> list;
while(!Q.empty()) {
pi p; int v; tie(p, v) = Q.front(); Q.pop(); int x, y; tie(x, y) = p;
list.push_back(v);
maxK = v;
for(int k=0; k<4; k++) {
int nx = x + "1012"[k] - '1', ny = y + "0121"[k] - '1';
if(nx < 0 || ny < 0 || nx >= N || ny >= M) continue;
if(When[nx][ny] != -1) continue;
When[nx][ny] = v+1;
Q.push(make_pair(pi(nx, ny), v+1));
}
}
int ix = 0, maxAns = 0;
for(int k=1; k<=maxK+1; k++) {
while(ix < SZ(list) && list[ix] < k) ix++;
int now = min(Z, SZ(list) - ix);
maxAns += now;
ix += now;
}
int minAns = 0;
ix = SZ(list) - 1;
for(int k=1; k<=maxK+1; k++) {
for(int i=0; i<Z; i++) {
if(ix < 0 || list[ix] < k) break;
minAns++; ix--;
}
if(ix < 0 || list[ix] < k) break;
}
printf("%d %d\n", minAns, maxAns);
return 0;
}
Compilation message
padak.cpp: In function 'int main()':
padak.cpp:23:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int x, y; scanf("%d%d", &x, &y); x--; y--;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2024 KB |
Output is correct |
2 |
Correct |
0 ms |
2024 KB |
Output is correct |
3 |
Correct |
53 ms |
12208 KB |
Output is correct |
4 |
Correct |
39 ms |
12196 KB |
Output is correct |
5 |
Correct |
29 ms |
12184 KB |
Output is correct |
6 |
Correct |
29 ms |
15284 KB |
Output is correct |
7 |
Correct |
33 ms |
12264 KB |
Output is correct |
8 |
Correct |
39 ms |
14204 KB |
Output is correct |
9 |
Correct |
89 ms |
62944 KB |
Output is correct |
10 |
Correct |
39 ms |
12220 KB |
Output is correct |
11 |
Correct |
39 ms |
12264 KB |
Output is correct |
12 |
Correct |
46 ms |
12208 KB |
Output is correct |
13 |
Correct |
43 ms |
15304 KB |
Output is correct |
14 |
Correct |
66 ms |
12268 KB |
Output is correct |
15 |
Correct |
39 ms |
14208 KB |
Output is correct |
16 |
Correct |
159 ms |
62944 KB |
Output is correct |
17 |
Correct |
59 ms |
12672 KB |
Output is correct |
18 |
Correct |
76 ms |
13232 KB |
Output is correct |
19 |
Correct |
69 ms |
12644 KB |
Output is correct |
20 |
Correct |
53 ms |
15416 KB |
Output is correct |
21 |
Correct |
96 ms |
13640 KB |
Output is correct |
22 |
Correct |
46 ms |
14228 KB |
Output is correct |
23 |
Correct |
249 ms |
63036 KB |
Output is correct |
24 |
Correct |
436 ms |
21468 KB |
Output is correct |
25 |
Correct |
446 ms |
21472 KB |
Output is correct |
26 |
Correct |
466 ms |
21440 KB |
Output is correct |
27 |
Correct |
613 ms |
24552 KB |
Output is correct |
28 |
Correct |
423 ms |
21432 KB |
Output is correct |
29 |
Correct |
433 ms |
26172 KB |
Output is correct |
30 |
Memory limit exceeded |
459 ms |
65536 KB |
Memory limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |