Submission #28550

# Submission time Handle Problem Language Result Execution time Memory
28550 2017-07-16T07:14:53 Z ㅁㄴㅇㄹ(#1150, TAMREF, Diuven, suhgyuho_william) Oriental P.A.D.A.K (FXCUP2_padak) C++14
0 / 1
383 ms 65536 KB
#include <bits/stdc++.h>
#include <unistd.h>

#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define lld long long
#define Inf 1000000000
#define get gett

using namespace std;

int N,M,K,B,Z;
int ans1,ans2;
int **a;
bool **check;
queue<pii> q;
priority_queue<int> q1;
priority_queue<int,vector<int>,greater<int>> q2;
int dx[] = {0,1,0,-1},dy[] = {1,0,-1,0};

int main(){
	scanf("%d %d %d %d %d",&N,&M,&K,&B,&Z);
	a = (int**)malloc(sizeof(int*)*(N+2));
	check = (bool**)malloc(sizeof(bool*)*(N+2));
	for(int i=0; i<=N+1; i++){
		a[i] = (int*)malloc(sizeof(int)*(M+2));
		check[i] = (bool*)malloc(sizeof(bool)*(M+2));
	}
	for(int i=1; i<=K; i++){
		int x,y;
		scanf("%d %d",&x,&y);
		check[x][y] = true;
		q.push({x,y});
	}
	while(!q.empty()){
		int x,y;
		x = q.front().first;
		y = q.front().second;
		q.pop();
		for(int i=0; i<4; i++){
			if(x+dx[i] < 1 || x+dx[i] > N || y+dy[i] < 1 || y+dy[i] > M) continue;
			if(check[x+dx[i]][y+dy[i]]) continue;
			check[x+dx[i]][y+dy[i]] = true;
			a[x+dx[i]][y+dy[i]] = a[x][y]+1;
			q.push({x+dx[i],y+dy[i]});
		}
	}
	for(int i=1; i<=N; i++) for(int j=1; j<=M; j++){
		q1.push(a[i][j]);
		q2.push(a[i][j]);
	}
	int cnt;
	cnt = 0;
	while(!q1.empty()){
		for(int i=1; i<=Z && !q1.empty(); i++){
			if(q1.top() > cnt) ans1++;
			q1.pop();
		}
		cnt++;
	}
	cnt = 0;
	while(!q2.empty()){
		while(!q2.empty() && q2.top() <= cnt) q2.pop();
		for(int i=1; i<=Z && !q2.empty(); i++){
			ans2++;
			q2.pop();
		}
		cnt++;
	}
	printf("%d %d\n",ans1,ans2);

	return 0;
}

Compilation message

padak.cpp: In function 'int main()':
padak.cpp:23:40: 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:32:23: 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 2024 KB Output is correct
2 Correct 0 ms 2168 KB Output is correct
3 Correct 346 ms 17312 KB Output is correct
4 Correct 359 ms 17300 KB Output is correct
5 Correct 383 ms 17288 KB Output is correct
6 Correct 326 ms 23360 KB Output is correct
7 Correct 376 ms 17628 KB Output is correct
8 Correct 253 ms 27080 KB Output is correct
9 Memory limit exceeded 149 ms 65536 KB Memory limit exceeded
10 Halted 0 ms 0 KB -