답안 #535598

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535598 2022-03-10T16:18:32 Z louiskwok Mecho (IOI09_mecho) C++17
0 / 100
1000 ms 4356 KB
#include <bits/stdc++.h>
using namespace std;
bool visited[805][805];
int distBee[805][805];
double distBear[805][805];
char g[805][805];
int dr[] = {-1,0,1,0};
int dc[] = {0,1,0,-1};
int mxtime;
int main() {
    queue < pair<int,int> > bfs;
    int n,sr,sc,er,ec;
    double s;
    cin >> n >> s;
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=n;j++) {
            cin >> g[i][j];
            if (g[i][j]=='M') sr = i,sc = j;
            else if (g[i][j]=='D') er = i,ec = j;
            else if (g[i][j]=='H') {
                visited[i][j] = true;
                bfs.push({i,j});
            }
        }
    }
    while (!bfs.empty()) {
        int curR = bfs.front().first;
        int curC = bfs.front().second;
        bfs.pop();
        for (int i=0;i<4;i++) {
            int nr = curR + dr[i];
            int nc = curC + dc[i];
            if (nr<1||nr>n||nc<1||nc>n||visited[nr][nc]||g[nr][nc]=='T') continue;
            visited[nr][nc] = true;
            distBee[nr][nc] = distBee[curR][curC]+1;
            mxtime = max(mxtime,distBee[nr][nc]);
            bfs.push({nr,nc});
        }
    }
    for (int i=max(100000,mxtime);i>=0;i--) {
        memset(visited,0,sizeof visited);
        distBear[sr][sc] = i;
        bfs.push({sr,sc});
        while (!bfs.empty()) {
            int curR = bfs.front().first;
            int curC = bfs.front().second;
            bfs.pop();
            for (int i=0;i<4;i++) {
                int nr = curR + dr[i];
                int nc = curC + dc[i];
                if (nr<1||nr>n||nc<1||nc>n||visited[nr][nc]||g[nr][nc]=='T'||distBear[curR][curC]+(double)1/s>=(double)distBee[nr][nc]) continue;
                visited[nr][nc] = true;
                distBear[nr][nc] = distBear[curR][curC]+1/s;
                bfs.push({nr,nc});
            }
        }
        if (visited[er][ec]) return cout << i << endl,0;
    }
    cout << -1 << endl;
    return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:57:27: warning: 'ec' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |         if (visited[er][ec]) return cout << i << endl,0;
      |             ~~~~~~~~~~~~~~^
