Submission #429533

# Submission time Handle Problem Language Result Execution time Memory
429533 2021-06-16T05:40:28 Z 송준혁(#7525) Brackets (CPSPC17_brackets) C++17
74 / 100
291 ms 174372 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[4010101], 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<=4000000; 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 <= 4000000 && i != u.fi) Q[D[i][u.fi] + d].pb(pii(i, u.se));
				if (D[u.se][i] + d <= 4000000 && 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 69 ms 95716 KB Output is correct
2 Correct 66 ms 95596 KB Output is correct
3 Correct 68 ms 95556 KB Output is correct
4 Correct 67 ms 95556 KB Output is correct
5 Correct 77 ms 95600 KB Output is correct
6 Correct 79 ms 95592 KB Output is correct
7 Correct 66 ms 95544 KB Output is correct
8 Correct 72 ms 95556 KB Output is correct
9 Correct 69 ms 95556 KB Output is correct
10 Correct 67 ms 95552 KB Output is correct
11 Correct 68 ms 95552 KB Output is correct
12 Correct 77 ms 95540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 95716 KB Output is correct
2 Correct 66 ms 95596 KB Output is correct
3 Correct 68 ms 95556 KB Output is correct
4 Correct 67 ms 95556 KB Output is correct
5 Correct 77 ms 95600 KB Output is correct
6 Correct 79 ms 95592 KB Output is correct
7 Correct 66 ms 95544 KB Output is correct
8 Correct 72 ms 95556 KB Output is correct
9 Correct 69 ms 95556 KB Output is correct
10 Correct 67 ms 95552 KB Output is correct
11 Correct 68 ms 95552 KB Output is correct
12 Correct 77 ms 95540 KB Output is correct
13 Correct 76 ms 95516 KB Output is correct
14 Correct 73 ms 95508 KB Output is correct
15 Correct 67 ms 95556 KB Output is correct
16 Correct 67 ms 95640 KB Output is correct
17 Correct 76 ms 95652 KB Output is correct
18 Correct 65 ms 95552 KB Output is correct
19 Correct 66 ms 95512 KB Output is correct
20 Correct 67 ms 95536 KB Output is correct
21 Correct 66 ms 95620 KB Output is correct
22 Correct 69 ms 95788 KB Output is correct
23 Correct 69 ms 95508 KB Output is correct
24 Correct 65 ms 95600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 95716 KB Output is correct
2 Correct 66 ms 95596 KB Output is correct
3 Correct 68 ms 95556 KB Output is correct
4 Correct 67 ms 95556 KB Output is correct
5 Correct 77 ms 95600 KB Output is correct
6 Correct 79 ms 95592 KB Output is correct
7 Correct 66 ms 95544 KB Output is correct
8 Correct 72 ms 95556 KB Output is correct
9 Correct 69 ms 95556 KB Output is correct
10 Correct 67 ms 95552 KB Output is correct
11 Correct 68 ms 95552 KB Output is correct
12 Correct 77 ms 95540 KB Output is correct
13 Correct 76 ms 95516 KB Output is correct
14 Correct 73 ms 95508 KB Output is correct
15 Correct 67 ms 95556 KB Output is correct
16 Correct 67 ms 95640 KB Output is correct
17 Correct 76 ms 95652 KB Output is correct
18 Correct 65 ms 95552 KB Output is correct
19 Correct 66 ms 95512 KB Output is correct
20 Correct 67 ms 95536 KB Output is correct
21 Correct 66 ms 95620 KB Output is correct
22 Correct 69 ms 95788 KB Output is correct
23 Correct 69 ms 95508 KB Output is correct
24 Correct 65 ms 95600 KB Output is correct
25 Correct 83 ms 95740 KB Output is correct
26 Correct 81 ms 96684 KB Output is correct
27 Correct 70 ms 96376 KB Output is correct
28 Correct 66 ms 95596 KB Output is correct
29 Correct 83 ms 97588 KB Output is correct
30 Correct 88 ms 102512 KB Output is correct
31 Correct 72 ms 95584 KB Output is correct
32 Correct 64 ms 95564 KB Output is correct
33 Correct 68 ms 96580 KB Output is correct
34 Correct 75 ms 95528 KB Output is correct
35 Correct 83 ms 100920 KB Output is correct
36 Correct 71 ms 97396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 95716 KB Output is correct
2 Correct 66 ms 95596 KB Output is correct
3 Correct 68 ms 95556 KB Output is correct
4 Correct 67 ms 95556 KB Output is correct
5 Correct 77 ms 95600 KB Output is correct
6 Correct 79 ms 95592 KB Output is correct
7 Correct 66 ms 95544 KB Output is correct
8 Correct 72 ms 95556 KB Output is correct
9 Correct 69 ms 95556 KB Output is correct
10 Correct 67 ms 95552 KB Output is correct
11 Correct 68 ms 95552 KB Output is correct
12 Correct 77 ms 95540 KB Output is correct
13 Correct 76 ms 95516 KB Output is correct
14 Correct 73 ms 95508 KB Output is correct
15 Correct 67 ms 95556 KB Output is correct
16 Correct 67 ms 95640 KB Output is correct
17 Correct 76 ms 95652 KB Output is correct
18 Correct 65 ms 95552 KB Output is correct
19 Correct 66 ms 95512 KB Output is correct
20 Correct 67 ms 95536 KB Output is correct
21 Correct 66 ms 95620 KB Output is correct
22 Correct 69 ms 95788 KB Output is correct
23 Correct 69 ms 95508 KB Output is correct
24 Correct 65 ms 95600 KB Output is correct
25 Correct 83 ms 95740 KB Output is correct
26 Correct 81 ms 96684 KB Output is correct
27 Correct 70 ms 96376 KB Output is correct
28 Correct 66 ms 95596 KB Output is correct
29 Correct 83 ms 97588 KB Output is correct
30 Correct 88 ms 102512 KB Output is correct
31 Correct 72 ms 95584 KB Output is correct
32 Correct 64 ms 95564 KB Output is correct
33 Correct 68 ms 96580 KB Output is correct
34 Correct 75 ms 95528 KB Output is correct
35 Correct 83 ms 100920 KB Output is correct
36 Correct 71 ms 97396 KB Output is correct
37 Correct 71 ms 95796 KB Output is correct
38 Correct 101 ms 106684 KB Output is correct
39 Correct 65 ms 95684 KB Output is correct
40 Correct 78 ms 95632 KB Output is correct
41 Correct 102 ms 106848 KB Output is correct
42 Correct 68 ms 95688 KB Output is correct
43 Correct 67 ms 95688 KB Output is correct
44 Correct 66 ms 95684 KB Output is correct
45 Correct 82 ms 101560 KB Output is correct
46 Correct 106 ms 111888 KB Output is correct
47 Correct 73 ms 95980 KB Output is correct
48 Correct 112 ms 109600 KB Output is correct
49 Correct 79 ms 95656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 110020 KB Output is correct
2 Correct 115 ms 110716 KB Output is correct
3 Correct 109 ms 109988 KB Output is correct
4 Correct 117 ms 109716 KB Output is correct
5 Correct 131 ms 109664 KB Output is correct
6 Correct 127 ms 109480 KB Output is correct
7 Correct 107 ms 109728 KB Output is correct
8 Correct 116 ms 110060 KB Output is correct
9 Correct 115 ms 109688 KB Output is correct
10 Correct 120 ms 109156 KB Output is correct
11 Correct 111 ms 109112 KB Output is correct
12 Correct 106 ms 109100 KB Output is correct
13 Correct 114 ms 108944 KB Output is correct
14 Correct 87 ms 99008 KB Output is correct
15 Correct 92 ms 99012 KB Output is correct
16 Correct 77 ms 95804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 95716 KB Output is correct
2 Correct 66 ms 95596 KB Output is correct
3 Correct 68 ms 95556 KB Output is correct
4 Correct 67 ms 95556 KB Output is correct
5 Correct 77 ms 95600 KB Output is correct
6 Correct 79 ms 95592 KB Output is correct
7 Correct 66 ms 95544 KB Output is correct
8 Correct 72 ms 95556 KB Output is correct
9 Correct 69 ms 95556 KB Output is correct
10 Correct 67 ms 95552 KB Output is correct
11 Correct 68 ms 95552 KB Output is correct
12 Correct 77 ms 95540 KB Output is correct
13 Correct 76 ms 95516 KB Output is correct
14 Correct 73 ms 95508 KB Output is correct
15 Correct 67 ms 95556 KB Output is correct
16 Correct 67 ms 95640 KB Output is correct
17 Correct 76 ms 95652 KB Output is correct
18 Correct 65 ms 95552 KB Output is correct
19 Correct 66 ms 95512 KB Output is correct
20 Correct 67 ms 95536 KB Output is correct
21 Correct 66 ms 95620 KB Output is correct
22 Correct 69 ms 95788 KB Output is correct
23 Correct 69 ms 95508 KB Output is correct
24 Correct 65 ms 95600 KB Output is correct
25 Correct 83 ms 95740 KB Output is correct
26 Correct 81 ms 96684 KB Output is correct
27 Correct 70 ms 96376 KB Output is correct
28 Correct 66 ms 95596 KB Output is correct
29 Correct 83 ms 97588 KB Output is correct
30 Correct 88 ms 102512 KB Output is correct
31 Correct 72 ms 95584 KB Output is correct
32 Correct 64 ms 95564 KB Output is correct
33 Correct 68 ms 96580 KB Output is correct
34 Correct 75 ms 95528 KB Output is correct
35 Correct 83 ms 100920 KB Output is correct
36 Correct 71 ms 97396 KB Output is correct
37 Correct 71 ms 95796 KB Output is correct
38 Correct 101 ms 106684 KB Output is correct
39 Correct 65 ms 95684 KB Output is correct
40 Correct 78 ms 95632 KB Output is correct
41 Correct 102 ms 106848 KB Output is correct
42 Correct 68 ms 95688 KB Output is correct
43 Correct 67 ms 95688 KB Output is correct
44 Correct 66 ms 95684 KB Output is correct
45 Correct 82 ms 101560 KB Output is correct
46 Correct 106 ms 111888 KB Output is correct
47 Correct 73 ms 95980 KB Output is correct
48 Correct 112 ms 109600 KB Output is correct
49 Correct 79 ms 95656 KB Output is correct
50 Correct 118 ms 110020 KB Output is correct
51 Correct 115 ms 110716 KB Output is correct
52 Correct 109 ms 109988 KB Output is correct
53 Correct 117 ms 109716 KB Output is correct
54 Correct 131 ms 109664 KB Output is correct
55 Correct 127 ms 109480 KB Output is correct
56 Correct 107 ms 109728 KB Output is correct
57 Correct 116 ms 110060 KB Output is correct
58 Correct 115 ms 109688 KB Output is correct
59 Correct 120 ms 109156 KB Output is correct
60 Correct 111 ms 109112 KB Output is correct
61 Correct 106 ms 109100 KB Output is correct
62 Correct 114 ms 108944 KB Output is correct
63 Correct 87 ms 99008 KB Output is correct
64 Correct 92 ms 99012 KB Output is correct
65 Correct 77 ms 95804 KB Output is correct
66 Correct 80 ms 95784 KB Output is correct
67 Correct 263 ms 167024 KB Output is correct
68 Correct 278 ms 165484 KB Output is correct
69 Correct 277 ms 165304 KB Output is correct
70 Correct 69 ms 95924 KB Output is correct
71 Correct 69 ms 96048 KB Output is correct
72 Correct 221 ms 170728 KB Output is correct
73 Correct 291 ms 174372 KB Output is correct
74 Correct 74 ms 96276 KB Output is correct
75 Correct 265 ms 165776 KB Output is correct
76 Correct 70 ms 96072 KB Output is correct
77 Correct 68 ms 95756 KB Output is correct
78 Incorrect 77 ms 95748 KB Output isn't correct
79 Halted 0 ms 0 KB -