답안 #850259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850259 2023-09-16T08:43:12 Z elotelo966 Portal (COCI17_portal) C++17
0 / 120
13 ms 11608 KB
#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

portal.cpp: In function 'int32_t main()':
portal.cpp:65:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int i=1;i<cev.size();i++){
      |                     ~^~~~~~~~~~~
portal.cpp:51:27: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |         while(!(i==bx && j==by)){
      |                          ~^~~~
portal.cpp:51:18: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |         while(!(i==bx && j==by)){
      |                 ~^~~~
portal.cpp:16:16: warning: 'by' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |     if(vis[x][y])return ;
      |        ~~~~~~~~^
portal.cpp:34:12: note: 'by' was declared here
   34 |     int bx,by,ex,ey;
      |            ^~
portal.cpp:15:20: warning: 'bx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   15 |     if(x<0 || x>=n || y<0 || y>=m)return ;
      |        ~~~~~~~~~~~~^~~~~~
portal.cpp:34:9: note: 'bx' was declared here
   34 |     int bx,by,ex,ey;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 8668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 9048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 11608 KB Output isn't correct
2 Halted 0 ms 0 KB -