# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
312058 | colazcy | Clickbait (COCI18_clickbait) | C++17 | 32 ms | 33656 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <cctype>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 1024;
char mp[maxn][maxn];
int n,m,tot,ans[maxn * maxn],id[maxn][maxn],vis[maxn][maxn],deltax[] = {-1,1,0,0},deltay[] = {0,0,-1,1};
inline bool chk(int x,int y){
return x >= 1 && x <= n && y >= 1 && y <= m;
}
struct point{int x,y;};
inline void bfs(point s,int col){
queue<point> q;
q.push(s);vis[s.x][s.y] = 1;
while(!q.empty()){
point now = q.front();q.pop();
id[now.x][now.y] = col;
for(int i = 0;i < 4;i++){
int nx = now.x + deltax[i],ny = now.y + deltay[i];
if(!chk(nx,ny) || vis[nx][ny])continue;
if(mp[nx][ny] == '.' || isdigit(mp[nx][ny]))q.push(point{nx,ny}),vis[nx][ny] = 1;
else id[nx][ny] = col,vis[nx][ny] = 1;
}
}
}
inline int find(point now){
while(!id[now.x][now.y]){
vis[now.x][now.y] = 1;
if(mp[now.x][now.y] == '-'){
if(!vis[now.x][now.y - 1])now.y--;
else if(!vis[now.x][now.y + 1])now.y++;
}else if(mp[now.x][now.y] == '|')now.x++;
else if(mp[now.x][now.y] == '+'){
for(int i = 0;i < 4;i++){
int nx = now.x + deltax[i],ny = now.y + deltay[i];
if(chk(nx,ny) && !vis[nx][ny] && mp[nx][ny] != '.'){
now.x = nx,now.y = ny;
break;
}
}
}
}
return id[now.x][now.y];
}
struct edge{
int v,d;
bool operator < (const edge &rhs)const{
return d > rhs.d;
}
};
vector<edge> G[maxn * maxn];
inline void addedge(int u,int v,int d){
G[u].push_back(edge{v,d});
}
inline void dfs(int u){
for(int i = 0;i < G[u].size();i++){
int v = G[u][i].v;
dfs(v);
}
ans[++tot] = u;
}
int main(){
// freopen("clickbait.in","r",stdin);
// freopen("clickbait.out","w",stdout);
scanf("%d %d",&n,&m);
for(int i = 1;i <= n;i++)scanf("%s",mp[i] + 1);
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)
if(isdigit(mp[i][j])){
int now = 0;
for(int k = j;isdigit(mp[i][k]);j = k,k++)now = now * 10 + mp[i][k] - '0';
bfs(point{i,j},now);
}
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)
if(mp[i][j] == '|')
if(mp[i][j - 1] == '-')addedge(id[i][j],find(point{i,j - 1}),i);
else if(mp[i][j + 1] == '-')addedge(id[i][j],find(point{i,j + 1}),i);
for(int i = 1;i < maxn;i++)
if(G[i].size() > 1)sort(G[i].begin(),G[i].end());
dfs(1);
for(int i = 1;i <= tot;i++)printf("%d\n",ans[i]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |