Submission #429532

# Submission time Handle Problem Language Result Execution time Memory
429532 2021-06-16T05:39:27 Z 송준혁(#7525) Brackets (CPSPC17_brackets) C++17
74 / 100
240 ms 104060 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[1010101], 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<=1000000; 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 <= 1000000 && i != u.fi) Q[D[i][u.fi] + d].pb(pii(i, u.se));
				if (D[u.se][i] + d <= 1000000 && 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 18 ms 25172 KB Output is correct
2 Correct 21 ms 25200 KB Output is correct
3 Correct 18 ms 25100 KB Output is correct
4 Correct 20 ms 25164 KB Output is correct
5 Correct 22 ms 25068 KB Output is correct
6 Correct 23 ms 25164 KB Output is correct
7 Correct 18 ms 25164 KB Output is correct
8 Correct 18 ms 25124 KB Output is correct
9 Correct 17 ms 25048 KB Output is correct
10 Correct 18 ms 25172 KB Output is correct
11 Correct 17 ms 25164 KB Output is correct
12 Correct 23 ms 25164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 25172 KB Output is correct
2 Correct 21 ms 25200 KB Output is correct
3 Correct 18 ms 25100 KB Output is correct
4 Correct 20 ms 25164 KB Output is correct
5 Correct 22 ms 25068 KB Output is correct
6 Correct 23 ms 25164 KB Output is correct
7 Correct 18 ms 25164 KB Output is correct
8 Correct 18 ms 25124 KB Output is correct
9 Correct 17 ms 25048 KB Output is correct
10 Correct 18 ms 25172 KB Output is correct
11 Correct 17 ms 25164 KB Output is correct
12 Correct 23 ms 25164 KB Output is correct
13 Correct 20 ms 25164 KB Output is correct
14 Correct 21 ms 25072 KB Output is correct
15 Correct 18 ms 25176 KB Output is correct
16 Correct 18 ms 25076 KB Output is correct
17 Correct 18 ms 25216 KB Output is correct
18 Correct 19 ms 25036 KB Output is correct
19 Correct 20 ms 25164 KB Output is correct
20 Correct 18 ms 25164 KB Output is correct
21 Correct 22 ms 25200 KB Output is correct
22 Correct 19 ms 25184 KB Output is correct
23 Correct 21 ms 25176 KB Output is correct
24 Correct 18 ms 25164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 25172 KB Output is correct
2 Correct 21 ms 25200 KB Output is correct
3 Correct 18 ms 25100 KB Output is correct
4 Correct 20 ms 25164 KB Output is correct
5 Correct 22 ms 25068 KB Output is correct
6 Correct 23 ms 25164 KB Output is correct
7 Correct 18 ms 25164 KB Output is correct
8 Correct 18 ms 25124 KB Output is correct
9 Correct 17 ms 25048 KB Output is correct
10 Correct 18 ms 25172 KB Output is correct
11 Correct 17 ms 25164 KB Output is correct
12 Correct 23 ms 25164 KB Output is correct
13 Correct 20 ms 25164 KB Output is correct
14 Correct 21 ms 25072 KB Output is correct
15 Correct 18 ms 25176 KB Output is correct
16 Correct 18 ms 25076 KB Output is correct
17 Correct 18 ms 25216 KB Output is correct
18 Correct 19 ms 25036 KB Output is correct
19 Correct 20 ms 25164 KB Output is correct
20 Correct 18 ms 25164 KB Output is correct
21 Correct 22 ms 25200 KB Output is correct
22 Correct 19 ms 25184 KB Output is correct
23 Correct 21 ms 25176 KB Output is correct
24 Correct 18 ms 25164 KB Output is correct
25 Correct 19 ms 25240 KB Output is correct
26 Correct 20 ms 26248 KB Output is correct
27 Correct 20 ms 25964 KB Output is correct
28 Correct 18 ms 25164 KB Output is correct
29 Correct 25 ms 27108 KB Output is correct
30 Correct 32 ms 31864 KB Output is correct
31 Correct 18 ms 25236 KB Output is correct
32 Correct 18 ms 25104 KB Output is correct
33 Correct 21 ms 26060 KB Output is correct
34 Correct 19 ms 25164 KB Output is correct
35 Correct 29 ms 30496 KB Output is correct
36 Correct 25 ms 26956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 25172 KB Output is correct
2 Correct 21 ms 25200 KB Output is correct
3 Correct 18 ms 25100 KB Output is correct
4 Correct 20 ms 25164 KB Output is correct
5 Correct 22 ms 25068 KB Output is correct
6 Correct 23 ms 25164 KB Output is correct
7 Correct 18 ms 25164 KB Output is correct
8 Correct 18 ms 25124 KB Output is correct
9 Correct 17 ms 25048 KB Output is correct
10 Correct 18 ms 25172 KB Output is correct
11 Correct 17 ms 25164 KB Output is correct
12 Correct 23 ms 25164 KB Output is correct
13 Correct 20 ms 25164 KB Output is correct
14 Correct 21 ms 25072 KB Output is correct
15 Correct 18 ms 25176 KB Output is correct
16 Correct 18 ms 25076 KB Output is correct
17 Correct 18 ms 25216 KB Output is correct
18 Correct 19 ms 25036 KB Output is correct
19 Correct 20 ms 25164 KB Output is correct
20 Correct 18 ms 25164 KB Output is correct
21 Correct 22 ms 25200 KB Output is correct
22 Correct 19 ms 25184 KB Output is correct
23 Correct 21 ms 25176 KB Output is correct
24 Correct 18 ms 25164 KB Output is correct
25 Correct 19 ms 25240 KB Output is correct
26 Correct 20 ms 26248 KB Output is correct
27 Correct 20 ms 25964 KB Output is correct
28 Correct 18 ms 25164 KB Output is correct
29 Correct 25 ms 27108 KB Output is correct
30 Correct 32 ms 31864 KB Output is correct
31 Correct 18 ms 25236 KB Output is correct
32 Correct 18 ms 25104 KB Output is correct
33 Correct 21 ms 26060 KB Output is correct
34 Correct 19 ms 25164 KB Output is correct
35 Correct 29 ms 30496 KB Output is correct
36 Correct 25 ms 26956 KB Output is correct
37 Correct 21 ms 25340 KB Output is correct
38 Correct 48 ms 36188 KB Output is correct
39 Correct 18 ms 25292 KB Output is correct
40 Correct 20 ms 25292 KB Output is correct
41 Correct 49 ms 36220 KB Output is correct
42 Correct 19 ms 25292 KB Output is correct
43 Correct 18 ms 25164 KB Output is correct
44 Correct 19 ms 25312 KB Output is correct
45 Correct 34 ms 31040 KB Output is correct
46 Correct 54 ms 41408 KB Output is correct
47 Correct 20 ms 25548 KB Output is correct
48 Correct 51 ms 39092 KB Output is correct
49 Correct 25 ms 25268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 39680 KB Output is correct
2 Correct 69 ms 40340 KB Output is correct
3 Correct 62 ms 39568 KB Output is correct
4 Correct 77 ms 39276 KB Output is correct
5 Correct 64 ms 39364 KB Output is correct
6 Correct 62 ms 38976 KB Output is correct
7 Correct 61 ms 39284 KB Output is correct
8 Correct 74 ms 39600 KB Output is correct
9 Correct 62 ms 39164 KB Output is correct
10 Correct 61 ms 38740 KB Output is correct
11 Correct 73 ms 38624 KB Output is correct
12 Correct 59 ms 38664 KB Output is correct
13 Correct 57 ms 38388 KB Output is correct
14 Correct 31 ms 28460 KB Output is correct
15 Correct 32 ms 28580 KB Output is correct
16 Correct 20 ms 25328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 25172 KB Output is correct
2 Correct 21 ms 25200 KB Output is correct
3 Correct 18 ms 25100 KB Output is correct
4 Correct 20 ms 25164 KB Output is correct
5 Correct 22 ms 25068 KB Output is correct
6 Correct 23 ms 25164 KB Output is correct
7 Correct 18 ms 25164 KB Output is correct
8 Correct 18 ms 25124 KB Output is correct
9 Correct 17 ms 25048 KB Output is correct
10 Correct 18 ms 25172 KB Output is correct
11 Correct 17 ms 25164 KB Output is correct
12 Correct 23 ms 25164 KB Output is correct
13 Correct 20 ms 25164 KB Output is correct
14 Correct 21 ms 25072 KB Output is correct
15 Correct 18 ms 25176 KB Output is correct
16 Correct 18 ms 25076 KB Output is correct
17 Correct 18 ms 25216 KB Output is correct
18 Correct 19 ms 25036 KB Output is correct
19 Correct 20 ms 25164 KB Output is correct
20 Correct 18 ms 25164 KB Output is correct
21 Correct 22 ms 25200 KB Output is correct
22 Correct 19 ms 25184 KB Output is correct
23 Correct 21 ms 25176 KB Output is correct
24 Correct 18 ms 25164 KB Output is correct
25 Correct 19 ms 25240 KB Output is correct
26 Correct 20 ms 26248 KB Output is correct
27 Correct 20 ms 25964 KB Output is correct
28 Correct 18 ms 25164 KB Output is correct
29 Correct 25 ms 27108 KB Output is correct
30 Correct 32 ms 31864 KB Output is correct
31 Correct 18 ms 25236 KB Output is correct
32 Correct 18 ms 25104 KB Output is correct
33 Correct 21 ms 26060 KB Output is correct
34 Correct 19 ms 25164 KB Output is correct
35 Correct 29 ms 30496 KB Output is correct
36 Correct 25 ms 26956 KB Output is correct
37 Correct 21 ms 25340 KB Output is correct
38 Correct 48 ms 36188 KB Output is correct
39 Correct 18 ms 25292 KB Output is correct
40 Correct 20 ms 25292 KB Output is correct
41 Correct 49 ms 36220 KB Output is correct
42 Correct 19 ms 25292 KB Output is correct
43 Correct 18 ms 25164 KB Output is correct
44 Correct 19 ms 25312 KB Output is correct
45 Correct 34 ms 31040 KB Output is correct
46 Correct 54 ms 41408 KB Output is correct
47 Correct 20 ms 25548 KB Output is correct
48 Correct 51 ms 39092 KB Output is correct
49 Correct 25 ms 25268 KB Output is correct
50 Correct 67 ms 39680 KB Output is correct
51 Correct 69 ms 40340 KB Output is correct
52 Correct 62 ms 39568 KB Output is correct
53 Correct 77 ms 39276 KB Output is correct
54 Correct 64 ms 39364 KB Output is correct
55 Correct 62 ms 38976 KB Output is correct
56 Correct 61 ms 39284 KB Output is correct
57 Correct 74 ms 39600 KB Output is correct
58 Correct 62 ms 39164 KB Output is correct
59 Correct 61 ms 38740 KB Output is correct
60 Correct 73 ms 38624 KB Output is correct
61 Correct 59 ms 38664 KB Output is correct
62 Correct 57 ms 38388 KB Output is correct
63 Correct 31 ms 28460 KB Output is correct
64 Correct 32 ms 28580 KB Output is correct
65 Correct 20 ms 25328 KB Output is correct
66 Correct 21 ms 25280 KB Output is correct
67 Correct 204 ms 96532 KB Output is correct
68 Correct 195 ms 94904 KB Output is correct
69 Correct 209 ms 94964 KB Output is correct
70 Correct 19 ms 25548 KB Output is correct
71 Correct 21 ms 25548 KB Output is correct
72 Correct 176 ms 100292 KB Output is correct
73 Correct 240 ms 104060 KB Output is correct
74 Correct 23 ms 25844 KB Output is correct
75 Correct 203 ms 95364 KB Output is correct
76 Correct 21 ms 25676 KB Output is correct
77 Correct 19 ms 25292 KB Output is correct
78 Incorrect 23 ms 25372 KB Output isn't correct
79 Halted 0 ms 0 KB -