Submission #1260836

#TimeUsernameProblemLanguageResultExecution timeMemory
1260836_unknown_2010Mecho (IOI09_mecho)C++20
Compilation error
0 ms0 KiB
// ... (sarlavha va includes o'zi kabi)
void solution() {
    int n,s;
    cin >> n >> s;
    vi<string> a(n);
    const int INF = 1e9;
    vi<vi<int>> dist(n, vi<int> (n, INF));
    queue<pair<int,int>> q;
    int sx=-1, sy=-1, ex=-1, ey=-1;
    for(int i=0; i<n; i++){
        cin >> a[i];
        for(int j=0; j<n; j++){
            if(a[i][j]=='H'){
                dist[i][j]=0;
                q.push({i, j});
            }
            if(a[i][j]=='M'){
                sx=i; sy=j;
            }
            if(a[i][j]=='D'){
                ex=i; ey=j;
            }
        }
    }
    auto isvalid = [&](int nx, int ny) -> bool {
        if(nx<0 || ny<0) return false;
        if(nx>=n || ny>=n) return false;
        if(a[nx][ny]!='G' && a[nx][ny]!='M') return false;
        return true;
    };
    while(!q.empty()){
        auto [x,y]=q.front(); q.pop();
        for(int i=0;i<4;i++){
            int nx=x+dx[i], ny=y+dy[i];
            if(isvalid(nx, ny) && dist[nx][ny]==INF){
                dist[nx][ny]=dist[x][y]+1;
                q.push({nx, ny});
            }
        }
    }

    int l=-1, r=n*n;
    while(l<r){
        int mid=(l+r+1)/2;
        queue<pair<int,int>> qq;
        bool ok = false;
        // if bees already at start at or before mid -> impossible
        if (dist[sx][sy] <= mid) {
            ok = false;
        } else {
            qq.push({sx, sy});
            vi<vi<char>> vis(n, vi<char>(n,0));
            vi<vi<int>> mt(n, vi<int>(n,0));
            vis[sx][sy]=1; mt[sx][sy]=0;
            while(!qq.empty() && !ok){
                auto [x,y]=qq.front(); qq.pop();
                for(int i=0;i<4;i++){
                    int nx=x+dx[i], ny=y+dy[i];
                    // if stepping straight into home
                    if(nx==ex && ny==ey){
                        int needed = (mt[x][y] + 1 + s - 1) / s;
                        if (dist[ex][ey] > mid + needed) { ok = true; break; }
                        else continue;
                    }
                    if(!isvalid(nx, ny)) continue;
                    if(vis[nx][ny]) continue;
                    int needed = (mt[x][y] + 1 + s - 1) / s;
                    if(dist[nx][ny] > mid + needed){
                        vis[nx][ny]=1;
                        mt[nx][ny]=mt[x][y]+1;
                        qq.push({nx, ny});
                    }
                }
            }
        }
        if(ok) l = mid;
        else r = mid-1;
    }
    cout << l << '\n';
}

Compilation message (stderr)

mecho.cpp: In function 'void solution()':
mecho.cpp:4:5: error: 'cin' was not declared in this scope
    4 |     cin >> n >> s;
      |     ^~~
mecho.cpp:5:8: error: 'string' was not declared in this scope
    5 |     vi<string> a(n);
      |        ^~~~~~
mecho.cpp:5:5: error: 'vi' was not declared in this scope
    5 |     vi<string> a(n);
      |     ^~
mecho.cpp:5:16: error: 'a' was not declared in this scope
    5 |     vi<string> a(n);
      |                ^
mecho.cpp:7:11: error: expected primary-expression before 'int'
    7 |     vi<vi<int>> dist(n, vi<int> (n, INF));
      |           ^~~
mecho.cpp:8:11: error: 'pair' was not declared in this scope
    8 |     queue<pair<int,int>> q;
      |           ^~~~
mecho.cpp:8:5: error: 'queue' was not declared in this scope
    8 |     queue<pair<int,int>> q;
      |     ^~~~~
mecho.cpp:8:16: error: expected primary-expression before 'int'
    8 |     queue<pair<int,int>> q;
      |                ^~~
mecho.cpp:14:17: error: 'dist' was not declared in this scope
   14 |                 dist[i][j]=0;
      |                 ^~~~
mecho.cpp:15:17: error: 'q' was not declared in this scope
   15 |                 q.push({i, j});
      |                 ^
mecho.cpp:31:12: error: 'q' was not declared in this scope
   31 |     while(!q.empty()){
      |            ^
mecho.cpp:34:22: error: 'dx' was not declared in this scope; did you mean 'nx'?
   34 |             int nx=x+dx[i], ny=y+dy[i];
      |                      ^~
      |                      nx
mecho.cpp:35:28: error: 'ny' was not declared in this scope; did you mean 'nx'?
   35 |             if(isvalid(nx, ny) && dist[nx][ny]==INF){
      |                            ^~
      |                            nx
mecho.cpp:35:35: error: 'dist' was not declared in this scope
   35 |             if(isvalid(nx, ny) && dist[nx][ny]==INF){
      |                                   ^~~~
mecho.cpp:45:20: error: expected primary-expression before 'int'
   45 |         queue<pair<int,int>> qq;
      |                    ^~~
mecho.cpp:48:13: error: 'dist' was not declared in this scope
   48 |         if (dist[sx][sy] <= mid) {
      |             ^~~~
mecho.cpp:51:13: error: 'qq' was not declared in this scope
   51 |             qq.push({sx, sy});
      |             ^~
mecho.cpp:52:19: error: expected primary-expression before 'char'
   52 |             vi<vi<char>> vis(n, vi<char>(n,0));
      |                   ^~~~
mecho.cpp:53:19: error: expected primary-expression before 'int'
   53 |             vi<vi<int>> mt(n, vi<int>(n,0));
      |                   ^~~
mecho.cpp:54:13: error: 'vis' was not declared in this scope
   54 |             vis[sx][sy]=1; mt[sx][sy]=0;
      |             ^~~
mecho.cpp:54:28: error: 'mt' was not declared in this scope
   54 |             vis[sx][sy]=1; mt[sx][sy]=0;
      |                            ^~
mecho.cpp:58:30: error: 'dx' was not declared in this scope; did you mean 'nx'?
   58 |                     int nx=x+dx[i], ny=y+dy[i];
      |                              ^~
      |                              nx
mecho.cpp:60:34: error: 'ny' was not declared in this scope; did you mean 'nx'?
   60 |                     if(nx==ex && ny==ey){
      |                                  ^~
      |                                  nx
mecho.cpp:65:37: error: 'ny' was not declared in this scope; did you mean 'nx'?
   65 |                     if(!isvalid(nx, ny)) continue;
      |                                     ^~
      |                                     nx
mecho.cpp:66:32: error: 'ny' was not declared in this scope; did you mean 'nx'?
   66 |                     if(vis[nx][ny]) continue;
      |                                ^~
      |                                nx
mecho.cpp:68:33: error: 'ny' was not declared in this scope; did you mean 'nx'?
   68 |                     if(dist[nx][ny] > mid + needed){
      |                                 ^~
      |                                 nx
mecho.cpp:79:5: error: 'cout' was not declared in this scope
   79 |     cout << l << '\n';
      |     ^~~~