답안 #960496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960496 2024-04-10T14:25:58 Z LmaoLmao Mecho (IOI09_mecho) C++14
30 / 100
116 ms 8280 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.0+1)/(s*1.0) && 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]+1;
                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;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Incorrect 1 ms 2648 KB Output isn't correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Incorrect 2 ms 2396 KB Output isn't correct
5 Correct 1 ms 2392 KB Output is correct
6 Incorrect 1 ms 2396 KB Output isn't correct
7 Incorrect 53 ms 7972 KB Output isn't correct
8 Incorrect 1 ms 2648 KB Output isn't correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Incorrect 1 ms 2652 KB Output isn't correct
13 Incorrect 1 ms 2648 KB Output isn't correct
14 Correct 1 ms 2648 KB Output is correct
15 Incorrect 2 ms 2392 KB Output isn't correct
16 Correct 1 ms 2396 KB Output is correct
17 Incorrect 1 ms 2396 KB Output isn't correct
18 Correct 1 ms 2396 KB Output is correct
19 Incorrect 2 ms 2652 KB Output isn't correct
20 Correct 1 ms 2652 KB Output is correct
21 Incorrect 1 ms 2652 KB Output isn't correct
22 Correct 1 ms 2652 KB Output is correct
23 Incorrect 1 ms 2652 KB Output isn't correct
24 Correct 1 ms 2652 KB Output is correct
25 Incorrect 1 ms 2652 KB Output isn't correct
26 Correct 1 ms 2648 KB Output is correct
27 Incorrect 1 ms 2648 KB Output isn't correct
28 Correct 1 ms 2652 KB Output is correct
29 Incorrect 1 ms 2652 KB Output isn't correct
30 Correct 1 ms 2652 KB Output is correct
31 Incorrect 1 ms 2652 KB Output isn't correct
32 Correct 1 ms 2648 KB Output is correct
33 Incorrect 4 ms 5980 KB Output isn't correct
34 Correct 4 ms 5976 KB Output is correct
35 Correct 13 ms 5980 KB Output is correct
36 Incorrect 5 ms 6236 KB Output isn't correct
37 Correct 4 ms 6236 KB Output is correct
38 Correct 17 ms 6236 KB Output is correct
39 Incorrect 8 ms 6492 KB Output isn't correct
40 Correct 6 ms 6280 KB Output is correct
41 Correct 21 ms 6492 KB Output is correct
42 Incorrect 7 ms 6492 KB Output isn't correct
43 Correct 7 ms 6492 KB Output is correct
44 Correct 27 ms 6492 KB Output is correct
45 Incorrect 7 ms 6748 KB Output isn't correct
46 Correct 7 ms 6748 KB Output is correct
47 Correct 37 ms 6748 KB Output is correct
48 Incorrect 9 ms 7000 KB Output isn't correct
49 Correct 9 ms 7004 KB Output is correct
50 Correct 39 ms 7004 KB Output is correct
51 Incorrect 11 ms 7540 KB Output isn't correct
52 Correct 14 ms 7256 KB Output is correct
53 Correct 67 ms 7276 KB Output is correct
54 Incorrect 12 ms 7256 KB Output isn't correct
55 Correct 15 ms 7340 KB Output is correct
56 Correct 57 ms 7472 KB Output is correct
57 Incorrect 13 ms 7516 KB Output isn't correct
58 Correct 12 ms 7456 KB Output is correct
59 Correct 69 ms 7684 KB Output is correct
60 Incorrect 17 ms 8028 KB Output isn't correct
61 Correct 17 ms 7768 KB Output is correct
62 Correct 71 ms 7772 KB Output is correct
63 Correct 75 ms 7860 KB Output is correct
64 Correct 116 ms 7772 KB Output is correct
65 Correct 112 ms 7856 KB Output is correct
66 Incorrect 99 ms 7860 KB Output isn't correct
67 Correct 77 ms 7772 KB Output is correct
68 Correct 34 ms 7888 KB Output is correct
69 Correct 37 ms 7896 KB Output is correct
70 Correct 30 ms 7772 KB Output is correct
71 Correct 26 ms 7772 KB Output is correct
72 Incorrect 25 ms 7908 KB Output isn't correct
73 Incorrect 24 ms 8140 KB Output isn't correct
74 Correct 37 ms 8016 KB Output is correct
75 Correct 42 ms 7888 KB Output is correct
76 Correct 36 ms 8148 KB Output is correct
77 Correct 38 ms 8028 KB Output is correct
78 Correct 48 ms 8124 KB Output is correct
79 Correct 34 ms 8024 KB Output is correct
80 Correct 41 ms 8108 KB Output is correct
81 Correct 42 ms 8280 KB Output is correct
82 Correct 33 ms 8028 KB Output is correct
83 Correct 48 ms 8072 KB Output is correct
84 Correct 42 ms 8028 KB Output is correct
85 Correct 47 ms 8060 KB Output is correct
86 Correct 48 ms 8024 KB Output is correct
87 Correct 48 ms 8068 KB Output is correct
88 Correct 47 ms 8024 KB Output is correct
89 Correct 46 ms 8028 KB Output is correct
90 Correct 48 ms 8024 KB Output is correct
91 Correct 51 ms 8024 KB Output is correct
92 Correct 61 ms 8028 KB Output is correct