답안 #1051112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051112 2024-08-09T20:02:43 Z kvintsekstakord Mecho (IOI09_mecho) C++17
80 / 100
116 ms 7620 KB
#include <bits/stdc++.h>
#define int int64_t
using namespace std;

int N, S;
char forest[810][810];
int btime[810][810];
bool visited[810][810];

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

struct src{
    int x, y;
    int step;
    src(int x, int y, int step) : x(x), y(y), step(step){};
};

int32_t main()
{
    cin >> N >> S;
    queue<src> bfs;
    int si, sj;
    int hi, hj;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            cin >> forest[i][j];
            btime[i][j]=1e9;

            if(forest[i][j]=='H'){
                bfs.push(src(i, j, 0));
                btime[i][j]=0;
            }
            if(forest[i][j]=='M'){
                si = i;
                sj = j;
            }
            if(forest[i][j]=='D'){
                hi=i; hj=j;
            }

        }
    }

    while(!bfs.empty()){
        int x = bfs.front().x;
        int y = bfs.front().y;
        int step = bfs.front().step;
        bfs.pop();
        for(int i = 0; i < 4; i++){
            int nx = x+dx[i];
            int ny = y+dy[i];
            if(nx<1 || nx>N || ny<1 || ny>N) continue;
            if(forest[nx][ny]=='T' || forest[nx][ny]=='D') continue;
            if(step+1<btime[nx][ny]){
                btime[nx][ny]=(step+1);
                bfs.push(src(nx, ny, step+1));
            }
        }
    }
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            btime[i][j]*=S;
        }
    }
    int lo = 0;
    int hig = N*N;
    lo--;
    while(lo<hig){
        int mid = lo+(hig-lo+1)/2;

        queue<src> bfs2;
        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= N; j++){
                visited[i][j]=false;
            }
        }
        visited[si][sj]=true;
        if(mid>0) bfs2.push({si, sj, mid*S});
        else bfs2.push({si, sj, -S});
        bool possible = false;
        while(!bfs2.empty()){
            int x = bfs2.front().x;
            int y = bfs2.front().y;
            int step = bfs2.front().step;

            bfs2.pop();
            for(int i = 0; i < 4; i++){
                int nx = x+dx[i];
                int ny = y+dy[i];
                if(nx<1 || nx>N || ny<1 || ny>N) continue;
                if(forest[nx][ny]=='T') continue;
                if(forest[nx][ny]=='D'){
                    possible = true;
                    break;
                }
                if(visited[nx][ny]) continue;
                if( step+1<btime[nx][ny]){
                    visited[nx][ny]=true;
                    bfs2.push(src(nx, ny, step+1));
                }
            }
            if(possible) break;
        }

        if(possible){
            lo = mid;
        }else{
            hig = mid-1;
        }
    }
    cout << lo;

    return 0;
}

Compilation message

mecho.cpp: In function 'int32_t main()':
mecho.cpp:24:9: warning: variable 'hi' set but not used [-Wunused-but-set-variable]
   24 |     int hi, hj;
      |         ^~
mecho.cpp:24:13: warning: variable 'hj' set but not used [-Wunused-but-set-variable]
   24 |     int hi, hj;
      |             ^~
mecho.cpp:16:56: warning: 'sj' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |     src(int x, int y, int step) : x(x), y(y), step(step){};
      |                                                        ^
mecho.cpp:23:13: note: 'sj' was declared here
   23 |     int si, sj;
      |             ^~
mecho.cpp:16:56: warning: 'si' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |     src(int x, int y, int step) : x(x), y(y), step(step){};
      |                                                        ^
mecho.cpp:23:9: note: 'si' was declared here
   23 |     int si, sj;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 52 ms 7148 KB Output is correct
8 Incorrect 0 ms 4440 KB Output isn't correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Incorrect 0 ms 4444 KB Output isn't correct
13 Incorrect 1 ms 4444 KB Output isn't correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 0 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4440 KB Output is correct
33 Correct 4 ms 6748 KB Output is correct
34 Correct 4 ms 6748 KB Output is correct
35 Correct 12 ms 6592 KB Output is correct
36 Correct 5 ms 6748 KB Output is correct
37 Correct 5 ms 6748 KB Output is correct
38 Correct 17 ms 6592 KB Output is correct
39 Correct 7 ms 6588 KB Output is correct
40 Correct 7 ms 6748 KB Output is correct
41 Correct 26 ms 6792 KB Output is correct
42 Correct 8 ms 6748 KB Output is correct
43 Correct 8 ms 6600 KB Output is correct
44 Correct 26 ms 6596 KB Output is correct
45 Correct 10 ms 6744 KB Output is correct
46 Correct 9 ms 6592 KB Output is correct
47 Correct 36 ms 6744 KB Output is correct
48 Correct 11 ms 6748 KB Output is correct
49 Correct 11 ms 6596 KB Output is correct
50 Correct 36 ms 6588 KB Output is correct
51 Correct 13 ms 6748 KB Output is correct
52 Correct 13 ms 6600 KB Output is correct
53 Correct 43 ms 6748 KB Output is correct
54 Correct 16 ms 6748 KB Output is correct
55 Correct 16 ms 6748 KB Output is correct
56 Correct 53 ms 6604 KB Output is correct
57 Correct 20 ms 6740 KB Output is correct
58 Correct 18 ms 6748 KB Output is correct
59 Correct 59 ms 6812 KB Output is correct
60 Correct 21 ms 6748 KB Output is correct
61 Correct 23 ms 6748 KB Output is correct
62 Correct 67 ms 6748 KB Output is correct
63 Correct 66 ms 6748 KB Output is correct
64 Correct 116 ms 6740 KB Output is correct
65 Correct 96 ms 6736 KB Output is correct
66 Correct 88 ms 6740 KB Output is correct
67 Correct 76 ms 6740 KB Output is correct
68 Correct 40 ms 6748 KB Output is correct
69 Correct 37 ms 6748 KB Output is correct
70 Correct 32 ms 6748 KB Output is correct
71 Correct 37 ms 6748 KB Output is correct
72 Incorrect 28 ms 6744 KB Output isn't correct
73 Incorrect 31 ms 7504 KB Output isn't correct
74 Correct 41 ms 7488 KB Output is correct
75 Correct 45 ms 7620 KB Output is correct
76 Correct 42 ms 7512 KB Output is correct
77 Correct 43 ms 7516 KB Output is correct
78 Correct 50 ms 7516 KB Output is correct
79 Correct 36 ms 7504 KB Output is correct
80 Correct 41 ms 7512 KB Output is correct
81 Correct 46 ms 7508 KB Output is correct
82 Correct 41 ms 7416 KB Output is correct
83 Correct 50 ms 7260 KB Output is correct
84 Correct 46 ms 7260 KB Output is correct
85 Correct 52 ms 7256 KB Output is correct
86 Correct 52 ms 7296 KB Output is correct
87 Correct 50 ms 7256 KB Output is correct
88 Correct 51 ms 7152 KB Output is correct
89 Correct 51 ms 7308 KB Output is correct
90 Correct 52 ms 7108 KB Output is correct
91 Correct 52 ms 7148 KB Output is correct
92 Correct 55 ms 7260 KB Output is correct