Submission #430190

# Submission time Handle Problem Language Result Execution time Memory
430190 2021-06-16T11:59:21 Z 최서현(#7488) Brackets (CPSPC17_brackets) C++17
74 / 100
325 ms 277832 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;
const int MAX = 10101010;
vector<int> gph[202][8];
vector<int> rgph[202][8];
vector<pii> Q[MAX];

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;
    for(int i = 0; i < n; ++i) Q[0].push_back({i, i});

    for(int d = 0; d < MAX - 2; d += 2)
    {
        for(auto x : Q[d])
        {
            if(C[x.ff][x.ss] != INF) continue;
            C[x.ff][x.ss] = d;
            for(int i = 0; i < 8; i += 2)
                for(auto j : rgph[x.ff][i])
                    for(auto k : gph[x.ss][i + 1])
                        Q[d + 2].push_back({j, k});
            for(int i = 0; i < n; ++i)
            {
                if(min(MAX, C[i][x.ss]) > C[x.ff][x.ss] + C[i][x.ff])
                    Q[C[x.ff][x.ss] + C[i][x.ff]].push_back({i, x.ss});
                if(min(MAX, C[x.ff][i]) > C[x.ff][x.ss] + C[x.ss][i])
                    Q[C[x.ff][x.ss] + C[x.ss][i]].push_back({x.ff, 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:30:13: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |         int z;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 186 ms 237580 KB Output is correct
2 Correct 186 ms 237576 KB Output is correct
3 Correct 238 ms 237528 KB Output is correct
4 Correct 202 ms 237572 KB Output is correct
5 Correct 188 ms 237516 KB Output is correct
6 Correct 189 ms 237576 KB Output is correct
7 Correct 194 ms 237508 KB Output is correct
8 Correct 199 ms 237688 KB Output is correct
9 Correct 199 ms 237516 KB Output is correct
10 Correct 193 ms 237620 KB Output is correct
11 Correct 193 ms 237576 KB Output is correct
12 Correct 186 ms 237464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 237580 KB Output is correct
2 Correct 186 ms 237576 KB Output is correct
3 Correct 238 ms 237528 KB Output is correct
4 Correct 202 ms 237572 KB Output is correct
5 Correct 188 ms 237516 KB Output is correct
6 Correct 189 ms 237576 KB Output is correct
7 Correct 194 ms 237508 KB Output is correct
8 Correct 199 ms 237688 KB Output is correct
9 Correct 199 ms 237516 KB Output is correct
10 Correct 193 ms 237620 KB Output is correct
11 Correct 193 ms 237576 KB Output is correct
12 Correct 186 ms 237464 KB Output is correct
13 Correct 197 ms 237644 KB Output is correct
14 Correct 186 ms 237508 KB Output is correct
15 Correct 200 ms 237508 KB Output is correct
16 Correct 192 ms 237512 KB Output is correct
17 Correct 196 ms 237604 KB Output is correct
18 Correct 203 ms 237484 KB Output is correct
19 Correct 193 ms 237512 KB Output is correct
20 Correct 197 ms 237588 KB Output is correct
21 Correct 186 ms 237592 KB Output is correct
22 Correct 187 ms 237540 KB Output is correct
23 Correct 189 ms 237612 KB Output is correct
24 Correct 212 ms 237596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 237580 KB Output is correct
2 Correct 186 ms 237576 KB Output is correct
3 Correct 238 ms 237528 KB Output is correct
4 Correct 202 ms 237572 KB Output is correct
5 Correct 188 ms 237516 KB Output is correct
6 Correct 189 ms 237576 KB Output is correct
7 Correct 194 ms 237508 KB Output is correct
8 Correct 199 ms 237688 KB Output is correct
9 Correct 199 ms 237516 KB Output is correct
10 Correct 193 ms 237620 KB Output is correct
11 Correct 193 ms 237576 KB Output is correct
12 Correct 186 ms 237464 KB Output is correct
13 Correct 197 ms 237644 KB Output is correct
14 Correct 186 ms 237508 KB Output is correct
15 Correct 200 ms 237508 KB Output is correct
16 Correct 192 ms 237512 KB Output is correct
17 Correct 196 ms 237604 KB Output is correct
18 Correct 203 ms 237484 KB Output is correct
19 Correct 193 ms 237512 KB Output is correct
20 Correct 197 ms 237588 KB Output is correct
21 Correct 186 ms 237592 KB Output is correct
22 Correct 187 ms 237540 KB Output is correct
23 Correct 189 ms 237612 KB Output is correct
24 Correct 212 ms 237596 KB Output is correct
25 Correct 193 ms 237620 KB Output is correct
26 Correct 188 ms 237868 KB Output is correct
27 Correct 208 ms 238020 KB Output is correct
28 Correct 190 ms 237596 KB Output is correct
29 Correct 196 ms 238344 KB Output is correct
30 Correct 198 ms 240924 KB Output is correct
31 Correct 197 ms 237688 KB Output is correct
32 Correct 186 ms 237488 KB Output is correct
33 Correct 192 ms 237764 KB Output is correct
34 Correct 198 ms 237636 KB Output is correct
35 Correct 214 ms 240380 KB Output is correct
36 Correct 213 ms 238484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 237580 KB Output is correct
2 Correct 186 ms 237576 KB Output is correct
3 Correct 238 ms 237528 KB Output is correct
4 Correct 202 ms 237572 KB Output is correct
5 Correct 188 ms 237516 KB Output is correct
6 Correct 189 ms 237576 KB Output is correct
7 Correct 194 ms 237508 KB Output is correct
8 Correct 199 ms 237688 KB Output is correct
9 Correct 199 ms 237516 KB Output is correct
10 Correct 193 ms 237620 KB Output is correct
11 Correct 193 ms 237576 KB Output is correct
12 Correct 186 ms 237464 KB Output is correct
13 Correct 197 ms 237644 KB Output is correct
14 Correct 186 ms 237508 KB Output is correct
15 Correct 200 ms 237508 KB Output is correct
16 Correct 192 ms 237512 KB Output is correct
17 Correct 196 ms 237604 KB Output is correct
18 Correct 203 ms 237484 KB Output is correct
19 Correct 193 ms 237512 KB Output is correct
20 Correct 197 ms 237588 KB Output is correct
21 Correct 186 ms 237592 KB Output is correct
22 Correct 187 ms 237540 KB Output is correct
23 Correct 189 ms 237612 KB Output is correct
24 Correct 212 ms 237596 KB Output is correct
25 Correct 193 ms 237620 KB Output is correct
26 Correct 188 ms 237868 KB Output is correct
27 Correct 208 ms 238020 KB Output is correct
28 Correct 190 ms 237596 KB Output is correct
29 Correct 196 ms 238344 KB Output is correct
30 Correct 198 ms 240924 KB Output is correct
31 Correct 197 ms 237688 KB Output is correct
32 Correct 186 ms 237488 KB Output is correct
33 Correct 192 ms 237764 KB Output is correct
34 Correct 198 ms 237636 KB Output is correct
35 Correct 214 ms 240380 KB Output is correct
36 Correct 213 ms 238484 KB Output is correct
37 Correct 193 ms 237668 KB Output is correct
38 Correct 225 ms 244484 KB Output is correct
39 Correct 206 ms 237636 KB Output is correct
40 Correct 204 ms 237608 KB Output is correct
41 Correct 212 ms 244480 KB Output is correct
42 Correct 201 ms 237732 KB Output is correct
43 Correct 189 ms 237588 KB Output is correct
44 Correct 188 ms 237612 KB Output is correct
45 Correct 229 ms 244476 KB Output is correct
46 Correct 221 ms 244412 KB Output is correct
47 Correct 195 ms 237764 KB Output is correct
48 Correct 211 ms 244564 KB Output is correct
49 Correct 195 ms 237608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 233 ms 248600 KB Output is correct
2 Correct 249 ms 249164 KB Output is correct
3 Correct 226 ms 248700 KB Output is correct
4 Correct 225 ms 248356 KB Output is correct
5 Correct 238 ms 248364 KB Output is correct
6 Correct 249 ms 248152 KB Output is correct
7 Correct 242 ms 248300 KB Output is correct
8 Correct 236 ms 248832 KB Output is correct
9 Correct 258 ms 248016 KB Output is correct
10 Correct 223 ms 247708 KB Output is correct
11 Correct 235 ms 247788 KB Output is correct
12 Correct 236 ms 247736 KB Output is correct
13 Correct 238 ms 247124 KB Output is correct
14 Correct 194 ms 237892 KB Output is correct
15 Correct 203 ms 237844 KB Output is correct
16 Correct 207 ms 237744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 237580 KB Output is correct
2 Correct 186 ms 237576 KB Output is correct
3 Correct 238 ms 237528 KB Output is correct
4 Correct 202 ms 237572 KB Output is correct
5 Correct 188 ms 237516 KB Output is correct
6 Correct 189 ms 237576 KB Output is correct
7 Correct 194 ms 237508 KB Output is correct
8 Correct 199 ms 237688 KB Output is correct
9 Correct 199 ms 237516 KB Output is correct
10 Correct 193 ms 237620 KB Output is correct
11 Correct 193 ms 237576 KB Output is correct
12 Correct 186 ms 237464 KB Output is correct
13 Correct 197 ms 237644 KB Output is correct
14 Correct 186 ms 237508 KB Output is correct
15 Correct 200 ms 237508 KB Output is correct
16 Correct 192 ms 237512 KB Output is correct
17 Correct 196 ms 237604 KB Output is correct
18 Correct 203 ms 237484 KB Output is correct
19 Correct 193 ms 237512 KB Output is correct
20 Correct 197 ms 237588 KB Output is correct
21 Correct 186 ms 237592 KB Output is correct
22 Correct 187 ms 237540 KB Output is correct
23 Correct 189 ms 237612 KB Output is correct
24 Correct 212 ms 237596 KB Output is correct
25 Correct 193 ms 237620 KB Output is correct
26 Correct 188 ms 237868 KB Output is correct
27 Correct 208 ms 238020 KB Output is correct
28 Correct 190 ms 237596 KB Output is correct
29 Correct 196 ms 238344 KB Output is correct
30 Correct 198 ms 240924 KB Output is correct
31 Correct 197 ms 237688 KB Output is correct
32 Correct 186 ms 237488 KB Output is correct
33 Correct 192 ms 237764 KB Output is correct
34 Correct 198 ms 237636 KB Output is correct
35 Correct 214 ms 240380 KB Output is correct
36 Correct 213 ms 238484 KB Output is correct
37 Correct 193 ms 237668 KB Output is correct
38 Correct 225 ms 244484 KB Output is correct
39 Correct 206 ms 237636 KB Output is correct
40 Correct 204 ms 237608 KB Output is correct
41 Correct 212 ms 244480 KB Output is correct
42 Correct 201 ms 237732 KB Output is correct
43 Correct 189 ms 237588 KB Output is correct
44 Correct 188 ms 237612 KB Output is correct
45 Correct 229 ms 244476 KB Output is correct
46 Correct 221 ms 244412 KB Output is correct
47 Correct 195 ms 237764 KB Output is correct
48 Correct 211 ms 244564 KB Output is correct
49 Correct 195 ms 237608 KB Output is correct
50 Correct 233 ms 248600 KB Output is correct
51 Correct 249 ms 249164 KB Output is correct
52 Correct 226 ms 248700 KB Output is correct
53 Correct 225 ms 248356 KB Output is correct
54 Correct 238 ms 248364 KB Output is correct
55 Correct 249 ms 248152 KB Output is correct
56 Correct 242 ms 248300 KB Output is correct
57 Correct 236 ms 248832 KB Output is correct
58 Correct 258 ms 248016 KB Output is correct
59 Correct 223 ms 247708 KB Output is correct
60 Correct 235 ms 247788 KB Output is correct
61 Correct 236 ms 247736 KB Output is correct
62 Correct 238 ms 247124 KB Output is correct
63 Correct 194 ms 237892 KB Output is correct
64 Correct 203 ms 237844 KB Output is correct
65 Correct 207 ms 237744 KB Output is correct
66 Correct 212 ms 237796 KB Output is correct
67 Correct 315 ms 275008 KB Output is correct
68 Correct 300 ms 273436 KB Output is correct
69 Correct 325 ms 277832 KB Output is correct
70 Correct 215 ms 237816 KB Output is correct
71 Correct 198 ms 237892 KB Output is correct
72 Correct 286 ms 263080 KB Output is correct
73 Correct 288 ms 261792 KB Output is correct
74 Correct 204 ms 238060 KB Output is correct
75 Correct 301 ms 273908 KB Output is correct
76 Correct 191 ms 237992 KB Output is correct
77 Correct 203 ms 237772 KB Output is correct
78 Incorrect 190 ms 237636 KB Output isn't correct
79 Halted 0 ms 0 KB -