답안 #255242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255242 2020-07-31T15:56:26 Z DavidDamian Mecho (IOI09_mecho) C++11
4 / 100
259 ms 12024 KB
#include <bits/stdc++.h>
using namespace std;
struct node
{
    int i,j;
    node(){}
    node(int i,int j) : i(i),j(j){}
};
int n,s;
char board[805][805];
int bee[805][805];
int d[805][805];
int color[805][805];
int fuel[805][805];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
queue<node> Q;
node start,finish;
void bfsBee()
{
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            bee[i][j]=INT_MAX;
            if(board[i][j]=='H'){
                Q.push(node(i,j));
                bee[i][j]=0;
                color[i][j]=-1;
            }
        }
    }
    while(Q.size()){
        node u=Q.front();Q.pop();
        for(int mov=0;mov<4;mov++){
            int i=u.i+dx[mov];
            int j=u.j+dy[mov];
            if(i<1 || i>n) continue;
            if(j<1 || j>n) continue;
            if(board[i][j]=='T' || board[i][j]=='D') continue;
            if(color[i][j]==0){
                color[i][j]=-1;
                Q.push(node(i,j));
                bee[i][j]=bee[u.i][u.j]+1;
            }
        }
    }
}
void bfsMecho(int init_d)
{
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            d[i][j]=INT_MAX;
            color[i][j]=0;
        }
    }
    if(bee[start.i][start.j]<=init_d-1) return;
    d[start.i][start.j]=init_d-1;
    fuel[start.i][start.j]=0;
    color[start.i][start.j]=init_d;
    Q.push(start);
    while(Q.size()){
        node u=Q.front();Q.pop();
        if(d[u.i][u.j]==bee[u.i][u.j] && fuel[u.i][u.j]==0) continue;
        for(int mov=0;mov<4;mov++){
            int i=u.i+dx[mov];
            int j=u.j+dy[mov];
            if(i<1 || i>n) continue;
            if(j<1 || j>n) continue;
            if(board[i][j]=='T') continue;
            if(color[i][j]!=init_d){
                d[i][j]=(fuel[u.i][u.j]>0)? d[u.i][u.j] : d[u.i][u.j]+1;
                if(bee[i][j]<d[i][j]) continue;
                fuel[i][j]=(fuel[u.i][u.j]>0)? fuel[u.i][u.j]-1 : s-1;
                color[i][j]=init_d;
                Q.push(node(i,j));
            }
        }
    }
}
bool valid(int k)
{
    bfsMecho(k);
    return d[finish.i][finish.j]!=INT_MAX;
}
int binarySearch()
{
    int k=0;
    for(int b=10000;b>=1;b/=2){
        while(valid(k+b)) k+=b;
    }
    return (k==0)? -1 : k;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>s;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>board[i][j];
            if(board[i][j]=='M') start={i,j};
            if(board[i][j]=='D') finish={i,j};
        }
    }
    bfsBee();
    int maximum=binarySearch();
    cout<<maximum<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Incorrect 0 ms 384 KB Output isn't correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Incorrect 1 ms 512 KB Output isn't correct
