Submission #948510

#TimeUsernameProblemLanguageResultExecution timeMemory
948510Darren0724Portals (BOI14_portals)C++17
20 / 100
13 ms8796 KiB
#include <bits/stdc++.h> using namespace std; #define LCBorz ios_base::sync_with_stdio(false); cin.tie(0); //#define int long long #define all(x) x.begin(), x.end() #define endl '\n' const int N=505; const int INF=1e9; int32_t main() { LCBorz; int n,m;cin>>n>>m; vector<vector<char>> v(n+2,vector<char>(m+2,'#')); auto id=[&](int a,int b){ return a*N+b; }; auto valid=[&](int a,int b){ return v[a][b]!='#'; }; auto rev=[&](int id){ return make_pair(id/N,id%N); }; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>v[i][j]; } } vector<int> adj[N*N]; for(int i=1;i<=n;i++){ int last=0; for(int j=1;j<=m;j++){ if(!valid(i,j)){ last=j; continue; } adj[id(i,j)].push_back(id(i,last+1)); } last=m+1; for(int j=m;j>=1;j--){ if(!valid(i,j)){ last=j; continue; } adj[id(i,j)].push_back(id(i,last-1)); } } for(int i=1;i<=m;i++){ int last=0; for(int j=1;j<=n;j++){ if(!valid(j,i)){ last=j; continue; } adj[id(j,i)].push_back(id(last+1,i)); } last=n+1; for(int j=n;j>=1;j--){ if(!valid(j,i)){ last=j; continue; } adj[id(j,i)].push_back(id(last-1,i)); } } vector<int> dx={0,0,-1,1},dy={1,-1,0,0}; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(!valid(i,j))continue; for(int k=0;k<4;k++){ int a=i+dx[k],b=j+dy[k]; if(!valid(a,b))continue; adj[id(i,j)].push_back(id(a,b)); } } } queue<int> q; vector<int> dis(N*N,INF); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(v[i][j]=='S'){ q.push(id(i,j)); dis[id(i,j)]=0; } } } while(q.size()){ int p=q.front(); q.pop(); for(int j:adj[p]){ if(dis[j]==INF){ dis[j]=dis[p]+1; q.push(j); } } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(v[i][j]=='C'){ cout<<dis[id(i,j)]<<endl; } } } return 0; }

Compilation message (stderr)

portals.cpp: In function 'int32_t main()':
portals.cpp:20:10: warning: variable 'rev' set but not used [-Wunused-but-set-variable]
   20 |     auto rev=[&](int id){
      |          ^~~
#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...