# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
28651 | 볼빨간 승관이 (#68) | Oriental P.A.D.A.K (FXCUP2_padak) | C++11 | 646 ms | 24436 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |