답안 #851503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851503 2023-09-20T02:39:54 Z abcvuitunggio Mecho (IOI09_mecho) C++17
53 / 100
132 ms 7248 KB
#include <bits/stdc++.h>
using namespace std;
int n,s,dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},d[801][801],d2[801][801];
string m[801];
queue <pair <int, int>> q;
bool check(int x){
    memset(d2,0,sizeof(d2));
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if (m[i][j]=='M'){
                q.push({i,j});
                d2[i][j]=1;
            }
    while (!q.empty()){
        auto [i,j]=q.front();
        q.pop();
        for (int k=0;k<4;k++){
            int u=i+dx[k],v=j+dy[k];
            if (min(u,v)>=0&&max(u,v)<n)
                if (m[u][v]!='T'&&(d[u][v]-x*s>d2[i][j]||(d[u][v]-x*s>=d2[i][j]&&m[u][v]=='D'))&&!d2[u][v]){
                    d2[u][v]=d2[i][j]+1;
                    q.push({u,v});
                }
        }
    }
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if (m[i][j]=='D')
                return d2[i][j];
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> s;
    for (int i=0;i<n;i++){
        cin >> m[i];
        for (int j=0;j<n;j++)
            if (m[i][j]=='H'){
                q.push({i,j});
                d[i][j]=1;
            }
    }
    while (!q.empty()){
        auto [i,j]=q.front();
        q.pop();
        for (int k=0;k<4;k++){
            int u=i+dx[k],v=j+dy[k];
            if (min(u,v)>=0&&max(u,v)<n)
                if (m[u][v]!='T'&&!d[u][v]){
                    d[u][v]=d[i][j]+1;
                    q.push({u,v});
                }
        }
    }
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            d[i][j]=(d[i][j]-1)*s;
    int l=0,r=100000,kq=-1;
    while (l<=r){
        int mid=(l+r)>>1;
        if (check(mid)){
            kq=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    cout << kq;
}

Compilation message

mecho.cpp: In function 'bool check(int)':
mecho.cpp:30:1: warning: control reaches end of non-void function [-Wreturn-type]
   30 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Incorrect 2 ms 4696 KB Output isn't correct
3 Correct 2 ms 4700 KB Output is correct
4 Incorrect 2 ms 4952 KB Output isn't correct
5 Correct 2 ms 4696 KB Output is correct
6 Incorrect 2 ms 4696 KB Output isn't correct
7 Incorrect 72 ms 6736 KB Output isn't correct
8 Correct 2 ms 4696 KB Output is correct
9 Correct 2 ms 4696 KB Output is correct
10 Correct 2 ms 4696 KB Output is correct
11 Correct 2 ms 4696 KB Output is correct
12 Incorrect 2 ms 4696 KB Output isn't correct
13 Incorrect 2 ms 4696 KB Output isn't correct
14 Correct 2 ms 4700 KB Output is correct
15 Correct 2 ms 4696 KB Output is correct
16 Correct 2 ms 4580 KB Output is correct
17 Correct 2 ms 4696 KB Output is correct
18 Correct 2 ms 4696 KB Output is correct
19 Correct 2 ms 4696 KB Output is correct
20 Correct 2 ms 4696 KB Output is correct
21 Correct 2 ms 4696 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 2 ms 4696 KB Output is correct
24 Correct 2 ms 4696 KB Output is correct
25 Correct 2 ms 4696 KB Output is correct
26 Correct 3 ms 4696 KB Output is correct
27 Correct 2 ms 4696 KB Output is correct
28 Correct 2 ms 4700 KB Output is correct
29 Correct 2 ms 4696 KB Output is correct
30 Correct 2 ms 4696 KB Output is correct
31 Correct 2 ms 4696 KB Output is correct
32 Correct 2 ms 4696 KB Output is correct
33 Correct 4 ms 4952 KB Output is correct
34 Correct 5 ms 4952 KB Output is correct
35 Correct 18 ms 4952 KB Output is correct
36 Correct 5 ms 4952 KB Output is correct
37 Correct 6 ms 4952 KB Output is correct
38 Correct 25 ms 4952 KB Output is correct
39 Incorrect 7 ms 4952 KB Output isn't correct
40 Correct 9 ms 5156 KB Output is correct
41 Correct 34 ms 4952 KB Output is correct
42 Incorrect 12 ms 5208 KB Output isn't correct
43 Correct 9 ms 5208 KB Output is correct
44 Correct 39 ms 5208 KB Output is correct
45 Incorrect 17 ms 5208 KB Output isn't correct
46 Correct 11 ms 5208 KB Output is correct
47 Correct 47 ms 5208 KB Output is correct
48 Incorrect 23 ms 5464 KB Output isn't correct
49 Correct 15 ms 5724 KB Output is correct
50 Correct 57 ms 5600 KB Output is correct
51 Incorrect 31 ms 5720 KB Output isn't correct
52 Incorrect 19 ms 5724 KB Output isn't correct
53 Correct 67 ms 5888 KB Output is correct
54 Incorrect 36 ms 5976 KB Output isn't correct
55 Incorrect 30 ms 5980 KB Output isn't correct
56 Correct 76 ms 5976 KB Output is correct
57 Incorrect 46 ms 6488 KB Output isn't correct
58 Incorrect 41 ms 6488 KB Output isn't correct
59 Correct 90 ms 6488 KB Output is correct
60 Incorrect 52 ms 6684 KB Output isn't correct
61 Incorrect 55 ms 6744 KB Output isn't correct
62 Correct 108 ms 6736 KB Output is correct
63 Correct 87 ms 6784 KB Output is correct
64 Correct 132 ms 6736 KB Output is correct
65 Correct 132 ms 6784 KB Output is correct
66 Correct 95 ms 6736 KB Output is correct
67 Correct 91 ms 6788 KB Output is correct
68 Correct 46 ms 6744 KB Output is correct
69 Correct 35 ms 6736 KB Output is correct
70 Correct 36 ms 6740 KB Output is correct
71 Correct 36 ms 6736 KB Output is correct
72 Incorrect 29 ms 6736 KB Output isn't correct
73 Incorrect 32 ms 7000 KB Output isn't correct
74 Correct 52 ms 6996 KB Output is correct
75 Correct 58 ms 7140 KB Output is correct
76 Correct 53 ms 6992 KB Output is correct
77 Correct 59 ms 7000 KB Output is correct
78 Correct 61 ms 7000 KB Output is correct
79 Correct 47 ms 7036 KB Output is correct
80 Correct 50 ms 6996 KB Output is correct
81 Correct 56 ms 7000 KB Output is correct
82 Correct 56 ms 7248 KB Output is correct
83 Correct 66 ms 7000 KB Output is correct
84 Correct 61 ms 7000 KB Output is correct
85 Correct 62 ms 7000 KB Output is correct
86 Correct 60 ms 7208 KB Output is correct
87 Correct 60 ms 7000 KB Output is correct
88 Correct 69 ms 6736 KB Output is correct
89 Correct 61 ms 6944 KB Output is correct
90 Correct 64 ms 6952 KB Output is correct
91 Correct 68 ms 7048 KB Output is correct
92 Correct 64 ms 6744 KB Output is correct