Submission #28796

# Submission time Handle Problem Language Result Execution time Memory
28796 2017-07-17T08:15:18 Z kajebiii Oriental P.A.D.A.K (FXCUP2_padak) C++14
1 / 1
513 ms 13740 KB
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, pi> plp;
typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
 
const int MAX_V = 1e6 + 100;
 
int N, M, K, B, Z;
int When[MAX_V], Q[MAX_V], List[MAX_V]; int r=0, f=0, ln = 0;
inline pi toPi(int s) {return pi(s/M, s%M);}
inline int toS(int x, int y) {return x*M+y;}
int main() {
	cin >> N >> M >> K >> B >> Z;
	for(int i=0; i<N; i++) for(int j=0; j<M; j++) When[toS(i, j)] = -1;
	for(int k=0; k<K; k++) {
		int x, y; scanf("%d%d", &x, &y); x--; y--;
		When[toS(x, y)] = 0;
		Q[r++] = toS(x, y);
	}
	int maxK = -1;
	while(f < r) {
		int s = Q[f]; f++;
		int x, y; tie(x, y) = toPi(s);
		int v = When[s];
//		printf("%d %d : %d\n", x, y, v);
		List[ln++] = maxK = v;
		for(int k=0; k<4; k++) {
			int nx = x + "1012"[k] - '1', ny = y + "0121"[k] - '1';
			if(nx < 0 || ny < 0 || nx >= N || ny >= M) continue;
			if(When[toS(nx,ny)] != -1) continue;
			When[toS(nx, ny)] = v+1;
//			printf("push %d %d [%d]\n", nx, ny, v+1);
			Q[r++] = toS(nx, ny);
		}
	}
	int ix = 0, maxAns = 0;
	for(int k=1; k<=maxK+1; k++) {
		while(ix < ln && List[ix] < k) ix++;
		int now = min(Z, ln - ix);
		maxAns += now;
		ix += now;
	}
	int minAns = 0;
	ix = ln - 1;
	for(int k=1; k<=maxK+1; k++) {
		for(int i=0; i<Z; i++) {
			if(ix < 0 || List[ix] < k) break;
			minAns++; ix--;
		}
		if(ix < 0 || List[ix] < k) break;
	}
	printf("%d %d\n", minAns, maxAns);
 
	return 0;
}

Compilation message

padak.cpp: In function 'int main()':
padak.cpp:26:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d", &x, &y); x--; y--;
                                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13740 KB Output is correct
2 Correct 0 ms 13740 KB Output is correct
3 Correct 26 ms 13740 KB Output is correct
4 Correct 23 ms 13740 KB Output is correct
5 Correct 26 ms 13740 KB Output is correct
6 Correct 26 ms 13740 KB Output is correct
7 Correct 26 ms 13740 KB Output is correct
8 Correct 23 ms 13740 KB Output is correct
9 Correct 29 ms 13740 KB Output is correct
10 Correct 26 ms 13740 KB Output is correct
11 Correct 26 ms 13740 KB Output is correct
12 Correct 29 ms 13740 KB Output is correct
13 Correct 39 ms 13740 KB Output is correct
14 Correct 19 ms 13740 KB Output is correct
15 Correct 29 ms 13740 KB Output is correct
16 Correct 23 ms 13740 KB Output is correct
17 Correct 39 ms 13740 KB Output is correct
18 Correct 59 ms 13740 KB Output is correct
19 Correct 63 ms 13740 KB Output is correct
20 Correct 33 ms 13740 KB Output is correct
21 Correct 73 ms 13740 KB Output is correct
22 Correct 39 ms 13740 KB Output is correct
23 Correct 53 ms 13740 KB Output is correct
24 Correct 513 ms 13740 KB Output is correct
25 Correct 443 ms 13740 KB Output is correct
26 Correct 266 ms 13740 KB Output is correct
27 Correct 439 ms 13740 KB Output is correct
28 Correct 446 ms 13740 KB Output is correct
29 Correct 453 ms 13740 KB Output is correct
30 Correct 416 ms 13740 KB Output is correct
31 Correct 46 ms 13740 KB Output is correct
32 Correct 29 ms 13740 KB Output is correct