# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
429534 |
2021-06-16T05:42:26 Z |
송준혁(#7525) |
Brackets (CPSPC17_brackets) |
C++17 |
|
622 ms |
456244 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], Q[16010101], adj[220][220];
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++) Q[0].pb(pii(i,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(pii(a.se, b.se));
for (int d=0; d<=16000000; d++){
for (pii u : Q[d]){
if (u.fi == S && u.se == T){
printf("%d\n", 2*d);
return 0;
}
if (D[u.fi][u.se] != MOD) continue;
D[u.fi][u.se] = d;
for (pii v : adj[u.fi][u.se]) Q[d+1].pb(v);
for (int i=1; i<=N; i++){
if (D[i][u.fi] + d <= 16000000 && i != u.fi) Q[D[i][u.fi] + d].pb(pii(i, u.se));
if (D[u.se][i] + d <= 16000000 && i != u.se) Q[D[u.se][i] + d].pb(pii(u.fi, i));
}
}
}
puts("-1");
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d %d %d %d", &N, &M, &S, &T);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d %d %c", &u, &v, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
353 ms |
377364 KB |
Output is correct |
2 |
Correct |
343 ms |
377392 KB |
Output is correct |
3 |
Correct |
269 ms |
377392 KB |
Output is correct |
4 |
Correct |
261 ms |
377392 KB |
Output is correct |
5 |
Correct |
297 ms |
377284 KB |
Output is correct |
6 |
Correct |
298 ms |
377336 KB |
Output is correct |
7 |
Correct |
272 ms |
377304 KB |
Output is correct |
8 |
Correct |
297 ms |
377388 KB |
Output is correct |
9 |
Correct |
263 ms |
377540 KB |
Output is correct |
10 |
Correct |
268 ms |
377348 KB |
Output is correct |
11 |
Correct |
265 ms |
377340 KB |
Output is correct |
12 |
Correct |
305 ms |
377480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
353 ms |
377364 KB |
Output is correct |
2 |
Correct |
343 ms |
377392 KB |
Output is correct |
3 |
Correct |
269 ms |
377392 KB |
Output is correct |
4 |
Correct |
261 ms |
377392 KB |
Output is correct |
5 |
Correct |
297 ms |
377284 KB |
Output is correct |
6 |
Correct |
298 ms |
377336 KB |
Output is correct |
7 |
Correct |
272 ms |
377304 KB |
Output is correct |
8 |
Correct |
297 ms |
377388 KB |
Output is correct |
9 |
Correct |
263 ms |
377540 KB |
Output is correct |
10 |
Correct |
268 ms |
377348 KB |
Output is correct |
11 |
Correct |
265 ms |
377340 KB |
Output is correct |
12 |
Correct |
305 ms |
377480 KB |
Output is correct |
13 |
Correct |
296 ms |
377376 KB |
Output is correct |
14 |
Correct |
255 ms |
377352 KB |
Output is correct |
15 |
Correct |
270 ms |
377420 KB |
Output is correct |
16 |
Correct |
257 ms |
377300 KB |
Output is correct |
17 |
Correct |
269 ms |
377412 KB |
Output is correct |
18 |
Correct |
262 ms |
377292 KB |
Output is correct |
19 |
Correct |
257 ms |
377412 KB |
Output is correct |
20 |
Correct |
263 ms |
377408 KB |
Output is correct |
21 |
Correct |
273 ms |
377452 KB |
Output is correct |
22 |
Correct |
265 ms |
377516 KB |
Output is correct |
23 |
Correct |
272 ms |
377336 KB |
Output is correct |
24 |
Correct |
270 ms |
377340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
353 ms |
377364 KB |
Output is correct |
2 |
Correct |
343 ms |
377392 KB |
Output is correct |
3 |
Correct |
269 ms |
377392 KB |
Output is correct |
4 |
Correct |
261 ms |
377392 KB |
Output is correct |
5 |
Correct |
297 ms |
377284 KB |
Output is correct |
6 |
Correct |
298 ms |
377336 KB |
Output is correct |
7 |
Correct |
272 ms |
377304 KB |
Output is correct |
8 |
Correct |
297 ms |
377388 KB |
Output is correct |
9 |
Correct |
263 ms |
377540 KB |
Output is correct |
10 |
Correct |
268 ms |
377348 KB |
Output is correct |
11 |
Correct |
265 ms |
377340 KB |
Output is correct |
12 |
Correct |
305 ms |
377480 KB |
Output is correct |
13 |
Correct |
296 ms |
377376 KB |
Output is correct |
14 |
Correct |
255 ms |
377352 KB |
Output is correct |
15 |
Correct |
270 ms |
377420 KB |
Output is correct |
16 |
Correct |
257 ms |
377300 KB |
Output is correct |
17 |
Correct |
269 ms |
377412 KB |
Output is correct |
18 |
Correct |
262 ms |
377292 KB |
Output is correct |
19 |
Correct |
257 ms |
377412 KB |
Output is correct |
20 |
Correct |
263 ms |
377408 KB |
Output is correct |
21 |
Correct |
273 ms |
377452 KB |
Output is correct |
22 |
Correct |
265 ms |
377516 KB |
Output is correct |
23 |
Correct |
272 ms |
377336 KB |
Output is correct |
24 |
Correct |
270 ms |
377340 KB |
Output is correct |
25 |
Correct |
270 ms |
377356 KB |
Output is correct |
26 |
Correct |
291 ms |
378504 KB |
Output is correct |
27 |
Correct |
259 ms |
378180 KB |
Output is correct |
28 |
Correct |
276 ms |
377356 KB |
Output is correct |
29 |
Correct |
328 ms |
379388 KB |
Output is correct |
30 |
Correct |
282 ms |
384176 KB |
Output is correct |
31 |
Correct |
276 ms |
377452 KB |
Output is correct |
32 |
Correct |
278 ms |
377316 KB |
Output is correct |
33 |
Correct |
259 ms |
378308 KB |
Output is correct |
34 |
Correct |
270 ms |
377428 KB |
Output is correct |
35 |
Correct |
270 ms |
382776 KB |
Output is correct |
36 |
Correct |
263 ms |
379096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
353 ms |
377364 KB |
Output is correct |
2 |
Correct |
343 ms |
377392 KB |
Output is correct |
3 |
Correct |
269 ms |
377392 KB |
Output is correct |
4 |
Correct |
261 ms |
377392 KB |
Output is correct |
5 |
Correct |
297 ms |
377284 KB |
Output is correct |
6 |
Correct |
298 ms |
377336 KB |
Output is correct |
7 |
Correct |
272 ms |
377304 KB |
Output is correct |
8 |
Correct |
297 ms |
377388 KB |
Output is correct |
9 |
Correct |
263 ms |
377540 KB |
Output is correct |
10 |
Correct |
268 ms |
377348 KB |
Output is correct |
11 |
Correct |
265 ms |
377340 KB |
Output is correct |
12 |
Correct |
305 ms |
377480 KB |
Output is correct |
13 |
Correct |
296 ms |
377376 KB |
Output is correct |
14 |
Correct |
255 ms |
377352 KB |
Output is correct |
15 |
Correct |
270 ms |
377420 KB |
Output is correct |
16 |
Correct |
257 ms |
377300 KB |
Output is correct |
17 |
Correct |
269 ms |
377412 KB |
Output is correct |
18 |
Correct |
262 ms |
377292 KB |
Output is correct |
19 |
Correct |
257 ms |
377412 KB |
Output is correct |
20 |
Correct |
263 ms |
377408 KB |
Output is correct |
21 |
Correct |
273 ms |
377452 KB |
Output is correct |
22 |
Correct |
265 ms |
377516 KB |
Output is correct |
23 |
Correct |
272 ms |
377336 KB |
Output is correct |
24 |
Correct |
270 ms |
377340 KB |
Output is correct |
25 |
Correct |
270 ms |
377356 KB |
Output is correct |
26 |
Correct |
291 ms |
378504 KB |
Output is correct |
27 |
Correct |
259 ms |
378180 KB |
Output is correct |
28 |
Correct |
276 ms |
377356 KB |
Output is correct |
29 |
Correct |
328 ms |
379388 KB |
Output is correct |
30 |
Correct |
282 ms |
384176 KB |
Output is correct |
31 |
Correct |
276 ms |
377452 KB |
Output is correct |
32 |
Correct |
278 ms |
377316 KB |
Output is correct |
33 |
Correct |
259 ms |
378308 KB |
Output is correct |
34 |
Correct |
270 ms |
377428 KB |
Output is correct |
35 |
Correct |
270 ms |
382776 KB |
Output is correct |
36 |
Correct |
263 ms |
379096 KB |
Output is correct |
37 |
Correct |
275 ms |
377596 KB |
Output is correct |
38 |
Correct |
314 ms |
388424 KB |
Output is correct |
39 |
Correct |
275 ms |
377576 KB |
Output is correct |
40 |
Correct |
298 ms |
377528 KB |
Output is correct |
41 |
Correct |
303 ms |
388480 KB |
Output is correct |
42 |
Correct |
268 ms |
377540 KB |
Output is correct |
43 |
Correct |
310 ms |
377408 KB |
Output is correct |
44 |
Correct |
270 ms |
377652 KB |
Output is correct |
45 |
Correct |
302 ms |
383288 KB |
Output is correct |
46 |
Correct |
316 ms |
393644 KB |
Output is correct |
47 |
Correct |
283 ms |
377832 KB |
Output is correct |
48 |
Correct |
324 ms |
391344 KB |
Output is correct |
49 |
Correct |
313 ms |
377448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
312 ms |
391716 KB |
Output is correct |
2 |
Correct |
317 ms |
392576 KB |
Output is correct |
3 |
Correct |
313 ms |
391716 KB |
Output is correct |
4 |
Correct |
320 ms |
391524 KB |
Output is correct |
5 |
Correct |
327 ms |
391520 KB |
Output is correct |
6 |
Correct |
313 ms |
391328 KB |
Output is correct |
7 |
Correct |
307 ms |
391596 KB |
Output is correct |
8 |
Correct |
311 ms |
391856 KB |
Output is correct |
9 |
Correct |
329 ms |
391404 KB |
Output is correct |
10 |
Correct |
305 ms |
390848 KB |
Output is correct |
11 |
Correct |
327 ms |
390920 KB |
Output is correct |
12 |
Correct |
306 ms |
390992 KB |
Output is correct |
13 |
Correct |
352 ms |
390728 KB |
Output is correct |
14 |
Correct |
273 ms |
380956 KB |
Output is correct |
15 |
Correct |
271 ms |
380900 KB |
Output is correct |
16 |
Correct |
312 ms |
377632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
353 ms |
377364 KB |
Output is correct |
2 |
Correct |
343 ms |
377392 KB |
Output is correct |
3 |
Correct |
269 ms |
377392 KB |
Output is correct |
4 |
Correct |
261 ms |
377392 KB |
Output is correct |
5 |
Correct |
297 ms |
377284 KB |
Output is correct |
6 |
Correct |
298 ms |
377336 KB |
Output is correct |
7 |
Correct |
272 ms |
377304 KB |
Output is correct |
8 |
Correct |
297 ms |
377388 KB |
Output is correct |
9 |
Correct |
263 ms |
377540 KB |
Output is correct |
10 |
Correct |
268 ms |
377348 KB |
Output is correct |
11 |
Correct |
265 ms |
377340 KB |
Output is correct |
12 |
Correct |
305 ms |
377480 KB |
Output is correct |
13 |
Correct |
296 ms |
377376 KB |
Output is correct |
14 |
Correct |
255 ms |
377352 KB |
Output is correct |
15 |
Correct |
270 ms |
377420 KB |
Output is correct |
16 |
Correct |
257 ms |
377300 KB |
Output is correct |
17 |
Correct |
269 ms |
377412 KB |
Output is correct |
18 |
Correct |
262 ms |
377292 KB |
Output is correct |
19 |
Correct |
257 ms |
377412 KB |
Output is correct |
20 |
Correct |
263 ms |
377408 KB |
Output is correct |
21 |
Correct |
273 ms |
377452 KB |
Output is correct |
22 |
Correct |
265 ms |
377516 KB |
Output is correct |
23 |
Correct |
272 ms |
377336 KB |
Output is correct |
24 |
Correct |
270 ms |
377340 KB |
Output is correct |
25 |
Correct |
270 ms |
377356 KB |
Output is correct |
26 |
Correct |
291 ms |
378504 KB |
Output is correct |
27 |
Correct |
259 ms |
378180 KB |
Output is correct |
28 |
Correct |
276 ms |
377356 KB |
Output is correct |
29 |
Correct |
328 ms |
379388 KB |
Output is correct |
30 |
Correct |
282 ms |
384176 KB |
Output is correct |
31 |
Correct |
276 ms |
377452 KB |
Output is correct |
32 |
Correct |
278 ms |
377316 KB |
Output is correct |
33 |
Correct |
259 ms |
378308 KB |
Output is correct |
34 |
Correct |
270 ms |
377428 KB |
Output is correct |
35 |
Correct |
270 ms |
382776 KB |
Output is correct |
36 |
Correct |
263 ms |
379096 KB |
Output is correct |
37 |
Correct |
275 ms |
377596 KB |
Output is correct |
38 |
Correct |
314 ms |
388424 KB |
Output is correct |
39 |
Correct |
275 ms |
377576 KB |
Output is correct |
40 |
Correct |
298 ms |
377528 KB |
Output is correct |
41 |
Correct |
303 ms |
388480 KB |
Output is correct |
42 |
Correct |
268 ms |
377540 KB |
Output is correct |
43 |
Correct |
310 ms |
377408 KB |
Output is correct |
44 |
Correct |
270 ms |
377652 KB |
Output is correct |
45 |
Correct |
302 ms |
383288 KB |
Output is correct |
46 |
Correct |
316 ms |
393644 KB |
Output is correct |
47 |
Correct |
283 ms |
377832 KB |
Output is correct |
48 |
Correct |
324 ms |
391344 KB |
Output is correct |
49 |
Correct |
313 ms |
377448 KB |
Output is correct |
50 |
Correct |
312 ms |
391716 KB |
Output is correct |
51 |
Correct |
317 ms |
392576 KB |
Output is correct |
52 |
Correct |
313 ms |
391716 KB |
Output is correct |
53 |
Correct |
320 ms |
391524 KB |
Output is correct |
54 |
Correct |
327 ms |
391520 KB |
Output is correct |
55 |
Correct |
313 ms |
391328 KB |
Output is correct |
56 |
Correct |
307 ms |
391596 KB |
Output is correct |
57 |
Correct |
311 ms |
391856 KB |
Output is correct |
58 |
Correct |
329 ms |
391404 KB |
Output is correct |
59 |
Correct |
305 ms |
390848 KB |
Output is correct |
60 |
Correct |
327 ms |
390920 KB |
Output is correct |
61 |
Correct |
306 ms |
390992 KB |
Output is correct |
62 |
Correct |
352 ms |
390728 KB |
Output is correct |
63 |
Correct |
273 ms |
380956 KB |
Output is correct |
64 |
Correct |
271 ms |
380900 KB |
Output is correct |
65 |
Correct |
312 ms |
377632 KB |
Output is correct |
66 |
Correct |
317 ms |
377560 KB |
Output is correct |
67 |
Correct |
447 ms |
448772 KB |
Output is correct |
68 |
Correct |
564 ms |
447112 KB |
Output is correct |
69 |
Correct |
456 ms |
447180 KB |
Output is correct |
70 |
Correct |
281 ms |
377804 KB |
Output is correct |
71 |
Correct |
285 ms |
377848 KB |
Output is correct |
72 |
Correct |
422 ms |
452544 KB |
Output is correct |
73 |
Correct |
622 ms |
456244 KB |
Output is correct |
74 |
Correct |
287 ms |
378052 KB |
Output is correct |
75 |
Correct |
527 ms |
447512 KB |
Output is correct |
76 |
Correct |
322 ms |
377864 KB |
Output is correct |
77 |
Correct |
292 ms |
377628 KB |
Output is correct |
78 |
Incorrect |
342 ms |
377616 KB |
Output isn't correct |
79 |
Halted |
0 ms |
0 KB |
- |