Submission #444683

# Submission time Handle Problem Language Result Execution time Memory
444683 2021-07-14T18:48:43 Z Deepesson Mecho (IOI09_mecho) C++17
84 / 100
515 ms 5212 KB
#include <bits/stdc++.h>
#define MAX 850
std::string mapa[MAX];
typedef std::pair<int,int> pii;
bool proibido[MAX][MAX]={},nobees[MAX][MAX]={};
int N,K;
typedef std::pair<int,pii> pip;
std::vector<pii> hon;
void avancar(void) {
    std::vector<pii> honfut;
    for(auto&x:hon) {
        #define PUSH(A,B) if(A>=0&&B>=0&&A<N&&B<N&&!proibido[A][B]&&!nobees[A][B]){proibido[A][B]=true;honfut.push_back({A,B});}
        PUSH(x.first+1,x.second);
        PUSH(x.first-1,x.second);
        PUSH(x.first,x.second+1);
        PUSH(x.first,x.second-1);
    }
    hon=honfut;
}
bool vis[MAX][MAX]={};
bool testar(int x,int s) {
    hon.clear();
    memset(&proibido[0][0],0,sizeof(proibido));
    memset(&nobees[0][0],0,sizeof(nobees));
    memset(&vis[0][0],0,sizeof(vis));
    pii inicio,fim;
    for(int i=0;i!=N;++i){
        for(int j=0;j!=N;++j){
            if(mapa[i][j]=='H'){
                proibido[i][j]=true;
                hon.push_back({i,j});
            }else if(mapa[i][j]=='M') {
                inicio={i,j};
            }else if(mapa[i][j]=='D') {
                nobees[i][j]=true;
                fim={i,j};
            }else if(mapa[i][j]=='T'){
                nobees[i][j]=true;
                proibido[i][j]=true;
            }
        }
    }
    for(int i=0;i!=x;++i)avancar();
    std::queue<pip> queue;
    queue.push({0,inicio});
    int laste=0;
    while(queue.size()) {
        auto _ = queue.front();
        queue.pop();
        int mov = _.first/s;
        if(mov>laste){
            laste=mov;
            avancar();
        }
        if(vis[_.second.first][_.second.second]||proibido[_.second.first][_.second.second])continue;
        vis[_.second.first][_.second.second]=true;
        if(_.second==fim)return true;
        #define QPUSH(A,B) if(A>=0&&B>=0&&A<N&&B<N)queue.push({_.first+1,{A,B}});
        QPUSH(_.second.first+1,_.second.second);
        QPUSH(_.second.first-1,_.second.second);
        QPUSH(_.second.first,_.second.second+1);
        QPUSH(_.second.first,_.second.second-1);
    }
    return false;
}
int main()
{
    std::cin>>N>>K;
    for(int i=0;i!=N;++i)std::cin>>mapa[i];
    int l=0,r=N*N;
    while(l<r) {
        int m = (l+r)/2 + ((l+r)&1);
        if(testar(m,K)) {
            l=m;
        }else r=m-1;
    }
    std::cout<<l<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2380 KB Output is correct
2 Correct 2 ms 2380 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 2 ms 2380 KB Output is correct
5 Correct 2 ms 2380 KB Output is correct
6 Correct 2 ms 2380 KB Output is correct
7 Correct 422 ms 4288 KB Output is correct
8 Incorrect 3 ms 2380 KB Output isn't correct
9 Correct 2 ms 2380 KB Output is correct
10 Correct 2 ms 2380 KB Output is correct
11 Correct 2 ms 2380 KB Output is correct
12 Correct 4 ms 2380 KB Output is correct
13 Correct 3 ms 2380 KB Output is correct
14 Incorrect 5 ms 2380 KB Output isn't correct
15 Correct 3 ms 2380 KB Output is correct
16 Correct 2 ms 2380 KB Output is correct
17 Correct 2 ms 2380 KB Output is correct
18 Correct 3 ms 2380 KB Output is correct
19 Correct 2 ms 2380 KB Output is correct
20 Correct 2 ms 2380 KB Output is correct
21 Correct 2 ms 2384 KB Output is correct
22 Correct 3 ms 2380 KB Output is correct
23 Correct 3 ms 2376 KB Output is correct
24 Correct 3 ms 2380 KB Output is correct
25 Correct 3 ms 2380 KB Output is correct
26 Correct 3 ms 2384 KB Output is correct
27 Correct 3 ms 2380 KB Output is correct
28 Correct 5 ms 2380 KB Output is correct
29 Correct 5 ms 2380 KB Output is correct
30 Correct 4 ms 2380 KB Output is correct
31 Correct 4 ms 2380 KB Output is correct
32 Correct 4 ms 2380 KB Output is correct
33 Correct 49 ms 2636 KB Output is correct
34 Correct 45 ms 2636 KB Output is correct
35 Correct 70 ms 2764 KB Output is correct
36 Correct 69 ms 2772 KB Output is correct
37 Correct 68 ms 2776 KB Output is correct
38 Correct 94 ms 2796 KB Output is correct
39 Correct 78 ms 2836 KB Output is correct
40 Correct 85 ms 2764 KB Output is correct
41 Correct 123 ms 2892 KB Output is correct
42 Correct 113 ms 3148 KB Output is correct
43 Correct 143 ms 3164 KB Output is correct
44 Correct 159 ms 3200 KB Output is correct
45 Correct 131 ms 3268 KB Output is correct
46 Correct 136 ms 3240 KB Output is correct
47 Correct 211 ms 3312 KB Output is correct
48 Correct 148 ms 3276 KB Output is correct
49 Correct 145 ms 3356 KB Output is correct
50 Correct 227 ms 3416 KB Output is correct
51 Correct 191 ms 3452 KB Output is correct
52 Correct 213 ms 3560 KB Output is correct
53 Correct 262 ms 3532 KB Output is correct
54 Correct 206 ms 3532 KB Output is correct
55 Correct 253 ms 3508 KB Output is correct
56 Correct 292 ms 3632 KB Output is correct
57 Correct 243 ms 3680 KB Output is correct
58 Correct 230 ms 3660 KB Output is correct
59 Correct 346 ms 3788 KB Output is correct
60 Correct 270 ms 3804 KB Output is correct
61 Correct 273 ms 3924 KB Output is correct
62 Correct 403 ms 3824 KB Output is correct
63 Correct 370 ms 3836 KB Output is correct
64 Correct 515 ms 3908 KB Output is correct
65 Correct 428 ms 3820 KB Output is correct
66 Correct 415 ms 3948 KB Output is correct
67 Incorrect 408 ms 3908 KB Output isn't correct
68 Correct 310 ms 3936 KB Output is correct
69 Correct 287 ms 3916 KB Output is correct
70 Correct 313 ms 3980 KB Output is correct
71 Correct 303 ms 4036 KB Output is correct
72 Correct 306 ms 4052 KB Output is correct
73 Correct 228 ms 5008 KB Output is correct
74 Correct 323 ms 5016 KB Output is correct
75 Correct 369 ms 5112 KB Output is correct
76 Correct 371 ms 5100 KB Output is correct
77 Correct 369 ms 5212 KB Output is correct
78 Incorrect 365 ms 4828 KB Output isn't correct
79 Correct 308 ms 4832 KB Output is correct
80 Correct 343 ms 4936 KB Output is correct
81 Correct 356 ms 4868 KB Output is correct
82 Correct 335 ms 4844 KB Output is correct
83 Correct 380 ms 4660 KB Output is correct
84 Correct 373 ms 4576 KB Output is correct
85 Correct 392 ms 4656 KB Output is correct
86 Correct 387 ms 4568 KB Output is correct
87 Correct 367 ms 4656 KB Output is correct
88 Correct 369 ms 4544 KB Output is correct
89 Correct 399 ms 4588 KB Output is correct
90 Correct 429 ms 4584 KB Output is correct
91 Correct 382 ms 4544 KB Output is correct
92 Correct 369 ms 4548 KB Output is correct