# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
152344 | arnold518 | 문명 (KOI17_civilization) | C++14 | 824 ms | 43068 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2000;
const int INF = 2e9;
const int dy[]={-1, 1, 0, 0};
const int dx[]={0, 0, -1, 1};
int N, K;
int A[MAXN+10][MAXN+10];
bool vis[MAXN+10][MAXN+10];
int par[MAXN*MAXN+10];
int f(int y, int x) { y--; x--; return y*N+x; }
int Find(int x) { return x==par[x]?x:(par[x]=Find(par[x])); }
int main()
{
int i, j;
scanf("%d%d", &N, &K);
for(i=0; i<N*N; i++) par[i]=i;
for(i=1; i<=N; i++) for(j=1; j<=N; j++) A[i][j]=INF;
queue<pii> Q;
for(i=1; i<=K; i++)
{
int y, x;
scanf("%d%d", &y, &x);
A[y][x]=0; Q.push({y, x});
}
K=0;
int ans=0;
for(ans=0; ; ans++)
{
int sz=Q.size();
while(sz--)
{
pii now=Q.front(); Q.pop();
vis[now.first][now.second]=1; K++;
for(i=0; i<4; i++)
{
pii nxt={now.first+dy[i], now.second+dx[i]};
if(!(1<=nxt.first && nxt.first<=N && 1<=nxt.second && nxt.second<=N)) continue;
if(vis[nxt.first][nxt.second])
{
int a=Find(f(now.first, now.second)), b=Find(f(nxt.first, nxt.second));
if(a!=b) K--;
par[a]=b;
}
else if(A[nxt.first][nxt.second]==INF)
{
A[nxt.first][nxt.second]=A[now.first][now.second]+1;
Q.push(nxt);
}
}
}
if(K==1) return !printf("%d", ans);
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |