제출 #465730

#제출 시각아이디문제언어결과실행 시간메모리
465730AnasBenMoussa포탈들 (BOI14_portals)C++14
0 / 100
119 ms262148 KiB
#include <bits/stdc++.h> typedef double db ; using namespace std; #define all(x) begin(x), end(x) #define pb push_back #define int long long #define doub(k) printf("%.1lf\n", k) // setprecision(5) typedef pair<int ,int > pll;typedef map<int , int > mll;typedef vector<int > vll;typedef vector<pll>vpll; typedef set<int > sll; const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; const int dr[8] = {1,1,0,-1,-1,-1, 0, 1}, dc[8] = {0,1,1, 1, 0,-1,-1,-1}; //vector<char>v{'R','B','G'}; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// vector<vector<pair<int,int>>> path;int cyt;int cye; char grid[10000][100000];int x,y;pll star,en;int vis[10000][10000]; int solve(int n,int j){ //cout<<n<< " "<<j<<endl; if(n==en.first&&j==en.second){ return -1; } if(n<0||n>x||j<0||j>y){ return 1000; } if(grid[n][j]=='#'){ return 1000; } int ans=1000; for(int i=0;i<=y;i++){ if(grid[n][j+i]!='#'&&grid[n][j+i+1]=='#'){ if(n<=0||j+i<=0||n>x||j+i>y){ continue; } if(vis[n][j+i]){ continue; } //cout<<"HERE"<<endl; //cout<<n<<" "<<j+i<<" "<<"k"<<endl; vis[n][j+i]=1; ans=min(ans,solve(n,j+i))+1; vis[n][j+i]=0; } } for(int i=0;i<=y;i++){ if(grid[n][j-i]!='#'&&grid[n][j-i-1]=='#'){ if(n<=0||j-i<=0||n>x||j-i>y){ continue; } if(vis[n][j-i]){ continue; } vis[n][j-i]=1; ans=min(ans,solve(n,j-i))+1; vis[n][j-i]=0; } } for(int i=0;i<=n;i++){ if(grid[n+i][j]!='#'&&grid[n+i+1][j]=='#'){ if(n+i<=0||j<=0||n+i>x||j>y){ continue; } if(vis[n+i][j]){ continue; } vis[n+i][j]=1; ans=min(ans,solve(n+i,j))+1; vis[n+i][j]=0; } } for(int i=0;i<=n;i++){ if(grid[n-i][j]!='#'&&grid[n-i-1][j]=='#'){ if(n-i<=0||j<=0||n-i>x||j>y){ continue; } if(vis[n-i][j]){ continue; } vis[n-i][j]=1; ans=min(ans,solve(n-i,j))+1; vis[n-i][j]=0; } } for(int r=0;r<4;r++){ if(n+nx[r]<=0||n+nx[r]>x||j+ny[r]<=0||j+ny[r]>y){ continue; } if(vis[n+nx[r]][j+ny[r]]){ continue; } vis[n+nx[r]][j+ny[r]]=1; ans=min(ans,solve(n+nx[r],j+ny[r]))+1; vis[n+nx[r]][j+ny[r]]=0; } //cout<<n<<" "<<j<<endl; //cout<<ans<<endl; return ans; } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(NULL); cin>>x; cin>>y; memset(grid,'#',sizeof(grid)); for(int i=1;i<=x;i++){ for(int j=1;j<=y;j++){ char t;cin>>t; if(t=='S'){ star={i,j}; } if(t=='C'){ en={i,j}; } grid[i][j]=t; } } //cout<<grid[x][1]<<endl; cout<<solve(star.first,star.second)<<endl; return 0; }
#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...