Submission #429547

# Submission time Handle Problem Language Result Execution time Memory
429547 2021-06-16T06:03:37 Z 송준혁(#7525) Brackets (CPSPC17_brackets) C++17
100 / 100
136 ms 8256 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<<61)
using namespace std;
typedef long long LL;
typedef pair<LL,int> pii;

int N, M, S, T;
LL D[220][220];
bool vis[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] = INF;
	for (int i=1; i<=N; i++) PQ.push(pii(0, i*(N+1)+i)), D[i][i] = 0;
	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()){
		LL 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("%lld\n", 2*d);
			return 0;
		}
		if (vis[a][b]) continue;
		vis[a][b] = true;
		for (int v : adj[a][b]) PQ.push(pii(-d-1, v));
		for (int i=1; i<=N; i++){
			if (D[i][b] > D[i][a] + d) D[i][b] = D[i][a] + d, PQ.push(pii(-D[i][a]-d, i*(N+1) + b));
			if (D[a][i] > D[b][i] + d) D[a][i] = D[b][i] + d, 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:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%d %d %d %d", &N, &M, &S, &T);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   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 1 ms 1356 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 2 ms 1356 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 2 ms 1356 KB Output is correct
12 Correct 2 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 1 ms 1356 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 2 ms 1356 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 2 ms 1356 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1356 KB Output is correct
15 Correct 1 ms 1484 KB Output is correct
16 Correct 1 ms 1484 KB Output is correct
17 Correct 1 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 1 ms 1484 KB Output is correct
21 Correct 2 ms 1484 KB Output is correct
22 Correct 1 ms 1484 KB Output is correct
23 Correct 1 ms 1484 KB Output is correct
24 Correct 1 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 1 ms 1356 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 2 ms 1356 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 2 ms 1356 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1356 KB Output is correct
15 Correct 1 ms 1484 KB Output is correct
16 Correct 1 ms 1484 KB Output is correct
17 Correct 1 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 1 ms 1484 KB Output is correct
21 Correct 2 ms 1484 KB Output is correct
22 Correct 1 ms 1484 KB Output is correct
23 Correct 1 ms 1484 KB Output is correct
24 Correct 1 ms 1484 KB Output is correct
25 Correct 2 ms 1484 KB Output is correct
26 Correct 3 ms 1740 KB Output is correct
27 Correct 5 ms 1868 KB Output is correct
28 Correct 1 ms 1484 KB Output is correct
29 Correct 7 ms 2384 KB Output is correct
30 Correct 43 ms 4292 KB Output is correct
31 Correct 1 ms 1484 KB Output is correct
32 Correct 2 ms 1484 KB Output is correct
33 Correct 2 ms 1612 KB Output is correct
34 Correct 1 ms 1484 KB Output is correct
35 Correct 11 ms 5268 KB Output is correct
36 Correct 8 ms 1996 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 1 ms 1356 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 2 ms 1356 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 2 ms 1356 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1356 KB Output is correct
15 Correct 1 ms 1484 KB Output is correct
16 Correct 1 ms 1484 KB Output is correct
17 Correct 1 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 1 ms 1484 KB Output is correct
21 Correct 2 ms 1484 KB Output is correct
22 Correct 1 ms 1484 KB Output is correct
23 Correct 1 ms 1484 KB Output is correct
24 Correct 1 ms 1484 KB Output is correct
25 Correct 2 ms 1484 KB Output is correct
26 Correct 3 ms 1740 KB Output is correct
27 Correct 5 ms 1868 KB Output is correct
28 Correct 1 ms 1484 KB Output is correct
29 Correct 7 ms 2384 KB Output is correct
30 Correct 43 ms 4292 KB Output is correct
31 Correct 1 ms 1484 KB Output is correct
32 Correct 2 ms 1484 KB Output is correct
33 Correct 2 ms 1612 KB Output is correct
34 Correct 1 ms 1484 KB Output is correct
35 Correct 11 ms 5268 KB Output is correct
36 Correct 8 ms 1996 KB Output is correct
37 Correct 2 ms 1612 KB Output is correct
38 Correct 16 ms 5568 KB Output is correct
39 Correct 4 ms 1612 KB Output is correct
40 Correct 2 ms 1612 KB Output is correct
41 Correct 33 ms 7536 KB Output is correct
42 Correct 2 ms 1740 KB Output is correct
43 Correct 2 ms 1612 KB Output is correct
44 Correct 2 ms 1612 KB Output is correct
45 Correct 16 ms 5520 KB Output is correct
46 Correct 53 ms 7620 KB Output is correct
47 Correct 3 ms 1740 KB Output is correct
48 Correct 74 ms 4548 KB Output is correct
49 Correct 1 ms 1612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 5052 KB Output is correct
2 Correct 49 ms 5060 KB Output is correct
3 Correct 49 ms 5068 KB Output is correct
4 Correct 48 ms 5060 KB Output is correct
5 Correct 52 ms 5072 KB Output is correct
6 Correct 57 ms 4964 KB Output is correct
7 Correct 45 ms 5060 KB Output is correct
8 Correct 63 ms 5080 KB Output is correct
9 Correct 46 ms 5072 KB Output is correct
10 Correct 46 ms 5072 KB Output is correct
11 Correct 52 ms 5052 KB Output is correct
12 Correct 46 ms 5060 KB Output is correct
13 Correct 48 ms 5072 KB Output is correct
14 Correct 12 ms 3788 KB Output is correct
15 Correct 15 ms 3880 KB Output is correct
16 Correct 2 ms 1868 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 1 ms 1356 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 2 ms 1356 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 2 ms 1356 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1356 KB Output is correct
15 Correct 1 ms 1484 KB Output is correct
16 Correct 1 ms 1484 KB Output is correct
17 Correct 1 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 1 ms 1484 KB Output is correct
21 Correct 2 ms 1484 KB Output is correct
22 Correct 1 ms 1484 KB Output is correct
23 Correct 1 ms 1484 KB Output is correct
24 Correct 1 ms 1484 KB Output is correct
25 Correct 2 ms 1484 KB Output is correct
26 Correct 3 ms 1740 KB Output is correct
27 Correct 5 ms 1868 KB Output is correct
28 Correct 1 ms 1484 KB Output is correct
29 Correct 7 ms 2384 KB Output is correct
30 Correct 43 ms 4292 KB Output is correct
31 Correct 1 ms 1484 KB Output is correct
32 Correct 2 ms 1484 KB Output is correct
33 Correct 2 ms 1612 KB Output is correct
34 Correct 1 ms 1484 KB Output is correct
35 Correct 11 ms 5268 KB Output is correct
36 Correct 8 ms 1996 KB Output is correct
37 Correct 2 ms 1612 KB Output is correct
38 Correct 16 ms 5568 KB Output is correct
39 Correct 4 ms 1612 KB Output is correct
40 Correct 2 ms 1612 KB Output is correct
41 Correct 33 ms 7536 KB Output is correct
42 Correct 2 ms 1740 KB Output is correct
43 Correct 2 ms 1612 KB Output is correct
44 Correct 2 ms 1612 KB Output is correct
45 Correct 16 ms 5520 KB Output is correct
46 Correct 53 ms 7620 KB Output is correct
47 Correct 3 ms 1740 KB Output is correct
48 Correct 74 ms 4548 KB Output is correct
49 Correct 1 ms 1612 KB Output is correct
50 Correct 49 ms 5052 KB Output is correct
51 Correct 49 ms 5060 KB Output is correct
52 Correct 49 ms 5068 KB Output is correct
53 Correct 48 ms 5060 KB Output is correct
54 Correct 52 ms 5072 KB Output is correct
55 Correct 57 ms 4964 KB Output is correct
56 Correct 45 ms 5060 KB Output is correct
57 Correct 63 ms 5080 KB Output is correct
58 Correct 46 ms 5072 KB Output is correct
59 Correct 46 ms 5072 KB Output is correct
60 Correct 52 ms 5052 KB Output is correct
61 Correct 46 ms 5060 KB Output is correct
62 Correct 48 ms 5072 KB Output is correct
63 Correct 12 ms 3788 KB Output is correct
64 Correct 15 ms 3880 KB Output is correct
65 Correct 2 ms 1868 KB Output is correct
66 Correct 2 ms 1868 KB Output is correct
67 Correct 123 ms 8180 KB Output is correct
68 Correct 128 ms 8256 KB Output is correct
69 Correct 135 ms 8124 KB Output is correct
70 Correct 4 ms 1996 KB Output is correct
71 Correct 4 ms 1868 KB Output is correct
72 Correct 43 ms 8184 KB Output is correct
73 Correct 113 ms 8124 KB Output is correct
74 Correct 7 ms 2084 KB Output is correct
75 Correct 111 ms 6068 KB Output is correct
76 Correct 6 ms 2124 KB Output is correct
77 Correct 3 ms 1740 KB Output is correct
78 Correct 6 ms 1868 KB Output is correct
79 Correct 111 ms 6020 KB Output is correct
80 Correct 136 ms 8168 KB Output is correct
81 Correct 6 ms 1996 KB Output is correct
82 Correct 7 ms 2124 KB Output is correct
83 Correct 41 ms 8084 KB Output is correct