Submission #500995

#TimeUsernameProblemLanguageResultExecution timeMemory
500995kevinRobots (IOI13_robots)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define nl cout<<"\n"
#define f first
#define s second
#define ca(v) for(auto i:v) cout<<i<<" ";

int xm[4] = {-1, 1, 0, 0};
int ym[4] = {0, 0, -1, 1};

int grid[801][801];
int dst[801][801];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
    int n; cin>>n; int x; cin>>x;
    queue<pair<int, int>> q;
    pair<int, int> st;
    pair<int, int> ed;
    vector<vector<bool>> vis(n, vector<bool>(n, 0));
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            char c; cin>>c;
            grid[i][j] = (c != 'T');
            if(c == 'M') st = {i, j};
            if(c == 'D') ed = {i, j};
            if(c == 'H') {
                q.push({i, j});
                vis[i][j] = 1;
            }
        }
    }
    while(q.size()){
        auto c = q.front(); q.pop();
        for(int i=0; i<4; i++){
            int nx = c.f + xm[i];
            int ny = c.s + ym[i];
            if((nx != ed.f || ny != ed.s) && nx >= 0 && nx < n && ny >= 0 && ny < n && grid[nx][ny] && !vis[nx][ny]){
                vis[nx][ny] = 1;
                dst[nx][ny] = dst[c.f][c.s] + 1;
                q.push({nx, ny});
            }
        }
    }
    dst[ed.f][ed.s] = n*n + 5;
    int l = 0;
    int r = dst[st.f][st.s] - 1;
    int ans = -1;
    while(l <= r){
        int m = (l + r) / 2;
        vis = vector<vector<bool>>(n, vector<bool>(n, 0));
        vector<vector<int>> d(n, vector<int>(n, 0));
        vis[st.f][st.s] = 1;
        d[st.f][st.s] = m * x;
        q.push({st.f, st.s});
        // cout<<m<<"\n";
        while(q.size()){
            auto c = q.front(); q.pop();
            int mx = (d[c.f][c.s] + 1) / x;
            for(int i=0; i<4; i++){
                int nx = c.f + xm[i];
                int ny = c.s + ym[i];
                if(nx >= 0 && nx < n && ny >= 0 && ny < n && grid[nx][ny] && !vis[nx][ny] && mx <= dst[nx][ny]){
                    d[nx][ny] = d[c.f][c.s] + 1;
                    vis[nx][ny] = 1;
                    q.push({nx, ny});
                }
            }
        }
        // for(int i=0; i<n; i++){
        //     for(int j=0; j<n; j++){
        //         cout<<dst[i][j]<<"|"<<d[i][j]<<" ";
        //     } nl;
        // }
        if(vis[ed.f][ed.s]){
            l = m+1;
            ans = m;
        }
        else{
            r = m-1;
        }
        // nl;
    }
    cout<<ans;
}

Compilation message (stderr)

robots.cpp: In function 'int main()':
robots.cpp:19:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
      |                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccaXKaVx.o: in function `main':
robots.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccCl8Smx.o:grader.c:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccCl8Smx.o: in function `main':
grader.c:(.text.startup+0x1b1): undefined reference to `putaway'
collect2: error: ld returned 1 exit status