제출 #751270

#제출 시각아이디문제언어결과실행 시간메모리
751270irmuun포탈들 (BOI14_portals)C++17
0 / 100
1 ms444 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define ff first #define ss second #define all(s) s.begin(),s.end() int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int r,c; cin>>r>>c; string s[r]; vector<pair<int,int>>adj[r][c]; int sx,sy,cx,cy; for(int i=0;i<r;i++){ cin>>s[i]; vector<int>v; v.pb(-1); for(int j=0;j<c;j++){ if(s[i][j]=='S'){ sx=i; sy=j; } if(s[i][j]=='C'){ cx=i; cy=j; } if(s[i][j]=='#'){ v.pb(j); } } v.pb(r); for(int j=0;j<v.size()-1;j++){ if(v[j]+1!=v[j+1]){ adj[i][v[j]+1].pb({i,v[j+1]-1}); adj[i][v[j+1]-1].pb({i,v[j]+1}); } } } for(int j=0;j<c;j++){ vector<int>v; v.pb(-1); for(int i=0;i<r;i++){ if(s[i][j]=='#'){ v.pb(i); } } v.pb(r); for(int i=0;i<v.size()-1;i++){ if(v[i]+1!=v[i+1]){ adj[v[i]+1][j].pb({v[i+1]-1,j}); adj[v[i+1]-1][j].pb({v[i]+1,j}); } } } vector<int>dx={1,-1,0,0}; vector<int>dy={0,0,1,-1}; for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ for(int k=0;k<4;k++){ int x=i+dx[k],y=j+dy[k]; if(x<0||x>=r||y<0||y>=c||s[x][y]=='#') continue; adj[i][j].pb({x,y}); } } } int dist[r][c]; memset(dist,-1,sizeof(dist)); queue<pair<int,int>>q; q.push({sx,sy}); dist[sx][sy]=0; while(!q.empty()){ int x=q.front().ff,y=q.front().ss; q.pop(); for(auto [i,j]:adj[x][y]){ if(dist[i][j]==-1){ dist[i][j]=dist[x][y]+1; q.push({i,j}); } } } cout<<dist[cx][cy]; }

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

portals.cpp: In function 'int main()':
portals.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int j=0;j<v.size()-1;j++){
      |                     ~^~~~~~~~~~~
portals.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int i=0;i<v.size()-1;i++){
      |                     ~^~~~~~~~~~~
portals.cpp:74:17: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   74 |     dist[sx][sy]=0;
      |     ~~~~~~~~~~~~^~
portals.cpp:74:17: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
portals.cpp:85:22: warning: 'cy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   85 |     cout<<dist[cx][cy];
      |                      ^
portals.cpp:85:22: warning: 'cx' 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...