# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
430169 |
2021-06-16T11:51:10 Z |
최서현(#7488) |
Brackets (CPSPC17_brackets) |
C++17 |
|
199 ms |
193308 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];
vector<pii> Q[4040404];
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 < 4040404; 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(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(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:29:13: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
29 | int z;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
95204 KB |
Output is correct |
2 |
Correct |
81 ms |
95248 KB |
Output is correct |
3 |
Correct |
82 ms |
95168 KB |
Output is correct |
4 |
Correct |
87 ms |
95256 KB |
Output is correct |
5 |
Correct |
84 ms |
95252 KB |
Output is correct |
6 |
Correct |
86 ms |
95132 KB |
Output is correct |
7 |
Correct |
85 ms |
95160 KB |
Output is correct |
8 |
Correct |
84 ms |
95284 KB |
Output is correct |
9 |
Correct |
84 ms |
95244 KB |
Output is correct |
10 |
Correct |
85 ms |
95184 KB |
Output is correct |
11 |
Correct |
86 ms |
95256 KB |
Output is correct |
12 |
Correct |
85 ms |
95248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
95204 KB |
Output is correct |
2 |
Correct |
81 ms |
95248 KB |
Output is correct |
3 |
Correct |
82 ms |
95168 KB |
Output is correct |
4 |
Correct |
87 ms |
95256 KB |
Output is correct |
5 |
Correct |
84 ms |
95252 KB |
Output is correct |
6 |
Correct |
86 ms |
95132 KB |
Output is correct |
7 |
Correct |
85 ms |
95160 KB |
Output is correct |
8 |
Correct |
84 ms |
95284 KB |
Output is correct |
9 |
Correct |
84 ms |
95244 KB |
Output is correct |
10 |
Correct |
85 ms |
95184 KB |
Output is correct |
11 |
Correct |
86 ms |
95256 KB |
Output is correct |
12 |
Correct |
85 ms |
95248 KB |
Output is correct |
13 |
Correct |
82 ms |
95140 KB |
Output is correct |
14 |
Correct |
83 ms |
95180 KB |
Output is correct |
15 |
Correct |
91 ms |
95268 KB |
Output is correct |
16 |
Correct |
83 ms |
95252 KB |
Output is correct |
17 |
Correct |
81 ms |
95160 KB |
Output is correct |
18 |
Correct |
83 ms |
95252 KB |
Output is correct |
19 |
Correct |
92 ms |
95252 KB |
Output is correct |
20 |
Correct |
93 ms |
95204 KB |
Output is correct |
21 |
Correct |
83 ms |
95208 KB |
Output is correct |
22 |
Correct |
95 ms |
95192 KB |
Output is correct |
23 |
Correct |
88 ms |
95248 KB |
Output is correct |
24 |
Correct |
86 ms |
95340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
95204 KB |
Output is correct |
2 |
Correct |
81 ms |
95248 KB |
Output is correct |
3 |
Correct |
82 ms |
95168 KB |
Output is correct |
4 |
Correct |
87 ms |
95256 KB |
Output is correct |
5 |
Correct |
84 ms |
95252 KB |
Output is correct |
6 |
Correct |
86 ms |
95132 KB |
Output is correct |
7 |
Correct |
85 ms |
95160 KB |
Output is correct |
8 |
Correct |
84 ms |
95284 KB |
Output is correct |
9 |
Correct |
84 ms |
95244 KB |
Output is correct |
10 |
Correct |
85 ms |
95184 KB |
Output is correct |
11 |
Correct |
86 ms |
95256 KB |
Output is correct |
12 |
Correct |
85 ms |
95248 KB |
Output is correct |
13 |
Correct |
82 ms |
95140 KB |
Output is correct |
14 |
Correct |
83 ms |
95180 KB |
Output is correct |
15 |
Correct |
91 ms |
95268 KB |
Output is correct |
16 |
Correct |
83 ms |
95252 KB |
Output is correct |
17 |
Correct |
81 ms |
95160 KB |
Output is correct |
18 |
Correct |
83 ms |
95252 KB |
Output is correct |
19 |
Correct |
92 ms |
95252 KB |
Output is correct |
20 |
Correct |
93 ms |
95204 KB |
Output is correct |
21 |
Correct |
83 ms |
95208 KB |
Output is correct |
22 |
Correct |
95 ms |
95192 KB |
Output is correct |
23 |
Correct |
88 ms |
95248 KB |
Output is correct |
24 |
Correct |
86 ms |
95340 KB |
Output is correct |
25 |
Correct |
81 ms |
95172 KB |
Output is correct |
26 |
Correct |
91 ms |
95512 KB |
Output is correct |
27 |
Correct |
86 ms |
95620 KB |
Output is correct |
28 |
Correct |
86 ms |
95280 KB |
Output is correct |
29 |
Correct |
86 ms |
95940 KB |
Output is correct |
30 |
Correct |
87 ms |
98504 KB |
Output is correct |
31 |
Correct |
85 ms |
95184 KB |
Output is correct |
32 |
Correct |
80 ms |
95244 KB |
Output is correct |
33 |
Correct |
88 ms |
95404 KB |
Output is correct |
34 |
Correct |
80 ms |
95260 KB |
Output is correct |
35 |
Correct |
88 ms |
98104 KB |
Output is correct |
36 |
Correct |
86 ms |
96320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
95204 KB |
Output is correct |
2 |
Correct |
81 ms |
95248 KB |
Output is correct |
3 |
Correct |
82 ms |
95168 KB |
Output is correct |
4 |
Correct |
87 ms |
95256 KB |
Output is correct |
5 |
Correct |
84 ms |
95252 KB |
Output is correct |
6 |
Correct |
86 ms |
95132 KB |
Output is correct |
7 |
Correct |
85 ms |
95160 KB |
Output is correct |
8 |
Correct |
84 ms |
95284 KB |
Output is correct |
9 |
Correct |
84 ms |
95244 KB |
Output is correct |
10 |
Correct |
85 ms |
95184 KB |
Output is correct |
11 |
Correct |
86 ms |
95256 KB |
Output is correct |
12 |
Correct |
85 ms |
95248 KB |
Output is correct |
13 |
Correct |
82 ms |
95140 KB |
Output is correct |
14 |
Correct |
83 ms |
95180 KB |
Output is correct |
15 |
Correct |
91 ms |
95268 KB |
Output is correct |
16 |
Correct |
83 ms |
95252 KB |
Output is correct |
17 |
Correct |
81 ms |
95160 KB |
Output is correct |
18 |
Correct |
83 ms |
95252 KB |
Output is correct |
19 |
Correct |
92 ms |
95252 KB |
Output is correct |
20 |
Correct |
93 ms |
95204 KB |
Output is correct |
21 |
Correct |
83 ms |
95208 KB |
Output is correct |
22 |
Correct |
95 ms |
95192 KB |
Output is correct |
23 |
Correct |
88 ms |
95248 KB |
Output is correct |
24 |
Correct |
86 ms |
95340 KB |
Output is correct |
25 |
Correct |
81 ms |
95172 KB |
Output is correct |
26 |
Correct |
91 ms |
95512 KB |
Output is correct |
27 |
Correct |
86 ms |
95620 KB |
Output is correct |
28 |
Correct |
86 ms |
95280 KB |
Output is correct |
29 |
Correct |
86 ms |
95940 KB |
Output is correct |
30 |
Correct |
87 ms |
98504 KB |
Output is correct |
31 |
Correct |
85 ms |
95184 KB |
Output is correct |
32 |
Correct |
80 ms |
95244 KB |
Output is correct |
33 |
Correct |
88 ms |
95404 KB |
Output is correct |
34 |
Correct |
80 ms |
95260 KB |
Output is correct |
35 |
Correct |
88 ms |
98104 KB |
Output is correct |
36 |
Correct |
86 ms |
96320 KB |
Output is correct |
37 |
Correct |
81 ms |
95372 KB |
Output is correct |
38 |
Correct |
96 ms |
102160 KB |
Output is correct |
39 |
Correct |
82 ms |
95344 KB |
Output is correct |
40 |
Correct |
81 ms |
95300 KB |
Output is correct |
41 |
Correct |
111 ms |
102220 KB |
Output is correct |
42 |
Correct |
77 ms |
95300 KB |
Output is correct |
43 |
Correct |
77 ms |
95276 KB |
Output is correct |
44 |
Correct |
80 ms |
95248 KB |
Output is correct |
45 |
Correct |
96 ms |
102196 KB |
Output is correct |
46 |
Correct |
99 ms |
102164 KB |
Output is correct |
47 |
Correct |
78 ms |
95356 KB |
Output is correct |
48 |
Correct |
99 ms |
102316 KB |
Output is correct |
49 |
Correct |
76 ms |
95220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
106204 KB |
Output is correct |
2 |
Correct |
115 ms |
106672 KB |
Output is correct |
3 |
Correct |
122 ms |
106272 KB |
Output is correct |
4 |
Correct |
121 ms |
105960 KB |
Output is correct |
5 |
Correct |
113 ms |
106024 KB |
Output is correct |
6 |
Correct |
112 ms |
105776 KB |
Output is correct |
7 |
Correct |
121 ms |
105948 KB |
Output is correct |
8 |
Correct |
114 ms |
106344 KB |
Output is correct |
9 |
Correct |
119 ms |
105736 KB |
Output is correct |
10 |
Correct |
116 ms |
105428 KB |
Output is correct |
11 |
Correct |
111 ms |
105296 KB |
Output is correct |
12 |
Correct |
119 ms |
105328 KB |
Output is correct |
13 |
Correct |
123 ms |
104804 KB |
Output is correct |
14 |
Correct |
83 ms |
95472 KB |
Output is correct |
15 |
Correct |
80 ms |
95452 KB |
Output is correct |
16 |
Correct |
82 ms |
95416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
95204 KB |
Output is correct |
2 |
Correct |
81 ms |
95248 KB |
Output is correct |
3 |
Correct |
82 ms |
95168 KB |
Output is correct |
4 |
Correct |
87 ms |
95256 KB |
Output is correct |
5 |
Correct |
84 ms |
95252 KB |
Output is correct |
6 |
Correct |
86 ms |
95132 KB |
Output is correct |
7 |
Correct |
85 ms |
95160 KB |
Output is correct |
8 |
Correct |
84 ms |
95284 KB |
Output is correct |
9 |
Correct |
84 ms |
95244 KB |
Output is correct |
10 |
Correct |
85 ms |
95184 KB |
Output is correct |
11 |
Correct |
86 ms |
95256 KB |
Output is correct |
12 |
Correct |
85 ms |
95248 KB |
Output is correct |
13 |
Correct |
82 ms |
95140 KB |
Output is correct |
14 |
Correct |
83 ms |
95180 KB |
Output is correct |
15 |
Correct |
91 ms |
95268 KB |
Output is correct |
16 |
Correct |
83 ms |
95252 KB |
Output is correct |
17 |
Correct |
81 ms |
95160 KB |
Output is correct |
18 |
Correct |
83 ms |
95252 KB |
Output is correct |
19 |
Correct |
92 ms |
95252 KB |
Output is correct |
20 |
Correct |
93 ms |
95204 KB |
Output is correct |
21 |
Correct |
83 ms |
95208 KB |
Output is correct |
22 |
Correct |
95 ms |
95192 KB |
Output is correct |
23 |
Correct |
88 ms |
95248 KB |
Output is correct |
24 |
Correct |
86 ms |
95340 KB |
Output is correct |
25 |
Correct |
81 ms |
95172 KB |
Output is correct |
26 |
Correct |
91 ms |
95512 KB |
Output is correct |
27 |
Correct |
86 ms |
95620 KB |
Output is correct |
28 |
Correct |
86 ms |
95280 KB |
Output is correct |
29 |
Correct |
86 ms |
95940 KB |
Output is correct |
30 |
Correct |
87 ms |
98504 KB |
Output is correct |
31 |
Correct |
85 ms |
95184 KB |
Output is correct |
32 |
Correct |
80 ms |
95244 KB |
Output is correct |
33 |
Correct |
88 ms |
95404 KB |
Output is correct |
34 |
Correct |
80 ms |
95260 KB |
Output is correct |
35 |
Correct |
88 ms |
98104 KB |
Output is correct |
36 |
Correct |
86 ms |
96320 KB |
Output is correct |
37 |
Correct |
81 ms |
95372 KB |
Output is correct |
38 |
Correct |
96 ms |
102160 KB |
Output is correct |
39 |
Correct |
82 ms |
95344 KB |
Output is correct |
40 |
Correct |
81 ms |
95300 KB |
Output is correct |
41 |
Correct |
111 ms |
102220 KB |
Output is correct |
42 |
Correct |
77 ms |
95300 KB |
Output is correct |
43 |
Correct |
77 ms |
95276 KB |
Output is correct |
44 |
Correct |
80 ms |
95248 KB |
Output is correct |
45 |
Correct |
96 ms |
102196 KB |
Output is correct |
46 |
Correct |
99 ms |
102164 KB |
Output is correct |
47 |
Correct |
78 ms |
95356 KB |
Output is correct |
48 |
Correct |
99 ms |
102316 KB |
Output is correct |
49 |
Correct |
76 ms |
95220 KB |
Output is correct |
50 |
Correct |
123 ms |
106204 KB |
Output is correct |
51 |
Correct |
115 ms |
106672 KB |
Output is correct |
52 |
Correct |
122 ms |
106272 KB |
Output is correct |
53 |
Correct |
121 ms |
105960 KB |
Output is correct |
54 |
Correct |
113 ms |
106024 KB |
Output is correct |
55 |
Correct |
112 ms |
105776 KB |
Output is correct |
56 |
Correct |
121 ms |
105948 KB |
Output is correct |
57 |
Correct |
114 ms |
106344 KB |
Output is correct |
58 |
Correct |
119 ms |
105736 KB |
Output is correct |
59 |
Correct |
116 ms |
105428 KB |
Output is correct |
60 |
Correct |
111 ms |
105296 KB |
Output is correct |
61 |
Correct |
119 ms |
105328 KB |
Output is correct |
62 |
Correct |
123 ms |
104804 KB |
Output is correct |
63 |
Correct |
83 ms |
95472 KB |
Output is correct |
64 |
Correct |
80 ms |
95452 KB |
Output is correct |
65 |
Correct |
82 ms |
95416 KB |
Output is correct |
66 |
Correct |
81 ms |
95372 KB |
Output is correct |
67 |
Correct |
187 ms |
132700 KB |
Output is correct |
68 |
Correct |
184 ms |
131152 KB |
Output is correct |
69 |
Correct |
192 ms |
135480 KB |
Output is correct |
70 |
Correct |
80 ms |
95436 KB |
Output is correct |
71 |
Correct |
77 ms |
95568 KB |
Output is correct |
72 |
Correct |
168 ms |
120760 KB |
Output is correct |
73 |
Correct |
181 ms |
119332 KB |
Output is correct |
74 |
Correct |
94 ms |
95620 KB |
Output is correct |
75 |
Correct |
199 ms |
131608 KB |
Output is correct |
76 |
Correct |
84 ms |
95620 KB |
Output is correct |
77 |
Correct |
78 ms |
95276 KB |
Output is correct |
78 |
Runtime error |
176 ms |
193308 KB |
Execution killed with signal 11 |
79 |
Halted |
0 ms |
0 KB |
- |