# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28651 | 볼빨간 승관이 (#68) | Oriental P.A.D.A.K (FXCUP2_padak) | C++11 | 646 ms | 24436 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using std::pair;
using std::vector;
using pii = pair<int, int>;
bool wall[1000010];
int dist[1000010];
bool chk[1000010];
int main() {
memset(dist, 0x3f, sizeof(dist));
int n, m, k, b, z;
scanf("%d%d%d%d%d", &n, &m, &k, &b, &z);
std::queue<int> que;
auto idx = [&](int i, int j) {return i*m + j; };
for (int i = 0; i < k; i++) {
int a, b;
scanf("%d%d", &a, &b);
a--; b--;
wall[idx(a, b)] = 1;
que.push(idx(a, b));
dist[idx(a, b)] = 0;
}
const int X[] = { +1,-1,0,0 };
const int Y[] = { 0,0,+1,-1 };
auto inner = [&](int i, int j) {return i >= 0 && i < n && j >= 0 && j < m; };
while (!que.empty()) {
int p = que.front();
que.pop();
int x = p / m;
int y = p%m;
for (int k = 0; k < 4; k++) {
int nx = x + X[k];
int ny = y + Y[k];
if (inner(nx, ny) && dist[idx(nx, ny)] > dist[p] + 1 && wall[idx(nx,ny)]==0) {
dist[idx(nx, ny)] = dist[p] + 1;
que.push(idx(nx, ny));
}
}
}
vector<pii> order;
for (int i = 0; i < n*m; i++) {
order.push_back({ dist[i],i });
}
std::sort(order.begin(), order.end());
int ans1 = 0, ans2 = 0;
int t = 1;
int p = 0;
while (p < n*m) {
while (p<n*m && order[p].first < t)p++;
for (int i = 0; i < z; i++) {
if (p < n*m) {
ans1++;
p++;
}
}
t++;
}
std::reverse(order.begin(), order.end());
t = 1;
p = 0;
while (p < n*m) {
while (p<n*m && order[p].first < t)p++;
for (int i = 0; i < z; i++) {
if (p < n*m && order[p].first>=t) {
ans2++;
p++;
}
}
t++;
}
printf("%d %d", ans2, ans1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |