답안 #429727

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429727 2021-06-16T08:58:01 Z 최서현(#7502) Brackets (CPSPC17_brackets) C++17
74 / 100
700 ms 25284 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}});
        }
    }

//    for(int i = 0; i < n; ++i)
//    {
//        for(int j = 0; j < n; ++j)
//            cout << C[i][j] << ' ';
//        cout << endl;
//    }

    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 8 ms 912 KB Output is correct
27 Correct 5 ms 460 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 14 ms 1224 KB Output is correct
30 Correct 70 ms 2116 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 7 ms 908 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 87 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 8 ms 912 KB Output is correct
27 Correct 5 ms 460 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 14 ms 1224 KB Output is correct
30 Correct 70 ms 2116 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 7 ms 908 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 87 ms 3648 KB Output is correct
36 Correct 18 ms 912 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 187 ms 6724 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 158 ms 6764 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 192 ms 6712 KB Output is correct
46 Correct 187 ms 6692 KB Output is correct
47 Correct 4 ms 588 KB Output is correct
48 Correct 177 ms 3640 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 330 ms 6828 KB Output is correct
2 Correct 364 ms 6848 KB Output is correct
3 Correct 319 ms 6896 KB Output is correct
4 Correct 331 ms 6952 KB Output is correct
5 Correct 307 ms 6880 KB Output is correct
6 Correct 315 ms 6824 KB Output is correct
7 Correct 309 ms 6832 KB Output is correct
8 Correct 332 ms 6864 KB Output is correct
9 Correct 408 ms 6864 KB Output is correct
10 Correct 303 ms 6812 KB Output is correct
11 Correct 294 ms 6832 KB Output is correct
12 Correct 366 ms 6828 KB Output is correct
13 Correct 282 ms 6828 KB Output is correct
14 Correct 4 ms 588 KB Output is correct
15 Correct 5 ms 592 KB Output is correct
16 Correct 1 ms 460 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 8 ms 912 KB Output is correct
27 Correct 5 ms 460 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 14 ms 1224 KB Output is correct
30 Correct 70 ms 2116 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 7 ms 908 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 87 ms 3648 KB Output is correct
36 Correct 18 ms 912 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 187 ms 6724 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 158 ms 6764 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 192 ms 6712 KB Output is correct
46 Correct 187 ms 6692 KB Output is correct
47 Correct 4 ms 588 KB Output is correct
48 Correct 177 ms 3640 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 330 ms 6828 KB Output is correct
51 Correct 364 ms 6848 KB Output is correct
52 Correct 319 ms 6896 KB Output is correct
53 Correct 331 ms 6952 KB Output is correct
54 Correct 307 ms 6880 KB Output is correct
55 Correct 315 ms 6824 KB Output is correct
56 Correct 309 ms 6832 KB Output is correct
57 Correct 332 ms 6864 KB Output is correct
58 Correct 408 ms 6864 KB Output is correct
59 Correct 303 ms 6812 KB Output is correct
60 Correct 294 ms 6832 KB Output is correct
61 Correct 366 ms 6828 KB Output is correct
62 Correct 282 ms 6828 KB Output is correct
63 Correct 4 ms 588 KB Output is correct
64 Correct 5 ms 592 KB Output is correct
65 Correct 1 ms 460 KB Output is correct
66 Correct 3 ms 588 KB Output is correct
67 Execution timed out 1089 ms 25284 KB Time limit exceeded
68 Halted 0 ms 0 KB -