6 Incorrect 0 ms 512 KB Output isn't correct
7 Incorrect 155 ms 10948 KB Output isn't correct
8 Correct 1 ms 512 KB Output is correct
9 Incorrect 0 ms 512 KB Output isn't correct
10 Incorrect 1 ms 512 KB Output isn't correct
11 Incorrect 1 ms 512 KB Output isn't correct
12 Incorrect 1 ms 1152 KB Output isn't correct
13 Incorrect 1 ms 896 KB Output isn't correct
14 Correct 1 ms 1152 KB Output is correct
15 Incorrect 1 ms 512 KB Output isn't correct
16 Incorrect 1 ms 512 KB Output isn't correct
17 Incorrect 1 ms 640 KB Output isn't correct
18 Incorrect 1 ms 640 KB Output isn't correct
19 Incorrect 1 ms 640 KB Output isn't correct
20 Incorrect 1 ms 640 KB Output isn't correct
21 Incorrect 1 ms 768 KB Output isn't correct
22 Incorrect 1 ms 768 KB Output isn't correct
23 Incorrect 1 ms 896 KB Output isn't correct
24 Incorrect 1 ms 896 KB Output isn't correct
25 Incorrect 1 ms 1024 KB Output isn't correct
26 Incorrect 1 ms 1024 KB Output isn't correct
27 Incorrect 1 ms 1024 KB Output isn't correct
28 Incorrect 1 ms 1152 KB Output isn't correct
29 Incorrect 1 ms 1152 KB Output isn't correct
30 Incorrect 1 ms 1152 KB Output isn't correct
31 Incorrect 1 ms 1152 KB Output isn't correct
32 Incorrect 1 ms 1152 KB Output isn't correct
33 Incorrect 10 ms 4480 KB Output isn't correct
34 Incorrect 10 ms 4864 KB Output isn't correct
35 Incorrect 28 ms 5120 KB Output isn't correct
36 Incorrect 15 ms 5120 KB Output isn't correct
37 Incorrect 15 ms 5632 KB Output isn't correct
38 Incorrect 36 ms 5888 KB Output isn't correct
39 Incorrect 21 ms 5760 KB Output isn't correct
40 Incorrect 19 ms 6272 KB Output isn't correct
41 Incorrect 49 ms 6580 KB Output isn't correct
42 Incorrect 26 ms 6400 KB Output isn't correct
43 Incorrect 22 ms 7040 KB Output isn't correct
44 Incorrect 75 ms 7296 KB Output isn't correct
45 Incorrect 36 ms 7152 KB Output isn't correct
46 Incorrect 28 ms 7796 KB Output isn't correct
47 Incorrect 75 ms 8064 KB Output isn't correct
48 Incorrect 48 ms 7808 KB Output isn't correct
49 Incorrect 38 ms 8696 KB Output isn't correct
50 Incorrect 105 ms 8792 KB Output isn't correct
51 Incorrect 58 ms 8484 KB Output isn't correct
52 Incorrect 51 ms 9344 KB Output isn't correct
53 Incorrect 121 ms 9464 KB Output isn't correct
54 Incorrect 76 ms 9208 KB Output isn't correct
55 Incorrect 57 ms 9976 KB Output isn't correct
56 Incorrect 161 ms 10360 KB Output isn't correct
57 Incorrect 87 ms 9728 KB Output isn't correct
58 Incorrect 86 ms 10744 KB Output isn't correct
59 Incorrect 259 ms 10876 KB Output isn't correct
60 Incorrect 120 ms 10360 KB Output isn't correct
61 Incorrect 107 ms 11512 KB Output isn't correct
62 Incorrect 206 ms 11768 KB Output isn't correct
63 Incorrect 143 ms 11640 KB Output isn't correct
64 Incorrect 245 ms 11640 KB Output isn't correct
65 Incorrect 229 ms 11840 KB Output isn't correct
66 Incorrect 179 ms 11644 KB Output isn't correct
67 Correct 136 ms 11640 KB Output is correct
68 Incorrect 69 ms 11896 KB Output isn't correct
69 Incorrect 59 ms 11840 KB Output isn't correct
70 Incorrect 58 ms 11768 KB Output isn't correct
71 Incorrect 57 ms 11768 KB Output isn't correct
72 Incorrect 45 ms 9848 KB Output isn't correct
73 Incorrect 59 ms 11896 KB Output isn't correct
74 Incorrect 90 ms 11896 KB Output isn't correct
75 Incorrect 103 ms 11896 KB Output isn't correct
76 Incorrect 97 ms 11896 KB Output isn't correct
77 Incorrect 91 ms 12024 KB Output isn't correct
78 Correct 95 ms 10744 KB Output is correct
79 Incorrect 73 ms 10232 KB Output isn't correct
80 Incorrect 89 ms 10360 KB Output isn't correct
81 Incorrect 96 ms 10488 KB Output isn't correct
82 Incorrect 89 ms 10488 KB Output isn't correct
83 Incorrect 107 ms 10616 KB Output isn't correct
84 Incorrect 114 ms 10488 KB Output isn't correct
85 Incorrect 108 ms 10616 KB Output isn't correct
86 Incorrect 117 ms 10616 KB Output isn't correct
87 Incorrect 127 ms 10616 KB Output isn't correct
88 Incorrect 107 ms 10872 KB Output isn't correct
89 Incorrect 123 ms 10648 KB Output isn't correct
90 Incorrect 135 ms 10616 KB Output isn't correct
91 Incorrect 159 ms 10744 KB Output isn't correct
92 Incorrect 131 ms 10744 KB Output isn't correct