Submission #535596

# Submission time Handle Problem Language Result Execution time Memory
535596 2022-03-10T16:12:41 Z louiskwok Mecho (IOI09_mecho) C++17
39 / 100
1000 ms 9292 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=mxtime+1;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]
# Verdict Execution time Memory Grader output
1 Correct 1 ms 852 KB Output is correct
2 Incorrect 1 ms 980 KB Output isn't correct
3 Correct 1 ms 852 KB Output is correct
4 Incorrect 1 ms 980 KB Output isn't correct
5 Correct 1 ms 980 KB Output is correct
6 Incorrect 1 ms 980 KB Output isn't correct
7 Execution timed out 1080 ms 6280 KB Time limit exceeded
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Incorrect 4 ms 1364 KB Output isn't correct
13 Incorrect 2 ms 1236 KB Output isn't correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 2 ms 1108 KB Output is correct
22 Correct 2 ms 1108 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 2 ms 1108 KB Output is correct
26 Correct 2 ms 1108 KB Output is correct
27 Correct 3 ms 1108 KB Output is correct
28 Correct 2 ms 1108 KB Output is correct
29 Correct 4 ms 1108 KB Output is correct
30 Correct 2 ms 1236 KB Output is correct
31 Correct 2 ms 1248 KB Output is correct
32 Correct 3 ms 1180 KB Output is correct
33 Correct 16 ms 2224 KB Output is correct
34 Correct 12 ms 2296 KB Output is correct
35 Correct 323 ms 4472 KB Output is correct
36 Correct 18 ms 2516 KB Output is correct
37 Correct 17 ms 2532 KB Output is correct
38 Correct 523 ms 5100 KB Output is correct
39 Correct 23 ms 2664 KB Output is correct
40 Correct 19 ms 2724 KB Output is correct
41 Correct 640 ms 5512 KB Output is correct
42 Correct 26 ms 2900 KB Output is correct
43 Correct 22 ms 2900 KB Output is correct
44 Correct 859 ms 5992 KB Output is correct
45 Correct 29 ms 3028 KB Output is correct
46 Correct 27 ms 3028 KB Output is correct
47 Execution timed out 1093 ms 6432 KB Time limit exceeded
48 Correct 36 ms 3388 KB Output is correct
49 Correct 29 ms 3252 KB Output is correct
50 Execution timed out 1083 ms 6992 KB Time limit exceeded
51 Correct 37 ms 3488 KB Output is correct
52 Correct 32 ms 3452 KB Output is correct
53 Execution timed out 1095 ms 7460 KB Time limit exceeded
54 Correct 45 ms 3664 KB Output is correct
55 Correct 40 ms 3732 KB Output is correct
56 Execution timed out 1094 ms 7952 KB Time limit exceeded
57 Correct 50 ms 3788 KB Output is correct
58 Correct 44 ms 3904 KB Output is correct
59 Execution timed out 1094 ms 8584 KB Time limit exceeded
60 Correct 55 ms 3992 KB Output is correct
61 Correct 48 ms 3988 KB Output is correct
62 Execution timed out 1081 ms 8960 KB Time limit exceeded
63 Execution timed out 1094 ms 6388 KB Time limit exceeded
64 Execution timed out 1096 ms 6984 KB Time limit exceeded
65 Execution timed out 1096 ms 6988 KB Time limit exceeded
66 Execution timed out 1083 ms 6488 KB Time limit exceeded
67 Execution timed out 1090 ms 6308 KB Time limit exceeded
68 Correct 138 ms 8616 KB Output is correct
69 Correct 81 ms 8712 KB Output is correct
70 Correct 79 ms 8504 KB Output is correct
71 Correct 81 ms 8396 KB Output is correct
72 Incorrect 58 ms 4648 KB Output isn't correct
73 Incorrect 65 ms 9292 KB Output isn't correct
74 Correct 280 ms 8700 KB Output is correct
75 Correct 582 ms 9012 KB Output is correct
76 Correct 507 ms 8908 KB Output is correct
77 Correct 501 ms 8956 KB Output is correct
78 Execution timed out 1036 ms 6796 KB Time limit exceeded
79 Correct 165 ms 5964 KB Output is correct
80 Correct 344 ms 6156 KB Output is correct
81 Correct 739 ms 6304 KB Output is correct
82 Correct 385 ms 6092 KB Output is correct
83 Execution timed out 1094 ms 6784 KB Time limit exceeded
84 Correct 575 ms 6420 KB Output is correct
85 Correct 323 ms 6476 KB Output is correct
86 Correct 770 ms 6852 KB Output is correct
87 Correct 694 ms 6576 KB Output is correct
88 Correct 982 ms 7012 KB Output is correct
89 Correct 675 ms 6732 KB Output is correct
90 Execution timed out 1051 ms 6684 KB Time limit exceeded
91 Correct 857 ms 6684 KB Output is correct
92 Execution timed out 1048 ms 6944 KB Time limit exceeded