제출 #28651

#제출 시각아이디문제언어결과실행 시간메모리
28651볼빨간 승관이 (#68)Oriental P.A.D.A.K (FXCUP2_padak)C++11
1 / 1
646 ms24436 KiB
#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) 메시지

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:16:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...