제출 #581294

#제출 시각아이디문제언어결과실행 시간메모리
581294qwerasdfzxcl로봇 (APIO13_robots)C++14
60 / 100
1565 ms96828 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; struct Vertex{ int x, y, d; Vertex(){} Vertex(int _x, int _y, int _d): x(_x), y(_y), d(_d) {} bool operator<(const Vertex &V) const{ return d > V.d; } }to[505][505][4]; char a[505][505]; bool visited[505][505][4]; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}, n, w, h; int dist[9][9][505][505]; void dfs(int x, int y, int d){ visited[x][y][d] = 1; int nx, ny, nd = d; if (a[x][y]=='A') nd = (d+3)%4; if (a[x][y]=='C') nd = (d+1)%4; nx = x + dx[nd], ny = y + dy[nd]; if (a[nx][ny]=='x') to[x][y][d] = Vertex(x, y, d); else if (visited[nx][ny][nd]) to[x][y][d] = to[nx][ny][nd]; else{ dfs(nx, ny, nd); to[x][y][d] = to[nx][ny][nd]; } } void init(){ for (int i=0;i<=h+1;i++) fill(a[i], a[i]+w+2, 'x'); for (int i=1;i<=h;i++){ scanf("%s", a[i]+1); a[i][w+1] = 'x'; } for (int i=1;i<=h;i++){ for (int j=1;j<=w;j++){ for (int d=0;d<4;d++) if (!visited[i][j][d]) dfs(i, j, d); } } for (int t=0;t<81;t++){ for (int i=1;i<=h;i++){ for (int j=1;j<=w;j++){ dist[t/9][t%9][i][j] = 1e9; } } } //printf("%d %d %d\n", to[1][1][0].x, to[1][1][0].y, to[1][1][0].d); } void bfs(int l, int r){ //printf(" %d %d\n", l, r); priority_queue<Vertex> pq; for (int i=1;i<=h;i++){ for (int j=1;j<=w;j++){ if (l==r&& a[i][j]=='1'+l) dist[l][r][i][j] = 0; if (dist[l][r][i][j]<1e9) pq.emplace(i, j, dist[l][r][i][j]); } } while(!pq.empty()){ auto [x, y, dd] = pq.top(); pq.pop(); if (dd!=dist[l][r][x][y]) continue; //if (t==21 && dist[l][r][x][y]==2) printf("YES %d %d\n", x, y); for (int i=0;i<l;i++){ dist[i][r][x][y] = min(dist[i][r][x][y], dist[i][l-1][x][y] + dist[l][r][x][y]); } for (int i=r+1;i<n;i++){ dist[l][i][x][y] = min(dist[l][i][x][y], dist[l][r][x][y] + dist[r+1][i][x][y]); } for (int d=0;d<4;d++){ int nx = to[x][y][d].x, ny = to[x][y][d].y; if (!nx) continue; if (dist[l][r][nx][ny] <= dist[l][r][x][y] + 1) continue; dist[l][r][nx][ny] = dist[l][r][x][y] + 1; pq.emplace(nx, ny, dist[l][r][nx][ny]); } } } int main(){ scanf("%d %d %d", &n, &w, &h); init(); for (int d=0;d<n;d++){ for (int i=0;i<n-d;i++){ int j = i+d; bfs(i, j); } } int ans = 1e9; for (int i=1;i<=h;i++){ for (int j=1;j<=w;j++){ //if (dist[0][i][j]==0 && dist[1][i][j]==0) printf("%d %d\n", i, j); //if (dist[3][3][i][j]!=1e9)printf("%d ", dist[3][3][i][j]); //else printf("x "); ans = min(ans, dist[0][n-1][i][j]); } //printf("\n"); } printf("%d\n", ans==1e9?-1:ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

robots.cpp: In function 'void bfs(int, int)':
robots.cpp:75:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   75 |         auto [x, y, dd] = pq.top(); pq.pop();
      |              ^
robots.cpp: In function 'void init()':
robots.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%s", a[i]+1);
      |         ~~~~~^~~~~~~~~~~~~~
robots.cpp: In function 'int main()':
robots.cpp:99:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |     scanf("%d %d %d", &n, &w, &h);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...