답안 #500730

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500730 2022-01-01T01:59:26 Z kevin Mecho (IOI09_mecho) C++17
21 / 100
213 ms 8104 KB
#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 >= 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});
            }
        }
    }
    int l = 0;
    int r = n+5;
    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] + x) / 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

mecho.cpp: In function 'int main()':
mecho.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);
      |                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Correct 0 ms 332 KB Output is correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Incorrect 99 ms 7996 KB Output isn't correct
8 Incorrect 0 ms 332 KB Output isn't correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Incorrect 1 ms 716 KB Output isn't correct
13 Incorrect 1 ms 588 KB Output isn't correct
14 Correct 1 ms 716 KB Output is correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Incorrect 1 ms 332 KB Output isn't correct
17 Incorrect 1 ms 460 KB Output isn't correct
18 Incorrect 1 ms 460 KB Output isn't correct
19 Incorrect 1 ms 460 KB Output isn't correct
20 Incorrect 1 ms 460 KB Output isn't correct
21 Incorrect 1 ms 460 KB Output isn't correct
22 Incorrect 1 ms 460 KB Output isn't correct
23 Incorrect 1 ms 588 KB Output isn't correct
24 Incorrect 1 ms 588 KB Output isn't correct
25 Incorrect 1 ms 716 KB Output isn't correct
26 Incorrect 1 ms 716 KB Output isn't correct
27 Incorrect 1 ms 716 KB Output isn't correct
28 Incorrect 1 ms 716 KB Output isn't correct
29 Incorrect 2 ms 716 KB Output isn't correct
30 Incorrect 2 ms 716 KB Output isn't correct
31 Incorrect 2 ms 728 KB Output isn't correct
32 Incorrect 2 ms 716 KB Output isn't correct
33 Incorrect 18 ms 3052 KB Output isn't correct
34 Incorrect 18 ms 3044 KB Output isn't correct
35 Correct 23 ms 3040 KB Output is correct
36 Incorrect 17 ms 3548 KB Output isn't correct
37 Incorrect 22 ms 3520 KB Output isn't correct
38 Correct 33 ms 3508 KB Output is correct
39 Incorrect 21 ms 4016 KB Output isn't correct
40 Incorrect 29 ms 4032 KB Output isn't correct
41 Correct 41 ms 3996 KB Output is correct
42 Incorrect 32 ms 4532 KB Output isn't correct
43 Incorrect 41 ms 4512 KB Output isn't correct
44 Correct 65 ms 4588 KB Output is correct
45 Incorrect 34 ms 5032 KB Output isn't correct
46 Incorrect 49 ms 5052 KB Output isn't correct
47 Correct 65 ms 5052 KB Output is correct
48 Incorrect 41 ms 5580 KB Output isn't correct
49 Incorrect 56 ms 5608 KB Output isn't correct
50 Correct 93 ms 5588 KB Output is correct
51 Incorrect 55 ms 6164 KB Output isn't correct
52 Incorrect 74 ms 6176 KB Output isn't correct
53 Correct 92 ms 6172 KB Output is correct
54 Incorrect 58 ms 6744 KB Output isn't correct
55 Incorrect 93 ms 6748 KB Output isn't correct
56 Correct 106 ms 6748 KB Output is correct
57 Incorrect 63 ms 7352 KB Output isn't correct
58 Incorrect 117 ms 7352 KB Output isn't correct
59 Correct 121 ms 7364 KB Output is correct
60 Incorrect 75 ms 7992 KB Output isn't correct
61 Incorrect 98 ms 7996 KB Output isn't correct
62 Correct 166 ms 7992 KB Output is correct
63 Correct 122 ms 7964 KB Output is correct
64 Incorrect 213 ms 7956 KB Output isn't correct
65 Correct 179 ms 7956 KB Output is correct
66 Incorrect 139 ms 7956 KB Output isn't correct
67 Correct 149 ms 7976 KB Output is correct
68 Correct 65 ms 7988 KB Output is correct
69 Correct 55 ms 8036 KB Output is correct
70 Correct 51 ms 8016 KB Output is correct
71 Correct 50 ms 8024 KB Output is correct
72 Incorrect 41 ms 8012 KB Output isn't correct
73 Incorrect 46 ms 8008 KB Output isn't correct
74 Correct 68 ms 8028 KB Output is correct
75 Correct 75 ms 8020 KB Output is correct
76 Correct 81 ms 8016 KB Output is correct
77 Correct 77 ms 8012 KB Output is correct
78 Correct 85 ms 8024 KB Output is correct
79 Correct 79 ms 8076 KB Output is correct
80 Correct 71 ms 8012 KB Output is correct
81 Correct 87 ms 8104 KB Output is correct
82 Correct 75 ms 8016 KB Output is correct
83 Correct 96 ms 8020 KB Output is correct
84 Correct 111 ms 8068 KB Output is correct
85 Correct 104 ms 8012 KB Output is correct
86 Correct 102 ms 8040 KB Output is correct
87 Correct 96 ms 8016 KB Output is correct
88 Correct 117 ms 8004 KB Output is correct
89 Correct 106 ms 8012 KB Output is correct
90 Correct 115 ms 8000 KB Output is correct
91 Correct 129 ms 8012 KB Output is correct
92 Correct 94 ms 8012 KB Output is correct