# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
28558 | ㅁㄴㅇㄹ (#68) | Oriental P.A.D.A.K (FXCUP2_padak) | C++14 | 96 ms | 65536 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
int *tmp;
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]});
}
}
tmp = (int*)malloc(sizeof(int)*(N*M+1));
for(int i=1; i<=N; i++) for(int j=1; j<=M; j++) tmp[(i-1)*M+j] = a[i][j];
sort(tmp+1,tmp+N*M+1);
int it,cnt;
cnt = 0; it = 1;
while(it <= N*M){
while(it <= N*M && tmp[it] <= cnt) it++;
for(int i=1; i<=Z && it <= N*M; i++){
it++;
ans2++;
}
cnt++;
}
reverse(tmp+1,tmp+N*M+1);
cnt = 0; it = 1;
while(it <= N*M){
for(int i=1; i<=Z && it <= N*M; i++){
if(tmp[it] > cnt) ans1++;
it++;
}
cnt++;
}
printf("%d %d\n",ans1,ans2);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |