답안 #893264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893264 2023-12-26T19:09:23 Z Macker Mecho (IOI09_mecho) C++17
45 / 100
286 ms 1516 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 = n * n, mid;
    while(l < r){
        mid = (l + r + 1) / 2;
        if(can(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 1 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 227 ms 988 KB Output is correct
8 Incorrect 1 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 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Incorrect 1 ms 348 KB Output isn't correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Correct 1 ms 344 KB Output is correct
17 Incorrect 1 ms 348 KB Output isn't correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Correct 0 ms 348 KB Output is correct
21 Incorrect 0 ms 348 KB Output isn't correct
22 Correct 1 ms 348 KB Output is correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Correct 1 ms 348 KB Output is correct
25 Incorrect 1 ms 600 KB Output isn't correct
26 Correct 1 ms 348 KB Output is correct
27 Incorrect 1 ms 344 KB Output isn't correct
28 Correct 1 ms 348 KB Output is correct
29 Incorrect 1 ms 348 KB Output isn't correct
30 Correct 1 ms 348 KB Output is correct
31 Incorrect 1 ms 348 KB Output isn't correct
32 Correct 1 ms 480 KB Output is correct
33 Incorrect 18 ms 344 KB Output isn't correct
34 Correct 17 ms 348 KB Output is correct
35 Correct 27 ms 348 KB Output is correct
36 Incorrect 27 ms 348 KB Output isn't correct
37 Correct 24 ms 348 KB Output is correct
38 Correct 36 ms 740 KB Output is correct
39 Incorrect 32 ms 604 KB Output isn't correct
40 Correct 30 ms 604 KB Output is correct
41 Correct 55 ms 612 KB Output is correct
42 Incorrect 40 ms 600 KB Output isn't correct
43 Correct 37 ms 600 KB Output is correct
44 Correct 70 ms 604 KB Output is correct
45 Incorrect 51 ms 604 KB Output isn't correct
46 Correct 47 ms 600 KB Output is correct
47 Correct 71 ms 600 KB Output is correct
48 Incorrect 70 ms 604 KB Output isn't correct
49 Correct 52 ms 600 KB Output is correct
50 Correct 89 ms 604 KB Output is correct
51 Incorrect 70 ms 604 KB Output isn't correct
52 Correct 65 ms 604 KB Output is correct
53 Correct 104 ms 604 KB Output is correct
54 Incorrect 82 ms 600 KB Output isn't correct
55 Correct 76 ms 604 KB Output is correct
56 Correct 120 ms 604 KB Output is correct
57 Incorrect 93 ms 792 KB Output isn't correct
58 Correct 86 ms 600 KB Output is correct
59 Correct 156 ms 848 KB Output is correct
60 Incorrect 117 ms 816 KB Output isn't correct
61 Correct 104 ms 600 KB Output is correct
62 Correct 162 ms 840 KB Output is correct
63 Correct 212 ms 600 KB Output is correct
64 Correct 245 ms 832 KB Output is correct
65 Correct 213 ms 824 KB Output is correct
66 Incorrect 230 ms 824 KB Output isn't correct
67 Incorrect 232 ms 604 KB Output isn't correct
68 Correct 246 ms 1104 KB Output is correct
69 Correct 211 ms 864 KB Output is correct
70 Correct 252 ms 860 KB Output is correct
71 Correct 249 ms 868 KB Output is correct
72 Correct 275 ms 872 KB Output is correct
73 Correct 190 ms 1116 KB Output is correct
74 Correct 255 ms 1368 KB Output is correct
75 Correct 253 ms 1112 KB Output is correct
76 Correct 257 ms 1516 KB Output is correct
77 Correct 255 ms 1112 KB Output is correct
78 Incorrect 246 ms 1116 KB Output isn't correct
79 Correct 246 ms 1212 KB Output is correct
80 Correct 249 ms 1232 KB Output is correct
81 Correct 244 ms 1112 KB Output is correct
82 Correct 243 ms 1112 KB Output is correct
83 Correct 244 ms 1112 KB Output is correct
84 Correct 259 ms 1144 KB Output is correct
85 Correct 251 ms 1116 KB Output is correct
86 Correct 251 ms 1140 KB Output is correct
87 Correct 242 ms 1364 KB Output is correct
88 Correct 234 ms 1108 KB Output is correct
89 Correct 248 ms 1068 KB Output is correct
90 Correct 286 ms 1068 KB Output is correct
91 Correct 235 ms 860 KB Output is correct
92 Correct 241 ms 1088 KB Output is correct