mecho.cpp:57:27: warning: 'er' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 852 KB Time limit exceeded
2 Execution timed out 1093 ms 852 KB Time limit exceeded
3 Execution timed out 1067 ms 852 KB Time limit exceeded
4 Execution timed out 1081 ms 852 KB Time limit exceeded
5 Execution timed out 1094 ms 852 KB Time limit exceeded
6 Execution timed out 1099 ms 980 KB Time limit exceeded
7 Execution timed out 1097 ms 4108 KB Time limit exceeded
8 Execution timed out 1096 ms 980 KB Time limit exceeded
9 Execution timed out 1099 ms 980 KB Time limit exceeded
10 Execution timed out 1093 ms 980 KB Time limit exceeded
11 Execution timed out 1093 ms 980 KB Time limit exceeded
12 Execution timed out 1076 ms 1108 KB Time limit exceeded
13 Execution timed out 1048 ms 1108 KB Time limit exceeded
14 Execution timed out 1097 ms 1108 KB Time limit exceeded
15 Execution timed out 1093 ms 980 KB Time limit exceeded
16 Execution timed out 1102 ms 980 KB Time limit exceeded
17 Execution timed out 1099 ms 980 KB Time limit exceeded
18 Execution timed out 1095 ms 980 KB Time limit exceeded
19 Execution timed out 1094 ms 980 KB Time limit exceeded
20 Execution timed out 1093 ms 980 KB Time limit exceeded
21 Execution timed out 1096 ms 980 KB Time limit exceeded
22 Execution timed out 1098 ms 1108 KB Time limit exceeded
23 Execution timed out 1069 ms 1108 KB Time limit exceeded
24 Execution timed out 1095 ms 1108 KB Time limit exceeded
25 Execution timed out 1088 ms 1108 KB Time limit exceeded
26 Execution timed out 1094 ms 1108 KB Time limit exceeded
27 Execution timed out 1084 ms 1168 KB Time limit exceeded
28 Execution timed out 1096 ms 1120 KB Time limit exceeded
29 Execution timed out 1090 ms 1108 KB Time limit exceeded
30 Execution timed out 1092 ms 1108 KB Time limit exceeded
31 Execution timed out 1093 ms 1236 KB Time limit exceeded
32 Execution timed out 1082 ms 1236 KB Time limit exceeded
33 Correct 669 ms 2304 KB Output is correct
34 Execution timed out 1071 ms 2260 KB Time limit exceeded
35 Execution timed out 1088 ms 2260 KB Time limit exceeded
36 Correct 395 ms 2516 KB Output is correct
37 Execution timed out 1012 ms 2512 KB Time limit exceeded
38 Execution timed out 1076 ms 2492 KB Time limit exceeded
39 Correct 22 ms 2584 KB Output is correct
40 Correct 813 ms 2716 KB Output is correct
41 Execution timed out 1099 ms 2644 KB Time limit exceeded
42 Correct 33 ms 2900 KB Output is correct
43 Correct 616 ms 2900 KB Output is correct
44 Execution timed out 1095 ms 2900 KB Time limit exceeded
45 Correct 33 ms 3144 KB Output is correct
46 Correct 417 ms 3096 KB Output is correct
47 Execution timed out 1083 ms 3044 KB Time limit exceeded
48 Correct 37 ms 3276 KB Output is correct
49 Correct 210 ms 3292 KB Output is correct
50 Execution timed out 1084 ms 3272 KB Time limit exceeded
51 Correct 40 ms 3404 KB Output is correct
52 Correct 41 ms 3412 KB Output is correct
53 Execution timed out 1098 ms 3404 KB Time limit exceeded
54 Correct 45 ms 3652 KB Output is correct
55 Correct 45 ms 3680 KB Output is correct
56 Execution timed out 1088 ms 3664 KB Time limit exceeded
57 Correct 49 ms 3852 KB Output is correct
58 Correct 45 ms 3788 KB Output is correct
59 Execution timed out 1097 ms 3844 KB Time limit exceeded
60 Correct 65 ms 4028 KB Output is correct
61 Correct 51 ms 4072 KB Output is correct
62 Execution timed out 1092 ms 3956 KB Time limit exceeded
63 Execution timed out 1084 ms 4096 KB Time limit exceeded
64 Execution timed out 1095 ms 3960 KB Time limit exceeded
65 Execution timed out 1097 ms 3960 KB Time limit exceeded
66 Execution timed out 1085 ms 4076 KB Time limit exceeded
67 Execution timed out 1097 ms 4004 KB Time limit exceeded
68 Execution timed out 1094 ms 4004 KB Time limit exceeded
69 Execution timed out 1099 ms 4104 KB Time limit exceeded
70 Execution timed out 1100 ms 4044 KB Time limit exceeded
71 Execution timed out 1090 ms 4100 KB Time limit exceeded
72 Execution timed out 1092 ms 3992 KB Time limit exceeded
73 Execution timed out 1088 ms 4300 KB Time limit exceeded
74 Execution timed out 1096 ms 4356 KB Time limit exceeded
75 Execution timed out 1089 ms 4284 KB Time limit exceeded
76 Execution timed out 1061 ms 4300 KB Time limit exceeded
77 Execution timed out 1100 ms 4260 KB Time limit exceeded
78 Execution timed out 1084 ms 4240 KB Time limit exceeded
79 Execution timed out 1086 ms 4224 KB Time limit exceeded
80 Execution timed out 1087 ms 4304 KB Time limit exceeded
81 Execution timed out 1093 ms 4264 KB Time limit exceeded
82 Execution timed out 1060 ms 4328 KB Time limit exceeded
83 Execution timed out 1093 ms 4216 KB Time limit exceeded
84 Execution timed out 1047 ms 4216 KB Time limit exceeded
85 Execution timed out 1096 ms 4176 KB Time limit exceeded
86 Execution timed out 1097 ms 4204 KB Time limit exceeded
87 Execution timed out 1097 ms 4168 KB Time limit exceeded
88 Execution timed out 1084 ms 4116 KB Time limit exceeded
89 Execution timed out 1088 ms 4236 KB Time limit exceeded
90 Execution timed out 1096 ms 4156 KB Time limit exceeded
91 Execution timed out 1084 ms 4144 KB Time limit exceeded
92 Execution timed out 1089 ms 4176 KB Time limit exceeded