Submission #1100750

# Submission time Handle Problem Language Result Execution time Memory
1100750 2024-10-14T15:22:30 Z Uniq0rn Mecho (IOI09_mecho) C++14
4 / 100
199 ms 6548 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ld long double 
#define ll long long int
#define pi pair<int,int>
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
 
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n,s;cin >> n >> s;
    vector<vector<char>> a(n + 1,vector<char>(n + 1));
    queue<pair<int,int>> qu;
    vector<vector<int>> bdist(n + 1,vector<int>(n + 1));
    vector<vector<bool>> bvis(n + 1,vector<bool>(n + 1));
    int si = -1,sj = -1,ei = -1,ej = -1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin >> a[i][j];
            if(a[i][j] == 'H'){
                bvis[i][j] = true;
                qu.push({i,j});
            }
            if(a[i][j] == 'M'){
                si = i;
                sj = j;
            }
            if(a[i][j] == 'D'){
                ei = i;
                ej = j;
            }
        }
    }
    while(sz(qu)){
        int ni = qu.front().first,nj = qu.front().second;
        //cout << ni << ' ' << nj << '\n';
        qu.pop();
        for(int i=-1;i<=1;i++) for(int j=-1;j<=1;j++){
            if(abs(i) == abs(j)) continue;
            int ii = ni + i,jj = nj + j;
            if(ii < 1 || ii > n || jj < 1 || jj > n) continue;
            if(bvis[ii][jj] || a[ii][jj] == 'T' || a[ii][jj] == 'D') continue;
            bvis[ii][jj] = true;
            bdist[ii][jj] = bdist[ni][nj] + 1;
            qu.push({ii,jj});
        }
    }
    /*
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cout << (bdist[i][j] == 1e9 ? -1 : bdist[i][j]) << ' ';
        }
        cout << '\n';
    }
    cout << "---------------------------------------------\n";
    */
    int ans = -1;
    int l = 0,r = n * n;
    while(l <= r){
        int mid = (l + r) >> 1;
        //cout << mid << '\n';
        vector<vector<int>> dist(n + 1,vector<int>(n + 1));
        vector<vector<bool>> vis(n + 1,vector<bool>(n + 1));
        queue<pair<int,int>> q;
        q.push({si,sj});
        vis[si][sj] = true;
        bool ok = false;
        while(sz(q)){
            int ni = q.front().first,nj = q.front().second;
            q.pop();
            if(a[ni][nj] == 'D'){
                ok = true;
                break;
            }
            for(int i=-1;i<=1;i++) for(int j=-1;j<=1;j++){
                if(abs(i) == abs(j)) continue;
                int ii = ni + i,jj = nj + j;
                if(ii < 1 || ii > n || jj < 1 || jj > n) continue;
                if(vis[ii][jj]) continue;
                if(a[ii][jj] == 'T' || a[ii][jj] == 'H') continue;
                if(bdist[ii][jj] <= mid + (dist[ni][nj] + 1) / s) continue;
                vis[ii][jj] = true;
                dist[ii][jj] = dist[ni][nj] + 1;
                q.push({ii,jj});
            }
        }
        /*
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=n;j++) {
                cout << dist[i][j] << ' ';
            }
            cout << '\n';
        }
        */
        if(ok){
            l = mid + 1;
            ans = mid;
        }
        else r = mid - 1;
    }
    cout << ans;
    /*
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cout << bdist[i][j] << ' ';
        }
        cout << '\n';
    }
    */
    return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:18:25: warning: variable 'ei' set but not used [-Wunused-but-set-variable]
   18 |     int si = -1,sj = -1,ei = -1,ej = -1;
      |                         ^~
mecho.cpp:18:33: warning: variable 'ej' set but not used [-Wunused-but-set-variable]
   18 |     int si = -1,sj = -1,ei = -1,ej = -1;
      |                                 ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Incorrect 1 ms 508 KB Output isn't correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Incorrect 1 ms 336 KB Output isn't correct
