# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
429544 |
2021-06-16T05:52:53 Z |
송준혁(#7525) |
Brackets (CPSPC17_brackets) |
C++17 |
|
700 ms |
36788 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define MOD 1000000007
#define INF (1ll<<62)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int N, M, S, T;
int D[220][220];
vector<pii> V[8];
vector<int> adj[220][220];
priority_queue<pii> PQ;
int main(){
char c;
scanf("%d %d %d %d", &N, &M, &S, &T);
for (int i=1; i<=M; i++){
int u, v;
scanf("%d %d %c", &u, &v, &c);
if (c == '(') V[0].pb(pii(v, u));
if (c == '{') V[1].pb(pii(v, u));
if (c == '[') V[2].pb(pii(v, u));
if (c == '<') V[3].pb(pii(v, u));
if (c == ')') V[4].pb(pii(u, v));
if (c == '}') V[5].pb(pii(u, v));
if (c == ']') V[6].pb(pii(u, v));
if (c == '>') V[7].pb(pii(u, v));
}
for (int i=1; i<=N; i++) for (int j=1; j<=N; j++) D[i][j] = MOD;
for (int i=1; i<=N; i++) PQ.push(pii(0, i*(N+1)+i));
for (int i=0; i<4; i++) for (pii a : V[i]) for (pii b : V[i+4]) adj[a.fi][b.fi].pb(a.se*(N+1)+b.se);
while (PQ.size()){
int d = -PQ.top().fi;
int a = PQ.top().se/(N+1);
int b = PQ.top().se%(N+1);
PQ.pop();
if (a == S && b == T){
printf("%d\n", 2*d);
return 0;
}
if (D[a][b] != MOD) continue;
D[a][b] = d;
for (int v : adj[a][b]) PQ.push(pii(-d-1, v));
for (int i=1; i<=N; i++){
if (D[i][a] != MOD) PQ.push(pii(-D[i][a]-d, i*(N+1) + b));
if (D[b][i] != MOD) PQ.push(pii(-D[b][i]-d, a*(N+1) + i));
}
}
puts("-1");
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | scanf("%d %d %d %d", &N, &M, &S, &T);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d %d %c", &u, &v, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
2 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1356 KB |
Output is correct |
6 |
Correct |
1 ms |
1356 KB |
Output is correct |
7 |
Correct |
1 ms |
1368 KB |
Output is correct |
8 |
Correct |
1 ms |
1356 KB |
Output is correct |
9 |
Correct |
1 ms |
1356 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
1 ms |
1356 KB |
Output is correct |
12 |
Correct |
1 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
2 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1356 KB |
Output is correct |
6 |
Correct |
1 ms |
1356 KB |
Output is correct |
7 |
Correct |
1 ms |
1368 KB |
Output is correct |
8 |
Correct |
1 ms |
1356 KB |
Output is correct |
9 |
Correct |
1 ms |
1356 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
1 ms |
1356 KB |
Output is correct |
12 |
Correct |
1 ms |
1356 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
1 ms |
1356 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
16 |
Correct |
1 ms |
1356 KB |
Output is correct |
17 |
Correct |
2 ms |
1484 KB |
Output is correct |
18 |
Correct |
1 ms |
1356 KB |
Output is correct |
19 |
Correct |
1 ms |
1356 KB |
Output is correct |
20 |
Correct |
2 ms |
1488 KB |
Output is correct |
21 |
Correct |
2 ms |
1484 KB |
Output is correct |
22 |
Correct |
3 ms |
1508 KB |
Output is correct |
23 |
Correct |
2 ms |
1356 KB |
Output is correct |
24 |
Correct |
3 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
2 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1356 KB |
Output is correct |
6 |
Correct |
1 ms |
1356 KB |
Output is correct |
7 |
Correct |
1 ms |
1368 KB |
Output is correct |
8 |
Correct |
1 ms |
1356 KB |
Output is correct |
9 |
Correct |
1 ms |
1356 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
1 ms |
1356 KB |
Output is correct |
12 |
Correct |
1 ms |
1356 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
1 ms |
1356 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
16 |
Correct |
1 ms |
1356 KB |
Output is correct |
17 |
Correct |
2 ms |
1484 KB |
Output is correct |
18 |
Correct |
1 ms |
1356 KB |
Output is correct |
19 |
Correct |
1 ms |
1356 KB |
Output is correct |
20 |
Correct |
2 ms |
1488 KB |
Output is correct |
21 |
Correct |
2 ms |
1484 KB |
Output is correct |
22 |
Correct |
3 ms |
1508 KB |
Output is correct |
23 |
Correct |
2 ms |
1356 KB |
Output is correct |
24 |
Correct |
3 ms |
1484 KB |
Output is correct |
25 |
Correct |
2 ms |
1484 KB |
Output is correct |
26 |
Correct |
20 ms |
2612 KB |
Output is correct |
27 |
Correct |
5 ms |
1740 KB |
Output is correct |
28 |
Correct |
2 ms |
1484 KB |
Output is correct |
29 |
Correct |
27 ms |
2756 KB |
Output is correct |
30 |
Correct |
55 ms |
5264 KB |
Output is correct |
31 |
Correct |
1 ms |
1484 KB |
Output is correct |
32 |
Correct |
1 ms |
1356 KB |
Output is correct |
33 |
Correct |
7 ms |
2120 KB |
Output is correct |
34 |
Correct |
1 ms |
1356 KB |
Output is correct |
35 |
Correct |
12 ms |
5200 KB |
Output is correct |
36 |
Correct |
22 ms |
2328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
2 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1356 KB |
Output is correct |
6 |
Correct |
1 ms |
1356 KB |
Output is correct |
7 |
Correct |
1 ms |
1368 KB |
Output is correct |
8 |
Correct |
1 ms |
1356 KB |
Output is correct |
9 |
Correct |
1 ms |
1356 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
1 ms |
1356 KB |
Output is correct |
12 |
Correct |
1 ms |
1356 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
1 ms |
1356 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
16 |
Correct |
1 ms |
1356 KB |
Output is correct |
17 |
Correct |
2 ms |
1484 KB |
Output is correct |
18 |
Correct |
1 ms |
1356 KB |
Output is correct |
19 |
Correct |
1 ms |
1356 KB |
Output is correct |
20 |
Correct |
2 ms |
1488 KB |
Output is correct |
21 |
Correct |
2 ms |
1484 KB |
Output is correct |
22 |
Correct |
3 ms |
1508 KB |
Output is correct |
23 |
Correct |
2 ms |
1356 KB |
Output is correct |
24 |
Correct |
3 ms |
1484 KB |
Output is correct |
25 |
Correct |
2 ms |
1484 KB |
Output is correct |
26 |
Correct |
20 ms |
2612 KB |
Output is correct |
27 |
Correct |
5 ms |
1740 KB |
Output is correct |
28 |
Correct |
2 ms |
1484 KB |
Output is correct |
29 |
Correct |
27 ms |
2756 KB |
Output is correct |
30 |
Correct |
55 ms |
5264 KB |
Output is correct |
31 |
Correct |
1 ms |
1484 KB |
Output is correct |
32 |
Correct |
1 ms |
1356 KB |
Output is correct |
33 |
Correct |
7 ms |
2120 KB |
Output is correct |
34 |
Correct |
1 ms |
1356 KB |
Output is correct |
35 |
Correct |
12 ms |
5200 KB |
Output is correct |
36 |
Correct |
22 ms |
2328 KB |
Output is correct |
37 |
Correct |
3 ms |
1484 KB |
Output is correct |
38 |
Correct |
18 ms |
5452 KB |
Output is correct |
39 |
Correct |
3 ms |
1484 KB |
Output is correct |
40 |
Correct |
2 ms |
1484 KB |
Output is correct |
41 |
Correct |
68 ms |
11576 KB |
Output is correct |
42 |
Correct |
2 ms |
1612 KB |
Output is correct |
43 |
Correct |
1 ms |
1484 KB |
Output is correct |
44 |
Correct |
2 ms |
1484 KB |
Output is correct |
45 |
Correct |
18 ms |
5440 KB |
Output is correct |
46 |
Correct |
169 ms |
19736 KB |
Output is correct |
47 |
Correct |
6 ms |
1868 KB |
Output is correct |
48 |
Correct |
190 ms |
7448 KB |
Output is correct |
49 |
Correct |
1 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
276 ms |
7932 KB |
Output is correct |
2 |
Correct |
283 ms |
7844 KB |
Output is correct |
3 |
Correct |
265 ms |
7916 KB |
Output is correct |
4 |
Correct |
274 ms |
7976 KB |
Output is correct |
5 |
Correct |
274 ms |
7932 KB |
Output is correct |
6 |
Correct |
264 ms |
7860 KB |
Output is correct |
7 |
Correct |
250 ms |
7844 KB |
Output is correct |
8 |
Correct |
269 ms |
7856 KB |
Output is correct |
9 |
Correct |
265 ms |
7900 KB |
Output is correct |
10 |
Correct |
248 ms |
7864 KB |
Output is correct |
11 |
Correct |
263 ms |
7876 KB |
Output is correct |
12 |
Correct |
263 ms |
7864 KB |
Output is correct |
13 |
Correct |
234 ms |
7864 KB |
Output is correct |
14 |
Correct |
13 ms |
3452 KB |
Output is correct |
15 |
Correct |
14 ms |
3572 KB |
Output is correct |
16 |
Correct |
2 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
2 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1356 KB |
Output is correct |
6 |
Correct |
1 ms |
1356 KB |
Output is correct |
7 |
Correct |
1 ms |
1368 KB |
Output is correct |
8 |
Correct |
1 ms |
1356 KB |
Output is correct |
9 |
Correct |
1 ms |
1356 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
1 ms |
1356 KB |
Output is correct |
12 |
Correct |
1 ms |
1356 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
1 ms |
1356 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
16 |
Correct |
1 ms |
1356 KB |
Output is correct |
17 |
Correct |
2 ms |
1484 KB |
Output is correct |
18 |
Correct |
1 ms |
1356 KB |
Output is correct |
19 |
Correct |
1 ms |
1356 KB |
Output is correct |
20 |
Correct |
2 ms |
1488 KB |
Output is correct |
21 |
Correct |
2 ms |
1484 KB |
Output is correct |
22 |
Correct |
3 ms |
1508 KB |
Output is correct |
23 |
Correct |
2 ms |
1356 KB |
Output is correct |
24 |
Correct |
3 ms |
1484 KB |
Output is correct |
25 |
Correct |
2 ms |
1484 KB |
Output is correct |
26 |
Correct |
20 ms |
2612 KB |
Output is correct |
27 |
Correct |
5 ms |
1740 KB |
Output is correct |
28 |
Correct |
2 ms |
1484 KB |
Output is correct |
29 |
Correct |
27 ms |
2756 KB |
Output is correct |
30 |
Correct |
55 ms |
5264 KB |
Output is correct |
31 |
Correct |
1 ms |
1484 KB |
Output is correct |
32 |
Correct |
1 ms |
1356 KB |
Output is correct |
33 |
Correct |
7 ms |
2120 KB |
Output is correct |
34 |
Correct |
1 ms |
1356 KB |
Output is correct |
35 |
Correct |
12 ms |
5200 KB |
Output is correct |
36 |
Correct |
22 ms |
2328 KB |
Output is correct |
37 |
Correct |
3 ms |
1484 KB |
Output is correct |
38 |
Correct |
18 ms |
5452 KB |
Output is correct |
39 |
Correct |
3 ms |
1484 KB |
Output is correct |
40 |
Correct |
2 ms |
1484 KB |
Output is correct |
41 |
Correct |
68 ms |
11576 KB |
Output is correct |
42 |
Correct |
2 ms |
1612 KB |
Output is correct |
43 |
Correct |
1 ms |
1484 KB |
Output is correct |
44 |
Correct |
2 ms |
1484 KB |
Output is correct |
45 |
Correct |
18 ms |
5440 KB |
Output is correct |
46 |
Correct |
169 ms |
19736 KB |
Output is correct |
47 |
Correct |
6 ms |
1868 KB |
Output is correct |
48 |
Correct |
190 ms |
7448 KB |
Output is correct |
49 |
Correct |
1 ms |
1484 KB |
Output is correct |
50 |
Correct |
276 ms |
7932 KB |
Output is correct |
51 |
Correct |
283 ms |
7844 KB |
Output is correct |
52 |
Correct |
265 ms |
7916 KB |
Output is correct |
53 |
Correct |
274 ms |
7976 KB |
Output is correct |
54 |
Correct |
274 ms |
7932 KB |
Output is correct |
55 |
Correct |
264 ms |
7860 KB |
Output is correct |
56 |
Correct |
250 ms |
7844 KB |
Output is correct |
57 |
Correct |
269 ms |
7856 KB |
Output is correct |
58 |
Correct |
265 ms |
7900 KB |
Output is correct |
59 |
Correct |
248 ms |
7864 KB |
Output is correct |
60 |
Correct |
263 ms |
7876 KB |
Output is correct |
61 |
Correct |
263 ms |
7864 KB |
Output is correct |
62 |
Correct |
234 ms |
7864 KB |
Output is correct |
63 |
Correct |
13 ms |
3452 KB |
Output is correct |
64 |
Correct |
14 ms |
3572 KB |
Output is correct |
65 |
Correct |
2 ms |
1612 KB |
Output is correct |
66 |
Correct |
2 ms |
1612 KB |
Output is correct |
67 |
Execution timed out |
1089 ms |
36788 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |