Submission #28410

# Submission time Handle Problem Language Result Execution time Memory
28410 2017-07-16T05:25:03 Z tlwpdus 팬클럽 회장(#1123, kdh9949) Oriental P.A.D.A.K (FXCUP2_padak) C++14
1 / 1
456 ms 21640 KB
#include <bits/stdc++.h>
using namespace std;

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, q[2000010], f, r;

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[r++] = x * 2 * m + y;
	}
	while(f < r){
		int x = q[f] / (2 * m), y = q[f] % (2 * m); f++;
		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[r++] = nx * 2 * m + 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 = 0; 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;
		if(j < i) break;
		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:8: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:15:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &y);
                        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17652 KB Output is correct
2 Correct 0 ms 17652 KB Output is correct
3 Correct 29 ms 21612 KB Output is correct
4 Correct 39 ms 21640 KB Output is correct
5 Correct 36 ms 21592 KB Output is correct
6 Correct 29 ms 21572 KB Output is correct
7 Correct 36 ms 21636 KB Output is correct
8 Correct 19 ms 21560 KB Output is correct
9 Correct 29 ms 21560 KB Output is correct
10 Correct 36 ms 21612 KB Output is correct
11 Correct 36 ms 21640 KB Output is correct
12 Correct 33 ms 21592 KB Output is correct
13 Correct 33 ms 21572 KB Output is correct
14 Correct 39 ms 21636 KB Output is correct
15 Correct 36 ms 21560 KB Output is correct
16 Correct 26 ms 21560 KB Output is correct
17 Correct 49 ms 21612 KB Output is correct
18 Correct 59 ms 21640 KB Output is correct
19 Correct 33 ms 21592 KB Output is correct
20 Correct 36 ms 21572 KB Output is correct
21 Correct 63 ms 21636 KB Output is correct
22 Correct 36 ms 21560 KB Output is correct
23 Correct 36 ms 21560 KB Output is correct
24 Correct 436 ms 21612 KB Output is correct
25 Correct 443 ms 21640 KB Output is correct
26 Correct 399 ms 21592 KB Output is correct
27 Correct 456 ms 21572 KB Output is correct
28 Correct 413 ms 21636 KB Output is correct
29 Correct 423 ms 21560 KB Output is correct
30 Correct 453 ms 21560 KB Output is correct
31 Correct 19 ms 21612 KB Output is correct
32 Correct 29 ms 21560 KB Output is correct