# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
430130 |
2021-06-16T11:39:32 Z |
최서현(#7488) |
Brackets (CPSPC17_brackets) |
C++17 |
|
700 ms |
25272 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;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 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 |
15 ms |
1280 KB |
Output is correct |
30 |
Correct |
73 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 |
6 ms |
908 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
67 ms |
3592 KB |
Output is correct |
36 |
Correct |
18 ms |
912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 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 |
15 ms |
1280 KB |
Output is correct |
30 |
Correct |
73 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 |
6 ms |
908 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
67 ms |
3592 KB |
Output is correct |
36 |
Correct |
18 ms |
912 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
38 |
Correct |
178 ms |
6660 KB |
Output is correct |
39 |
Correct |
2 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
156 ms |
6740 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 |
169 ms |
6764 KB |
Output is correct |
46 |
Correct |
171 ms |
6764 KB |
Output is correct |
47 |
Correct |
4 ms |
588 KB |
Output is correct |
48 |
Correct |
187 ms |
3708 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
331 ms |
6824 KB |
Output is correct |
2 |
Correct |
346 ms |
6900 KB |
Output is correct |
3 |
Correct |
316 ms |
6828 KB |
Output is correct |
4 |
Correct |
339 ms |
6888 KB |
Output is correct |
5 |
Correct |
317 ms |
6828 KB |
Output is correct |
6 |
Correct |
305 ms |
6908 KB |
Output is correct |
7 |
Correct |
312 ms |
6800 KB |
Output is correct |
8 |
Correct |
355 ms |
6832 KB |
Output is correct |
9 |
Correct |
327 ms |
6832 KB |
Output is correct |
10 |
Correct |
308 ms |
6956 KB |
Output is correct |
11 |
Correct |
307 ms |
6832 KB |
Output is correct |
12 |
Correct |
298 ms |
6820 KB |
Output is correct |
13 |
Correct |
284 ms |
6844 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 |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 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 |
15 ms |
1280 KB |
Output is correct |
30 |
Correct |
73 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 |
6 ms |
908 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
67 ms |
3592 KB |
Output is correct |
36 |
Correct |
18 ms |
912 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
38 |
Correct |
178 ms |
6660 KB |
Output is correct |
39 |
Correct |
2 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
156 ms |
6740 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 |
169 ms |
6764 KB |
Output is correct |
46 |
Correct |
171 ms |
6764 KB |
Output is correct |
47 |
Correct |
4 ms |
588 KB |
Output is correct |
48 |
Correct |
187 ms |
3708 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
331 ms |
6824 KB |
Output is correct |
51 |
Correct |
346 ms |
6900 KB |
Output is correct |
52 |
Correct |
316 ms |
6828 KB |
Output is correct |
53 |
Correct |
339 ms |
6888 KB |
Output is correct |
54 |
Correct |
317 ms |
6828 KB |
Output is correct |
55 |
Correct |
305 ms |
6908 KB |
Output is correct |
56 |
Correct |
312 ms |
6800 KB |
Output is correct |
57 |
Correct |
355 ms |
6832 KB |
Output is correct |
58 |
Correct |
327 ms |
6832 KB |
Output is correct |
59 |
Correct |
308 ms |
6956 KB |
Output is correct |
60 |
Correct |
307 ms |
6832 KB |
Output is correct |
61 |
Correct |
298 ms |
6820 KB |
Output is correct |
62 |
Correct |
284 ms |
6844 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 |
460 KB |
Output is correct |
66 |
Correct |
2 ms |
588 KB |
Output is correct |
67 |
Execution timed out |
1080 ms |
25272 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |