답안 #430576

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430576 2021-06-16T16:31:42 Z CodePlatina Brackets (CPSPC17_brackets) C++17
74 / 100
700 ms 25412 KB
#include <iostream>
#include <vector>
#include <queue>
#define pii pair<int, int>
#define piii pair<int, pii>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss

using namespace std;

const int INF = (int)1e9 + 7;
vector<int> gph[202][8];
vector<int> rgph[202][8];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

//    freopen("in.txt", "r", stdin);

    int n, m, s, e; cin >> n >> m >> s >> e; --s; --e;
    for(int i = 0; i < m; ++i)
    {
        int x, y; char c; cin >> x >> y >> c; --x; --y;
        int z;
        if(c == '<') z = 0;
        if(c == '>') z = 1;
        if(c == '{') z = 2;
        if(c == '}') z = 3;
        if(c == '[') z = 4;
        if(c == ']') z = 5;
        if(c == '(') z = 6;
        if(c == ')') z = 7;
        gph[x][z].push_back(y);
        rgph[y][z].push_back(x);
    }

    int C[n][n];
    for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) C[i][j] = INF;
    priority_queue<piii, vector<piii>, greater<piii>> Q;
    for(int i = 0; i < n; ++i) Q.push({0, {i, i}});

    while(Q.size())
    {
        auto x = Q.top(); Q.pop();
        if(C[x.ee][x.rr] != INF) continue;
        C[x.ee][x.rr] = x.ff;
        for(int i = 0; i < 8; i += 2)
            for(auto j : rgph[x.ee][i])
                for(auto k : gph[x.rr][i + 1])
                    Q.push({x.ff + 2, {j, k}});
        for(int i = 0; i < n; ++i)
        {
            if(C[i][x.rr] > C[x.ee][x.rr] + C[i][x.ee])
                Q.push({C[x.ee][x.rr] + C[i][x.ee], {i, x.rr}});
            if(C[x.ee][i] > C[x.ee][x.rr] + C[x.rr][i])
                Q.push({C[x.ee][x.rr] + C[x.rr][i], {x.ee, i}});
        }
    }

    cout << (C[s][e] == INF ? -1 : C[s][e]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:28:13: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
   28 |         int z;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 9 ms 912 KB Output is correct
27 Correct 5 ms 460 KB Output is correct
28 Correct 1 ms 380 KB Output is correct
29 Correct 14 ms 1224 KB Output is correct
30 Correct 70 ms 2060 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 6 ms 908 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 70 ms 3648 KB Output is correct
36 Correct 18 ms 912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 9 ms 912 KB Output is correct
27 Correct 5 ms 460 KB Output is correct
28 Correct 1 ms 380 KB Output is correct
29 Correct 14 ms 1224 KB Output is correct
30 Correct 70 ms 2060 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 6 ms 908 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 70 ms 3648 KB Output is correct
36 Correct 18 ms 912 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 153 ms 6684 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 152 ms 6728 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 151 ms 6712 KB Output is correct
46 Correct 221 ms 6776 KB Output is correct
47 Correct 4 ms 588 KB Output is correct
48 Correct 180 ms 3696 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 335 ms 6880 KB Output is correct
2 Correct 335 ms 6832 KB Output is correct
3 Correct 318 ms 6908 KB Output is correct
4 Correct 330 ms 6784 KB Output is correct
5 Correct 306 ms 6832 KB Output is correct
6 Correct 384 ms 6828 KB Output is correct
7 Correct 302 ms 6872 KB Output is correct
8 Correct 339 ms 6916 KB Output is correct
9 Correct 316 ms 6824 KB Output is correct
10 Correct 295 ms 6868 KB Output is correct
11 Correct 301 ms 6836 KB Output is correct
12 Correct 314 ms 6920 KB Output is correct
13 Correct 274 ms 6812 KB Output is correct
14 Correct 4 ms 588 KB Output is correct
15 Correct 5 ms 588 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 9 ms 912 KB Output is correct
27 Correct 5 ms 460 KB Output is correct
28 Correct 1 ms 380 KB Output is correct
29 Correct 14 ms 1224 KB Output is correct
30 Correct 70 ms 2060 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 6 ms 908 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 70 ms 3648 KB Output is correct
36 Correct 18 ms 912 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 153 ms 6684 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 152 ms 6728 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 151 ms 6712 KB Output is correct
46 Correct 221 ms 6776 KB Output is correct
47 Correct 4 ms 588 KB Output is correct
48 Correct 180 ms 3696 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 335 ms 6880 KB Output is correct
51 Correct 335 ms 6832 KB Output is correct
52 Correct 318 ms 6908 KB Output is correct
53 Correct 330 ms 6784 KB Output is correct
54 Correct 306 ms 6832 KB Output is correct
55 Correct 384 ms 6828 KB Output is correct
56 Correct 302 ms 6872 KB Output is correct
57 Correct 339 ms 6916 KB Output is correct
58 Correct 316 ms 6824 KB Output is correct
59 Correct 295 ms 6868 KB Output is correct
60 Correct 301 ms 6836 KB Output is correct
61 Correct 314 ms 6920 KB Output is correct
62 Correct 274 ms 6812 KB Output is correct
63 Correct 4 ms 588 KB Output is correct
64 Correct 5 ms 588 KB Output is correct
65 Correct 1 ms 468 KB Output is correct
66 Correct 2 ms 588 KB Output is correct
67 Execution timed out 1089 ms 25412 KB Time limit exceeded
68 Halted 0 ms 0 KB -