# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
850246 | elotelo966 | Portal (COCI17_portal) | C++17 | 13 ms | 11672 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define OYY 100000005
#define mod 100000007
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mid (start+end)/2
#define lim 505
int n,m,yol[lim][lim],xd[4]={0,0,1,-1},yd[4]={1,-1,0,0},vis[lim][lim];
char dizi[lim][lim];
vector<int> cev,as;
inline void dfs(int x,int y,int gel){
//cout<<x<<" "<<y<<" " <<gel<<endl;
if(x<0 || x>=n || y<0 || y>=m)return ;
if(vis[x][y])return ;
if(dizi[x][y]=='#')return ;
vis[x][y]=1;
yol[x][y]=gel;
int tut=0;
for(int i=gel;i<4;i++){
tut++;
dfs(x+xd[i],y+yd[i],i);
}
for(int i=0;i<4-tut;i++){
dfs(x+xd[i],y+yd[i],i);
}
}
int32_t main(){
faster
cin>>n>>m;
string deg;
int bx,by,ex,ey;
for(int i=0;i<n;i++){
cin>>deg;
for(int j=0;j<m;j++){
dizi[i][j]=deg[j];
if(dizi[i][j]=='C'){
bx=i,by=j;
}
else if(dizi[i][j]=='F'){
ex=i,ey=j;
}
}
}
dfs(bx,by,0);
if(vis[ex][ey]){
int i=ex,j=ey;
cev.push_back(yol[i][j]);
while(!(i==bx && j==by)){
if(yol[i][j]==0)j--;
else if(yol[i][j]==1)j++;
else if(yol[i][j]==2)i--;
else if(yol[i][j]==3)i++;
cev.push_back(yol[i][j]);
}
/*for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cout<<yol[i][j]<<" ";
}
cout<<endl;
}*/
as.push_back(cev[0]);
for(int i=1;i<cev.size();i++){
if(cev[i]!=as.back()){
as.push_back(cev[i]);
}
}
cout<<as.size()<<'\n';
}
else cout<<"nemoguce"<<'\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |