제출 #465724

#제출 시각아이디문제언어결과실행 시간메모리
465724MohamedFaresNebili포탈들 (BOI14_portals)C++14
0 / 100
1 ms204 KiB
#include <bits/stdc++.h> using namespace std; void solve() { /// JUST KEEP GOING const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; int n, m; cin>>n>>m; char grid[n][m]; int d[n][m]; int sx, sy; int ex, ey; for(int l=0;l<n;l++) { for(int i=0;i<m;i++) { cin>>grid[l][i]; d[l][i]=1000000000; if(grid[l][i]=='S') { sx=l; sy=i; d[sx][sy]=0; } else if(grid[l][i]=='C') { ex=l; ey=i; } } } queue<pair<int, int>>pq; pq.push({sx, sy}); while(!pq.empty()) { int a=pq.front().first, b=pq.front().second; pq.pop(); bool wall=false; for(int l=0;l<4;l++) { int x=a+nx[l], y=b+ny[l]; if(x>=0&&x<n&&y>=0&&y<m) { if(grid[x][y]=='#') { wall=true; continue; } if(d[x][y]>d[a][b]+1) { d[x][y]=d[a][b]+1; pq.push({x, y}); } } } int p=1000000000; vector<pair<int, int>>to; if(!wall) { for(int l=0;l<4;l++) { int x=a, y=b; int k=0; while(x>=0&&y>=0&&x<n&&y<m&&grid[x][y]!='#') { x+=nx[l], y+=ny[l]; k++; } x-=nx[l], y-=ny[l]; p=min(p, k); to.push_back({x, y}); } } else p=1; for(auto u:to) { int x=u.first, y=u.second; if(d[x][y]>d[a][b]+p) { d[x][y]=d[a][b]+p; pq.push({x, y}); } } } cout<<d[ex][ey]<<'\n'; } int32_t main() { int t; t=1; while(t--) { solve(); } return 0; }

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

portals.cpp: In function 'void solve()':
portals.cpp:53:22: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |     cout<<d[ex][ey]<<'\n';
      |                      ^~~~
portals.cpp:53:22: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
#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...