Submission #751272

# Submission time Handle Problem Language Result Execution time Memory
751272 2023-05-31T10:28:48 Z irmuun Portals (BOI14_portals) C++17
Compilation error
0 ms 0 KB
v#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+5];
    vector<pair<int,int>>adj[r+5][c+5];
    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++){
            if(s[i][j]=='#') continue;
            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+5][c+5];
    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];
}

Compilation message

portals.cpp:1:2: error: stray '#' in program
    1 | v#include<bits/stdc++.h>
      |  ^
portals.cpp:1:1: error: 'v' does not name a type
    1 | v#include<bits/stdc++.h>
      | ^
portals.cpp: In function 'int main()':
portals.cpp:12:5: error: 'ios_base' has not been declared
   12 |     ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
      |     ^~~~~~~~
portals.cpp:12:39: error: 'cin' was not declared in this scope
   12 |     ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
      |                                       ^~~
portals.cpp:12:51: error: 'cout' was not declared in this scope
   12 |     ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
      |                                                   ^~~~
portals.cpp:15:5: error: 'string' was not declared in this scope
   15 |     string s[r+5];
      |     ^~~~~~
portals.cpp:16:5: error: 'vector' was not declared in this scope
   16 |     vector<pair<int,int>>adj[r+5][c+5];
      |     ^~~~~~
portals.cpp:16:12: error: 'pair' was not declared in this scope
   16 |     vector<pair<int,int>>adj[r+5][c+5];
      |            ^~~~
portals.cpp:16:17: error: expected primary-expression before 'int'
   16 |     vector<pair<int,int>>adj[r+5][c+5];
      |                 ^~~
portals.cpp:19:14: error: 's' was not declared in this scope
   19 |         cin>>s[i];
      |              ^
portals.cpp:20:16: error: expected primary-expression before 'int'
   20 |         vector<int>v;
      |                ^~~
portals.cpp:21:9: error: 'v' was not declared in this scope
   21 |         v.pb(-1);
      |         ^
portals.cpp:38:17: error: 'adj' was not declared in this scope
   38 |                 adj[i][v[j]+1].pb({i,v[j+1]-1});
      |                 ^~~
portals.cpp:44:16: error: expected primary-expression before 'int'
   44 |         vector<int>v;
      |                ^~~
portals.cpp:45:9: error: 'v' was not declared in this scope
   45 |         v.pb(-1);
      |         ^
portals.cpp:47:16: error: 's' was not declared in this scope
   47 |             if(s[i][j]=='#'){
      |                ^
portals.cpp:54:17: error: 'adj' was not declared in this scope
   54 |                 adj[v[i]+1][j].pb({v[i+1]-1,j});
      |                 ^~~
portals.cpp:59:12: error: expected primary-expression before 'int'
   59 |     vector<int>dx={1,-1,0,0};
      |            ^~~
portals.cpp:60:12: error: expected primary-expression before 'int'
   60 |     vector<int>dy={0,0,1,-1};
      |            ^~~
portals.cpp:63:16: error: 's' was not declared in this scope
   63 |             if(s[i][j]=='#') continue;
      |                ^
portals.cpp:65:25: error: 'dx' was not declared in this scope; did you mean 'x'?
   65 |                 int x=i+dx[k],y=j+dy[k];
      |                         ^~
      |                         x
portals.cpp:66:31: error: 'y' was not declared in this scope
   66 |                 if(x<0||x>=r||y<0||y>=c||s[x][y]=='#') continue;
      |                               ^
portals.cpp:66:42: error: 's' was not declared in this scope
   66 |                 if(x<0||x>=r||y<0||y>=c||s[x][y]=='#') continue;
      |                                          ^
portals.cpp:67:17: error: 'adj' was not declared in this scope
   67 |                 adj[i][j].pb({x,y});
      |                 ^~~
portals.cpp:67:33: error: 'y' was not declared in this scope
   67 |                 adj[i][j].pb({x,y});
      |                                 ^
portals.cpp:72:5: error: 'memset' was not declared in this scope
   72 |     memset(dist,-1,sizeof(dist));
      |     ^~~~~~
portals.cpp:1:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
  +++ |+#include <cstring>
    1 | v#include<bits/stdc++.h>
portals.cpp:73:5: error: 'queue' was not declared in this scope
   73 |     queue<pair<int,int>>q;
      |     ^~~~~
portals.cpp:73:16: error: expected primary-expression before 'int'
   73 |     queue<pair<int,int>>q;
      |                ^~~
portals.cpp:74:5: error: 'q' was not declared in this scope
   74 |     q.push({sx,sy});
      |     ^
portals.cpp:79:24: error: 'adj' was not declared in this scope
   79 |         for(auto [i,j]:adj[x][y]){
      |                        ^~~
portals.cpp:79:31: error: 'y' was not declared in this scope
   79 |         for(auto [i,j]:adj[x][y]){
      |                               ^