제출 #494041

#제출 시각아이디문제언어결과실행 시간메모리
494041goodluck2020포탈들 (BOI14_portals)C++14
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> #define task "portals" using namespace std; const int N = 1e3 + 5; int n, m, A[N][N]; struct Data { int x, y; } S, C, D; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; namespace sub4 { queue < Data > Q; int Visited[N][N], dist[N][N]; void Go(int x, int y) { Q.push({x, y}); Visited[x][y] = 1; dist[x][y] = dist[D.x][D.y] + 1; } void solve() { Q.push(S); Visited[S.x][S.y] = 1; while(!Q.empty()) { D = Q.front(); Q.pop(); bool ok = 1; for(int i = 0; i < 4; i++) { int x = D.x + dx[i]; int y = D.y + dy[i]; if(A[x][y] && !Visited[x][y]) Go(x, y); ok &= A[x][y]; } if(!ok) { int x, y; x = D.x; y = D.y; while(A[x][y]) { if(A[x-1][y] && !Visited[x][y]) Go(x, y); x--; } x = D.x; y = D.y; while(A[x][y]) { if(A[x+1][y] && !Visited[x][y]) Go(x, y); x++; } x = D.x; y = D.y; while(A[x][y]) { if(A[x][y - 1] && !Visited[x][y]) Go(x, y); y--; } x = D.x; y = D.y; while(A[x][y]) { if(A[x][y + 1] && !Visited[x][y]) Go(x, y); y++; } } } cout << dist[C.x][C.y]; } } int main() { if(fopen(task ".inp","r")) { freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) { char ch; cin >> ch; if(ch == 'S') S = {i, j}; if(ch == 'C') C = {i, j}; if(ch != '#') A[i][j] = 1; } if(n <= 200 && m <= 200) sub4::solve(); }

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

portals.cpp: In function 'int main()':
portals.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
portals.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...