Submission #28773

# Submission time Handle Problem Language Result Execution time Memory
28773 2017-07-17T07:31:10 Z sgc109 Oriental P.A.D.A.K (FXCUP2_padak) C++11
1 / 1
809 ms 57256 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int INF = 0x3c3c3c3c;
const long long INFL = 0x3c3c3c3c3c3c3c3c;

int N, M, K, B, Z;
bool inRange(int i, int j){
	return 0 <= i && i < N && 0 <= j && j < M;
}
int cnt[1000003];
int backup[1000003];	
int** dist;
queue<pair<int,int> > q;
int main() {
	scanf("%d%d%d%d%d",&N,&M,&K,&B,&Z);
	dist = (int**)malloc(sizeof(int*) * N);
	for(int i = 0 ; i < N; i++) dist[i] = (int*)malloc(sizeof(int) * M);
	for(int i = 0 ; i < N; i++) for(int j = 0 ; j < M; j++) dist[i][j] = -1;
	for(int i = 0 ; i < K; i++){
		int r,c;
		scanf("%d%d",&r,&c);
		r--, c--;
		q.push({r, c});
		dist[r][c] = 0;
	}
	int maxD = 0;
	while(!q.empty()){
		auto p = q.front();
		q.pop();
		int ci = p.first;
		int cj = p.second;
		for(int k = 0 ; k < 4; k++){
			int ni = ci + "1021"[k] - '1';
			int nj = cj + "0112"[k] - '1';
			if(!inRange(ni, nj) || dist[ni][nj] != -1) continue;
			dist[ni][nj] = dist[ci][cj] + 1;
			cnt[dist[ni][nj]]++;
			maxD = max(maxD, dist[ni][nj]);
			q.push({ni, nj});
		}
	}
	for(int i = 0; i <= maxD; i++) backup[i] = cnt[i];
	int ans1 = 0;
	int t = 0;
	int cur = Z;
	for(int i = maxD; t < i;) {
		if(cnt[i] > cur){
			cnt[i] -= cur;
			ans1 += cur;
			cur = Z;
			t++;
		}
		else {
			cur -= cnt[i];
			ans1 += cnt[i];
			i--;
		}
	}
	printf("%d\n",ans1);

	for(int i = 0 ; i <= maxD; i++) cnt[i] = backup[i];

	int ans2 = 0;
	t = 0;
	int pos = 1;
	cur = Z;
	while(t < maxD && pos <= maxD) {
		if(t == pos) pos = t + 1;
		if(cnt[pos] > cur){
			cnt[pos] -= cur;
			ans2 += cur;
			cur = Z;
			t++;
		}
		else {
			cur -= cnt[pos];
			ans2 += cnt[pos];
			pos++;
		}
	}

	printf("%d\n",ans2);

	return 0;
}

Compilation message

padak.cpp: In function 'int main()':
padak.cpp:17:36: 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:23:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&r,&c);
                      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9836 KB Output is correct
2 Correct 0 ms 9836 KB Output is correct
3 Correct 29 ms 13796 KB Output is correct
4 Correct 29 ms 13816 KB Output is correct
5 Correct 33 ms 13776 KB Output is correct
6 Correct 29 ms 15372 KB Output is correct
7 Correct 29 ms 13820 KB Output is correct
8 Correct 23 ms 13744 KB Output is correct
9 Correct 63 ms 48936 KB Output is correct
10 Correct 36 ms 13796 KB Output is correct
11 Correct 36 ms 13948 KB Output is correct
12 Correct 36 ms 13776 KB Output is correct
13 Correct 29 ms 15372 KB Output is correct
14 Correct 26 ms 13820 KB Output is correct
15 Correct 26 ms 13744 KB Output is correct
16 Correct 106 ms 48936 KB Output is correct
17 Correct 36 ms 14060 KB Output is correct
18 Correct 63 ms 14492 KB Output is correct
19 Correct 36 ms 14040 KB Output is correct
20 Correct 43 ms 15504 KB Output is correct
21 Correct 66 ms 14744 KB Output is correct
22 Correct 26 ms 13744 KB Output is correct
23 Correct 203 ms 48936 KB Output is correct
24 Correct 439 ms 22172 KB Output is correct
25 Correct 313 ms 22116 KB Output is correct
26 Correct 456 ms 22152 KB Output is correct
27 Correct 589 ms 23660 KB Output is correct
28 Correct 323 ms 22096 KB Output is correct
29 Correct 369 ms 21988 KB Output is correct
30 Correct 809 ms 57256 KB Output is correct
31 Correct 26 ms 13796 KB Output is correct
32 Correct 66 ms 48936 KB Output is correct