6 Incorrect 1 ms 336 KB Output isn't correct
7 Incorrect 163 ms 6540 KB Output isn't correct
8 Correct 1 ms 336 KB Output is correct
9 Incorrect 1 ms 336 KB Output isn't correct
10 Incorrect 1 ms 336 KB Output isn't correct
11 Incorrect 1 ms 336 KB Output isn't correct
12 Incorrect 1 ms 336 KB Output isn't correct
13 Incorrect 1 ms 336 KB Output isn't correct
14 Correct 1 ms 336 KB Output is correct
15 Incorrect 1 ms 336 KB Output isn't correct
16 Incorrect 1 ms 336 KB Output isn't correct
17 Incorrect 1 ms 336 KB Output isn't correct
18 Incorrect 1 ms 336 KB Output isn't correct
19 Incorrect 1 ms 336 KB Output isn't correct
20 Incorrect 1 ms 336 KB Output isn't correct
21 Incorrect 1 ms 352 KB Output isn't correct
22 Incorrect 1 ms 336 KB Output isn't correct
23 Incorrect 1 ms 336 KB Output isn't correct
24 Incorrect 1 ms 504 KB Output isn't correct
25 Incorrect 1 ms 336 KB Output isn't correct
26 Incorrect 2 ms 336 KB Output isn't correct
27 Incorrect 1 ms 336 KB Output isn't correct
28 Incorrect 2 ms 336 KB Output isn't correct
29 Incorrect 1 ms 336 KB Output isn't correct
30 Incorrect 1 ms 336 KB Output isn't correct
31 Incorrect 1 ms 336 KB Output isn't correct
32 Incorrect 2 ms 532 KB Output isn't correct
33 Incorrect 17 ms 1616 KB Output isn't correct
34 Incorrect 23 ms 1664 KB Output isn't correct
35 Incorrect 22 ms 1664 KB Output isn't correct
36 Incorrect 20 ms 1872 KB Output isn't correct
37 Incorrect 32 ms 1872 KB Output isn't correct
38 Incorrect 40 ms 1976 KB Output isn't correct
39 Incorrect 26 ms 2412 KB Output isn't correct
40 Incorrect 45 ms 2412 KB Output isn't correct
41 Incorrect 39 ms 2416 KB Output isn't correct
42 Incorrect 33 ms 2848 KB Output isn't correct
43 Incorrect 52 ms 2804 KB Output isn't correct
44 Incorrect 62 ms 2864 KB Output isn't correct
45 Incorrect 41 ms 3312 KB Output isn't correct
46 Incorrect 67 ms 3472 KB Output isn't correct
47 Incorrect 66 ms 3336 KB Output isn't correct
48 Incorrect 46 ms 3664 KB Output isn't correct
49 Incorrect 77 ms 3872 KB Output isn't correct
50 Incorrect 72 ms 3860 KB Output isn't correct
51 Incorrect 54 ms 4600 KB Output isn't correct
52 Incorrect 88 ms 4432 KB Output isn't correct
53 Incorrect 88 ms 4432 KB Output isn't correct
54 Incorrect 65 ms 4944 KB Output isn't correct
55 Incorrect 104 ms 5056 KB Output isn't correct
56 Incorrect 98 ms 5072 KB Output isn't correct
57 Incorrect 74 ms 5712 KB Output isn't correct
58 Incorrect 130 ms 5724 KB Output isn't correct
59 Incorrect 119 ms 5736 KB Output isn't correct
60 Incorrect 84 ms 6380 KB Output isn't correct
61 Incorrect 148 ms 6300 KB Output isn't correct
62 Incorrect 133 ms 6464 KB Output isn't correct
63 Incorrect 115 ms 6488 KB Output isn't correct
64 Incorrect 199 ms 6452 KB Output isn't correct
65 Incorrect 179 ms 6432 KB Output isn't correct
66 Incorrect 147 ms 6440 KB Output isn't correct
67 Correct 117 ms 6548 KB Output is correct
68 Incorrect 68 ms 6460 KB Output isn't correct
69 Incorrect 75 ms 6488 KB Output isn't correct
70 Incorrect 66 ms 6532 KB Output isn't correct
71 Incorrect 65 ms 6488 KB Output isn't correct
72 Incorrect 91 ms 6456 KB Output isn't correct
73 Incorrect 68 ms 6488 KB Output isn't correct
74 Incorrect 135 ms 6480 KB Output isn't correct
75 Incorrect 98 ms 6452 KB Output isn't correct
76 Incorrect 96 ms 6468 KB Output isn't correct
77 Incorrect 108 ms 6452 KB Output isn't correct
78 Correct 101 ms 6272 KB Output is correct
79 Incorrect 145 ms 6268 KB Output isn't correct
80 Incorrect 107 ms 6384 KB Output isn't correct
81 Incorrect 103 ms 6404 KB Output isn't correct
82 Incorrect 104 ms 6496 KB Output isn't correct
83 Incorrect 107 ms 6500 KB Output isn't correct
84 Incorrect 144 ms 6480 KB Output isn't correct
85 Incorrect 94 ms 6448 KB Output isn't correct
86 Incorrect 97 ms 6456 KB Output isn't correct
87 Incorrect 113 ms 6480 KB Output isn't correct
88 Incorrect 101 ms 6460 KB Output isn't correct
89 Incorrect 159 ms 6432 KB Output isn't correct
90 Incorrect 126 ms 6448 KB Output isn't correct
91 Incorrect 113 ms 6448 KB Output isn't correct
92 Incorrect 104 ms 6508 KB Output isn't correct