답안 #313758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313758 2020-10-16T23:59:36 Z Massiosare Mecho (IOI09_mecho) C++14
84 / 100
315 ms 6392 KB
#include <iostream>
#include <queue>

#define MAX 805

using namespace std;

struct coords{
    int fil;
    int col;
    int nivel;
    int temporal;
};

int best;
int maxpro;
coords pro,start;
int n,steps;
char mat[MAX][MAX];
bool visitados[MAX][MAX];
int valores[MAX][MAX];
queue <coords> q,q2;

void add(coords temp){
    coords temp2=temp;
    temp2.nivel++;
    //col+
    temp2.col++;
    q.push(temp2);
    temp2.col--;
    //fil+
    temp2.fil++;
    q.push(temp2);
    temp2.fil--;
    //col-
    temp2.col--;
    q.push(temp2);
    temp2.col++;
    //fil-
    temp2.fil--;
    q.push(temp2);
    temp2.fil++;
    return;
}

void add2(coords temp){
    coords temp2=temp;
    temp2.temporal++;
    if(temp2.temporal%steps==0){
        temp2.nivel++;
    }
    //col+
    temp2.col++;
    q2.push(temp2);
    temp2.col--;
    //fil+
    temp2.fil++;
    q2.push(temp2);
    temp2.fil--;
    //col-
    temp2.col--;
    q2.push(temp2);
    temp2.col++;
    //fil-
    temp2.fil--;
    q2.push(temp2);
    temp2.fil++;
    return;
}

bool busca2(){
    while(!q2.empty()){
        coords temp=q2.front();
        q2.pop();
        if(temp.col<1||temp.col>n||temp.fil>n||temp.fil<1){
            continue;
        }
        if(visitados[temp.fil][temp.col]==1||mat[temp.fil][temp.col]=='T'||mat[temp.fil][temp.col]=='H'){
            continue;
        }
        else {
            visitados[temp.fil][temp.col]=1;
        }
        if(valores[temp.fil][temp.col]<=temp.nivel){
            continue;
        }
        if(mat[temp.fil][temp.col]=='D'){
            if(valores[temp.fil][temp.col]<=temp.nivel){
                return 0;
            }
            return 1;
        }
        add2(temp);
    }
    return 0;
}

void binaria(int ini,int fin){
    while(ini<=fin){
        for(int i=1; i<=n; i++){
            for(int j=1; j<=n; j++){
                visitados[i][j]=0;
            }
        }
        while(!q2.empty()){
            q2.pop();
        }
        int mid=(ini+fin)/2;
        start.nivel=mid;
        q2.push(start);
        bool x=busca2();
        if(x==1){
            best=mid;
            ini=mid+1;
        }
        else {
            fin=mid-1;
        }
    }
    cout << best;
}

void busca(){
    while(!q.empty()){
        coords temp=q.front();
        q.pop();
        if(temp.col<1||temp.col>n||temp.fil>n||temp.fil<1||mat[temp.fil][temp.col]=='T'||mat[temp.fil][temp.col]=='D'){
            continue;
        }
        if(visitados[temp.fil][temp.col]==0){
            valores[temp.fil][temp.col]=temp.nivel;
            visitados[temp.fil][temp.col]=1;
        }
        else {
            continue;
        }
        if(mat[temp.fil][temp.col]=='M'){
            maxpro=valores[temp.fil][temp.col];
        }
        add(temp);
    }
    return;
}

int main()
{
    cin >> n >> steps;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            cin >> mat[i][j];
            if(mat[i][j]=='H'){
                pro.fil=i;
                pro.col=j;
                q.push(pro);
            }
            if(mat[i][j]=='M'){
                start.fil=i;
                start.col=j;
                start.nivel=0;
            }
            if(mat[i][j]=='D'){
                valores[i][j]=99999999;
            }
        }
    }
    busca();
    binaria(1,maxpro);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 198 ms 4948 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 640 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Incorrect 1 ms 640 KB Output isn't correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 640 KB Output is correct
27 Correct 1 ms 640 KB Output is correct
28 Correct 1 ms 640 KB Output is correct
29 Correct 1 ms 640 KB Output is correct
30 Correct 1 ms 640 KB Output is correct
31 Correct 1 ms 672 KB Output is correct
32 Correct 1 ms 640 KB Output is correct
33 Correct 16 ms 1920 KB Output is correct
34 Correct 17 ms 1920 KB Output is correct
35 Correct 46 ms 2048 KB Output is correct
36 Correct 20 ms 2176 KB Output is correct
37 Correct 21 ms 2176 KB Output is correct
38 Correct 64 ms 2296 KB Output is correct
39 Correct 26 ms 2432 KB Output is correct
40 Correct 27 ms 2552 KB Output is correct
41 Correct 79 ms 2552 KB Output is correct
42 Correct 31 ms 2688 KB Output is correct
43 Correct 32 ms 2680 KB Output is correct
44 Correct 98 ms 2688 KB Output is correct
45 Correct 37 ms 2936 KB Output is correct
46 Correct 38 ms 2936 KB Output is correct
47 Correct 124 ms 2940 KB Output is correct
48 Correct 44 ms 3320 KB Output is correct
49 Correct 45 ms 3192 KB Output is correct
50 Correct 146 ms 3320 KB Output is correct
51 Correct 52 ms 3448 KB Output is correct
52 Correct 53 ms 3448 KB Output is correct
53 Correct 174 ms 3456 KB Output is correct
54 Correct 60 ms 3576 KB Output is correct
55 Correct 61 ms 3648 KB Output is correct
56 Correct 208 ms 3832 KB Output is correct
57 Correct 69 ms 3832 KB Output is correct
58 Correct 71 ms 3832 KB Output is correct
59 Correct 232 ms 4088 KB Output is correct
60 Correct 84 ms 4216 KB Output is correct
61 Correct 78 ms 4104 KB Output is correct
62 Correct 270 ms 4344 KB Output is correct
63 Correct 196 ms 4088 KB Output is correct
64 Correct 315 ms 4196 KB Output is correct
65 Correct 298 ms 4216 KB Output is correct
66 Correct 275 ms 4216 KB Output is correct
67 Incorrect 232 ms 4088 KB Output isn't correct
68 Correct 128 ms 4344 KB Output is correct
69 Correct 110 ms 4332 KB Output is correct
70 Correct 110 ms 4472 KB Output is correct
71 Correct 107 ms 4376 KB Output is correct
72 Correct 97 ms 4344 KB Output is correct
73 Correct 108 ms 6264 KB Output is correct
74 Correct 186 ms 6264 KB Output is correct
75 Correct 181 ms 6392 KB Output is correct
76 Correct 172 ms 6264 KB Output is correct
77 Correct 173 ms 6264 KB Output is correct
78 Incorrect 187 ms 5720 KB Output isn't correct
79 Correct 145 ms 5720 KB Output is correct
80 Correct 173 ms 5720 KB Output is correct
81 Correct 196 ms 5840 KB Output is correct
82 Correct 167 ms 5720 KB Output is correct
83 Correct 196 ms 5804 KB Output is correct
84 Correct 226 ms 5672 KB Output is correct
85 Correct 184 ms 5672 KB Output is correct
86 Correct 221 ms 5800 KB Output is correct
87 Correct 192 ms 5672 KB Output is correct
88 Correct 186 ms 4972 KB Output is correct
89 Correct 198 ms 4972 KB Output is correct
90 Correct 210 ms 4976 KB Output is correct
91 Correct 208 ms 5100 KB Output is correct
92 Correct 208 ms 5100 KB Output is correct