답안 #28390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28390 2017-07-16T05:11:45 Z tlwpdus 팬클럽 회장(#1123, kdh9949) Oriental P.A.D.A.K (FXCUP2_padak) C++14
0 / 1
0 ms 9844 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

const int inf = 1e9, dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, k, b, z, tr, *md[1010], cnt[1000010], ccnt[1000010], mn, mx;
queue<pii> q;

int main(){
	scanf("%d%d%d%d%d", &n, &m, &k, &b, &z);
	if(n > m){ swap(n, m); tr = 1; }
	for(int i = 1; i <= n; i++){
		md[i] = new int[m + 1];
		fill(md[i] + 1, md[i] + m + 1, inf);
	}
	for(int x, y; k--; ){
		scanf("%d%d", &x, &y);
		if(tr) swap(x, y);
		md[x][y] = 0;
		q.push(pii(x, y));
	}
	while(!q.empty()){
		int x, y; tie(x, y) = q.front(); q.pop();
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(nx < 1 || ny < 1 || nx > n || ny > m) continue;
			if(md[nx][ny] > md[x][y] + 1){
				md[nx][ny] = md[x][y] + 1;
				q.push(pii(nx, ny));
			}
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cnt[md[i][j]]++;
			ccnt[md[i][j]]++;
		}
	}
	for(int i = 1, j; i <= n + m; i++){
		int t = z;
		j = max(j, i);
		while(t >= cnt[j]){
			mx += cnt[j];
			t -= cnt[j];
			cnt[j] = 0;
			j++;
			if(j > n + m) break;
		}
		if(j > n + m) break;
		if(t){
			mx += t;
			cnt[j] -= t;
		}
	}
	for(int i = 1, j = n + m; i <= n + m; i++){
		int t = z;
		while(t >= ccnt[j]){
			mn += ccnt[j];
			t -= ccnt[j];
			ccnt[j] = 0;
			j--;
			if(j < i) break;
		}
		if(j < i) break;
		if(t){
			mn += t;
			ccnt[j] -= t;
		}
	}
	printf("%d %d\n", mn, mx);
}

Compilation message

padak.cpp: In function 'int main()':
padak.cpp:10: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:17:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &y);
                        ^
padak.cpp:39:17: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
  for(int i = 1, j; i <= n + m; i++){
                 ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 9844 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -