답안 #960544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960544 2024-04-10T15:39:36 Z LmaoLmao Mecho (IOI09_mecho) C++14
37 / 100
214 ms 8568 KB
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
 
using ll = long long;
using ii = pair<int, int>;
 
const int N = 1e6+5;
const int INF = 1e9;

int d[1000][1000],m[1000][1000],n,s;
char a[1000][1000];
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};
ii pos,h;

bool bfs(int x) {
    queue<ii> q;
    q.push(pos);
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            m[i][j]=0;
        }
    }
    while(!q.empty()) {
        ii u=q.front();
        q.pop();
        for(int i=0;i<4;i++) {
            ii v={u.fi+dx[i],u.se+dy[i]};
            if(v.fi<0 || v.fi>=n || v.se<0 || v.se>=n) continue;
            if(m[v.fi][v.se]==0 && a[v.fi][v.se]!='T' && 
            d[v.fi][v.se]-x>m[u.fi][u.se]+1 && a[v.fi][v.se]!='M') {
                m[v.fi][v.se]=m[u.fi][u.se]+1;
                q.push(v);
            }
        }
    }
    if(m[h.fi][h.se]>0) return 1; else return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    queue<ii> q;
    cin >> n >> s;
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            cin >> a[i][j];
            if(a[i][j]=='H') {
                q.push({i,j});
            }
            if(a[i][j]=='M') pos={i,j};
            if(a[i][j]=='D') h={i,j};
        }
    }
    while(!q.empty()) {
        ii u=q.front();
        q.pop();
        for(int i=0;i<4;i++) {
            ii v={u.fi+dx[i],u.se+dy[i]};
            if(v.fi<0 || v.fi>=n || v.se<0 || v.se>=n) continue;
            if(d[v.fi][v.se]==0 && a[v.fi][v.se]!='T' && a[v.fi][v.se]!='H') {
                d[v.fi][v.se]=d[u.fi][u.se]+s;
                q.push(v);
            }
        }
    }
    int l=0,r=1000000,ans=-1;
    while(l<=r) {
        int m=(l+r)/2;
        if(bfs(m)) {
            ans=m;
            l=m+1;
        }
        else {
            r=m-1;
        }
    }
    cout << ans/s;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Correct 1 ms 2396 KB Output is correct
6 Incorrect 1 ms 2396 KB Output isn't correct
7 Incorrect 68 ms 8028 KB Output isn't correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Incorrect 2 ms 2652 KB Output isn't correct
13 Incorrect 1 ms 2652 KB Output isn't correct
14 Incorrect 1 ms 2652 KB Output isn't correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2512 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2648 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2648 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2804 KB Output is correct
33 Correct 4 ms 6104 KB Output is correct
34 Incorrect 22 ms 6236 KB Output isn't correct
35 Correct 24 ms 6108 KB Output is correct
36 Correct 5 ms 6236 KB Output is correct
37 Incorrect 22 ms 6324 KB Output isn't correct
38 Correct 30 ms 6236 KB Output is correct
39 Correct 6 ms 6488 KB Output is correct
40 Incorrect 32 ms 6492 KB Output isn't correct
41 Correct 45 ms 6648 KB Output is correct
42 Correct 8 ms 6748 KB Output is correct
43 Incorrect 35 ms 6748 KB Output isn't correct
44 Correct 49 ms 6872 KB Output is correct
45 Correct 8 ms 7000 KB Output is correct
46 Incorrect 42 ms 7072 KB Output isn't correct
47 Correct 61 ms 7104 KB Output is correct
48 Correct 9 ms 7256 KB Output is correct
49 Incorrect 56 ms 7292 KB Output isn't correct
50 Correct 76 ms 7260 KB Output is correct
51 Correct 11 ms 7512 KB Output is correct
52 Incorrect 59 ms 7548 KB Output isn't correct
53 Correct 87 ms 7596 KB Output is correct
54 Correct 13 ms 7512 KB Output is correct
55 Incorrect 70 ms 7800 KB Output isn't correct
56 Correct 99 ms 7788 KB Output is correct
57 Correct 13 ms 7776 KB Output is correct
58 Incorrect 80 ms 8036 KB Output isn't correct
59 Correct 124 ms 8028 KB Output is correct
60 Correct 15 ms 8232 KB Output is correct
61 Incorrect 87 ms 8404 KB Output isn't correct
62 Correct 131 ms 8280 KB Output is correct
63 Correct 76 ms 8252 KB Output is correct
64 Correct 214 ms 8228 KB Output is correct
65 Correct 118 ms 8296 KB Output is correct
66 Correct 97 ms 8012 KB Output is correct
67 Incorrect 82 ms 8284 KB Output isn't correct
68 Correct 51 ms 8284 KB Output is correct
69 Correct 55 ms 8280 KB Output is correct
70 Correct 31 ms 8312 KB Output is correct
71 Correct 28 ms 8156 KB Output is correct
72 Incorrect 24 ms 8284 KB Output isn't correct
73 Incorrect 28 ms 8536 KB Output isn't correct
74 Correct 54 ms 8560 KB Output is correct
75 Correct 46 ms 8536 KB Output is correct
76 Correct 44 ms 8540 KB Output is correct
77 Correct 56 ms 8568 KB Output is correct
78 Incorrect 55 ms 8512 KB Output isn't correct
79 Correct 57 ms 8544 KB Output is correct
80 Correct 45 ms 8284 KB Output is correct
81 Correct 57 ms 8272 KB Output is correct
82 Correct 49 ms 8384 KB Output is correct
83 Correct 61 ms 8264 KB Output is correct
84 Correct 64 ms 8324 KB Output is correct
85 Correct 55 ms 8284 KB Output is correct
86 Correct 58 ms 8496 KB Output is correct
87 Correct 73 ms 8520 KB Output is correct
88 Correct 68 ms 8456 KB Output is correct
89 Correct 83 ms 8400 KB Output is correct
90 Correct 68 ms 8444 KB Output is correct
91 Correct 68 ms 8412 KB Output is correct
92 Correct 74 ms 8452 KB Output is correct