Submission #893263

# Submission time Handle Problem Language Result Execution time Memory
893263 2023-12-26T19:04:45 Z Macker Mecho (IOI09_mecho) C++17
31 / 100
161 ms 1368 KB
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define v(x) v[x.first][x.second]
#define bs(x) bs[x.first][x.second]

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")

int n, s;
vector<vector<bool>> mp;
vector<pii> hives;
pii strt;
pii trgt;

vector<pii> adj = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
bool in(pii x){
    if(x.first < 0 || x.first >= n) return 0;
    if(x.second < 0 || x.second >= n) return 0;
    return 1;
}

bool can(int t){
    vector<vector<bool>> v = mp;
    vector<vector<bool>> bs;
    bs.resize(n, vector<bool>(n));

    queue<pair<pii, int>> q, bq;
    q.push({strt, t});
    for(auto i : hives) bq.push({i, 0});
    while(bq.size() && bq.front().second < t){
        auto [a, d] = bq.front(); bq.pop();
        for (auto &&o : adj) {
            pii b = {a.first + o.first, a.second + o.second};
            if(in(b) && !v(b) && !bs(b)){
                bs(b) = true;
                bq.push({b, d + 1});
            }
        }
    }

    int nt = t;
    while(q.size()){
        nt += s;
        t++;
        while(q.size() && q.front().second < nt){
            auto [a, d] = q.front(); q.pop();
            if(bs(a)) continue;
            for (auto &&o : adj) {
                pii b = {a.first + o.first, a.second + o.second};
                if(in(b) && !v(b) && !bs(b)){
                    v(b) = true;
                    q.push({b, d + 1});
                }
                if(b == trgt) return true;
            }
        }
        while(bq.size() && bq.front().second < t){
        auto [a, d] = bq.front(); bq.pop();
            for (auto &&o : adj) {
                pii b = {a.first + o.first, a.second + o.second};
                if(in(b) && !v(b) && !bs(b)){
                    bs(b) = true;
                    bq.push({b, d + 1});
                }
            }
        }
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> s;
    mp.resize(n, vector<bool>(n));
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        for (int j = 0; j < n; j++) {
            char a = s[j];
            if(a == 'M') strt = {i, j};
            else if(a == 'D') { trgt = {i, j}; mp[i][j] = 1;}
            else if(a == 'H') hives.push_back({i, j});
            else if(a == 'T') mp[i][j] = 1;
        }
    }
    
    int l = 0, r = 2*n, mid;
    while(l < r){
        mid = (l + r + 1) / 2;
        if(can(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 126 ms 1104 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Correct 1 ms 348 KB Output is correct
14 Incorrect 1 ms 344 KB Output isn't correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Incorrect 0 ms 348 KB Output isn't correct
21 Incorrect 1 ms 348 KB Output isn't correct
22 Incorrect 0 ms 348 KB Output isn't correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Incorrect 1 ms 348 KB Output isn't correct
25 Incorrect 1 ms 348 KB Output isn't correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Incorrect 1 ms 348 KB Output isn't correct
28 Incorrect 0 ms 348 KB Output isn't correct
29 Incorrect 0 ms 348 KB Output isn't correct
30 Incorrect 0 ms 348 KB Output isn't correct
31 Incorrect 1 ms 348 KB Output isn't correct
32 Incorrect 0 ms 348 KB Output isn't correct
33 Incorrect 1 ms 344 KB Output isn't correct
34 Incorrect 2 ms 348 KB Output isn't correct
35 Correct 16 ms 348 KB Output is correct
36 Incorrect 1 ms 344 KB Output isn't correct
37 Incorrect 2 ms 856 KB Output isn't correct
38 Correct 20 ms 592 KB Output is correct
39 Incorrect 2 ms 604 KB Output isn't correct
40 Incorrect 2 ms 604 KB Output isn't correct
41 Correct 26 ms 640 KB Output is correct
42 Incorrect 3 ms 600 KB Output isn't correct
43 Incorrect 3 ms 528 KB Output isn't correct
44 Correct 33 ms 600 KB Output is correct
45 Incorrect 2 ms 600 KB Output isn't correct
46 Incorrect 3 ms 604 KB Output isn't correct
47 Correct 40 ms 604 KB Output is correct
48 Incorrect 2 ms 604 KB Output isn't correct
49 Incorrect 3 ms 600 KB Output isn't correct
50 Correct 48 ms 604 KB Output is correct
51 Incorrect 3 ms 604 KB Output isn't correct
52 Incorrect 4 ms 604 KB Output isn't correct
53 Correct 64 ms 744 KB Output is correct
54 Incorrect 4 ms 604 KB Output isn't correct
55 Incorrect 4 ms 756 KB Output isn't correct
56 Correct 67 ms 572 KB Output is correct
57 Incorrect 4 ms 604 KB Output isn't correct
58 Incorrect 4 ms 604 KB Output isn't correct
59 Correct 76 ms 604 KB Output is correct
60 Incorrect 4 ms 600 KB Output isn't correct
61 Incorrect 4 ms 604 KB Output isn't correct
62 Correct 89 ms 604 KB Output is correct
63 Correct 84 ms 824 KB Output is correct
64 Correct 109 ms 832 KB Output is correct
65 Correct 111 ms 828 KB Output is correct
66 Incorrect 108 ms 828 KB Output isn't correct
67 Incorrect 110 ms 828 KB Output isn't correct
68 Correct 111 ms 864 KB Output is correct
69 Correct 89 ms 860 KB Output is correct
70 Correct 107 ms 860 KB Output is correct
71 Correct 111 ms 860 KB Output is correct
72 Correct 161 ms 860 KB Output is correct
73 Correct 87 ms 1112 KB Output is correct
74 Correct 139 ms 1268 KB Output is correct
75 Correct 142 ms 1272 KB Output is correct
76 Correct 134 ms 1256 KB Output is correct
77 Correct 148 ms 1112 KB Output is correct
78 Incorrect 150 ms 1208 KB Output isn't correct
79 Correct 140 ms 1368 KB Output is correct
80 Correct 145 ms 1208 KB Output is correct
81 Correct 150 ms 1116 KB Output is correct
82 Correct 145 ms 1112 KB Output is correct
83 Correct 127 ms 1140 KB Output is correct
84 Correct 143 ms 1140 KB Output is correct
85 Correct 149 ms 1112 KB Output is correct
86 Correct 140 ms 1116 KB Output is correct
87 Correct 130 ms 1116 KB Output is correct
88 Correct 145 ms 856 KB Output is correct
89 Correct 135 ms 856 KB Output is correct
90 Correct 146 ms 1068 KB Output is correct
91 Correct 137 ms 860 KB Output is correct
92 Correct 144 ms 1116 KB Output is correct