Submission #429546

# Submission time Handle Problem Language Result Execution time Memory
429546 2021-06-16T06:01:04 Z 송준혁(#7525) Brackets (CPSPC17_brackets) C++17
74 / 100
124 ms 5972 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];
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] = MOD;
	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()){
		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 (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 2 ms 1356 KB Output is correct
5 Correct 3 ms 1356 KB Output is correct
6 Correct 2 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 1 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 2 ms 1356 KB Output is correct
5 Correct 3 ms 1356 KB Output is correct
6 Correct 2 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 1 ms 1356 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 1 ms 1356 KB Output is correct
15 Correct 2 ms 1420 KB Output is correct
16 Correct 2 ms 1404 KB Output is correct
17 Correct 2 ms 1356 KB Output is correct
18 Correct 1 ms 1356 KB Output is correct
19 Correct 2 ms 1356 KB Output is correct
20 Correct 1 ms 1356 KB Output is correct
21 Correct 2 ms 1356 KB Output is correct
22 Correct 2 ms 1356 KB Output is correct
23 Correct 2 ms 1356 KB Output is correct
24 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 2 ms 1356 KB Output is correct
5 Correct 3 ms 1356 KB Output is correct
6 Correct 2 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 1 ms 1356 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 1 ms 1356 KB Output is correct
15 Correct 2 ms 1420 KB Output is correct
16 Correct 2 ms 1404 KB Output is correct
17 Correct 2 ms 1356 KB Output is correct
18 Correct 1 ms 1356 KB Output is correct
19 Correct 2 ms 1356 KB Output is correct
20 Correct 1 ms 1356 KB Output is correct
21 Correct 2 ms 1356 KB Output is correct
22 Correct 2 ms 1356 KB Output is correct
23 Correct 2 ms 1356 KB Output is correct
24 Correct 2 ms 1356 KB Output is correct
25 Correct 2 ms 1484 KB Output is correct
26 Correct 4 ms 1612 KB Output is correct
27 Correct 5 ms 1740 KB Output is correct
28 Correct 2 ms 1484 KB Output is correct
29 Correct 7 ms 1996 KB Output is correct
30 Correct 41 ms 3656 KB Output is correct
31 Correct 2 ms 1484 KB Output is correct
32 Correct 2 ms 1484 KB Output is correct
33 Correct 4 ms 1484 KB Output is correct
34 Correct 2 ms 1484 KB Output is correct
35 Correct 12 ms 4240 KB Output is correct
36 Correct 9 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 2 ms 1356 KB Output is correct
5 Correct 3 ms 1356 KB Output is correct
6 Correct 2 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 1 ms 1356 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 1 ms 1356 KB Output is correct
15 Correct 2 ms 1420 KB Output is correct
16 Correct 2 ms 1404 KB Output is correct
17 Correct 2 ms 1356 KB Output is correct
18 Correct 1 ms 1356 KB Output is correct
19 Correct 2 ms 1356 KB Output is correct
20 Correct 1 ms 1356 KB Output is correct
21 Correct 2 ms 1356 KB Output is correct
22 Correct 2 ms 1356 KB Output is correct
23 Correct 2 ms 1356 KB Output is correct
24 Correct 2 ms 1356 KB Output is correct
25 Correct 2 ms 1484 KB Output is correct
26 Correct 4 ms 1612 KB Output is correct
27 Correct 5 ms 1740 KB Output is correct
28 Correct 2 ms 1484 KB Output is correct
29 Correct 7 ms 1996 KB Output is correct
30 Correct 41 ms 3656 KB Output is correct
31 Correct 2 ms 1484 KB Output is correct
32 Correct 2 ms 1484 KB Output is correct
33 Correct 4 ms 1484 KB Output is correct
34 Correct 2 ms 1484 KB Output is correct
35 Correct 12 ms 4240 KB Output is correct
36 Correct 9 ms 1868 KB Output is correct
37 Correct 3 ms 1484 KB Output is correct
38 Correct 16 ms 4396 KB Output is correct
39 Correct 2 ms 1484 KB Output is correct
40 Correct 2 ms 1484 KB Output is correct
41 Correct 28 ms 5444 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 17 ms 4332 KB Output is correct
46 Correct 48 ms 5432 KB Output is correct
47 Correct 3 ms 1612 KB Output is correct
48 Correct 57 ms 3912 KB Output is correct
49 Correct 2 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 4360 KB Output is correct
2 Correct 54 ms 4368 KB Output is correct
3 Correct 48 ms 4308 KB Output is correct
4 Correct 53 ms 4296 KB Output is correct
5 Correct 44 ms 4244 KB Output is correct
6 Correct 47 ms 4304 KB Output is correct
7 Correct 59 ms 4304 KB Output is correct
8 Correct 51 ms 4408 KB Output is correct
9 Correct 47 ms 4304 KB Output is correct
10 Correct 48 ms 4308 KB Output is correct
11 Correct 45 ms 4304 KB Output is correct
12 Correct 45 ms 4368 KB Output is correct
13 Correct 44 ms 4304 KB Output is correct
14 Correct 12 ms 3532 KB Output is correct
15 Correct 16 ms 3660 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 3 ms 1356 KB Output is correct
6 Correct 2 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 1 ms 1356 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 1 ms 1356 KB Output is correct
15 Correct 2 ms 1420 KB Output is correct
16 Correct 2 ms 1404 KB Output is correct
17 Correct 2 ms 1356 KB Output is correct
18 Correct 1 ms 1356 KB Output is correct
19 Correct 2 ms 1356 KB Output is correct
20 Correct 1 ms 1356 KB Output is correct
21 Correct 2 ms 1356 KB Output is correct
22 Correct 2 ms 1356 KB Output is correct
23 Correct 2 ms 1356 KB Output is correct
24 Correct 2 ms 1356 KB Output is correct
25 Correct 2 ms 1484 KB Output is correct
26 Correct 4 ms 1612 KB Output is correct
27 Correct 5 ms 1740 KB Output is correct
28 Correct 2 ms 1484 KB Output is correct
29 Correct 7 ms 1996 KB Output is correct
30 Correct 41 ms 3656 KB Output is correct
31 Correct 2 ms 1484 KB Output is correct
32 Correct 2 ms 1484 KB Output is correct
33 Correct 4 ms 1484 KB Output is correct
34 Correct 2 ms 1484 KB Output is correct
35 Correct 12 ms 4240 KB Output is correct
36 Correct 9 ms 1868 KB Output is correct
37 Correct 3 ms 1484 KB Output is correct
38 Correct 16 ms 4396 KB Output is correct
39 Correct 2 ms 1484 KB Output is correct
40 Correct 2 ms 1484 KB Output is correct
41 Correct 28 ms 5444 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 17 ms 4332 KB Output is correct
46 Correct 48 ms 5432 KB Output is correct
47 Correct 3 ms 1612 KB Output is correct
48 Correct 57 ms 3912 KB Output is correct
49 Correct 2 ms 1484 KB Output is correct
50 Correct 56 ms 4360 KB Output is correct
51 Correct 54 ms 4368 KB Output is correct
52 Correct 48 ms 4308 KB Output is correct
53 Correct 53 ms 4296 KB Output is correct
54 Correct 44 ms 4244 KB Output is correct
55 Correct 47 ms 4304 KB Output is correct
56 Correct 59 ms 4304 KB Output is correct
57 Correct 51 ms 4408 KB Output is correct
58 Correct 47 ms 4304 KB Output is correct
59 Correct 48 ms 4308 KB Output is correct
60 Correct 45 ms 4304 KB Output is correct
61 Correct 45 ms 4368 KB Output is correct
62 Correct 44 ms 4304 KB Output is correct
63 Correct 12 ms 3532 KB Output is correct
64 Correct 16 ms 3660 KB Output is correct
65 Correct 2 ms 1612 KB Output is correct
66 Correct 3 ms 1612 KB Output is correct
67 Correct 124 ms 5972 KB Output is correct
68 Correct 119 ms 5944 KB Output is correct
69 Correct 119 ms 5884 KB Output is correct
70 Correct 4 ms 1656 KB Output is correct
71 Correct 4 ms 1740 KB Output is correct
72 Correct 50 ms 5824 KB Output is correct
73 Correct 100 ms 5848 KB Output is correct
74 Correct 6 ms 1904 KB Output is correct
75 Correct 106 ms 4988 KB Output is correct
76 Correct 5 ms 1740 KB Output is correct
77 Correct 2 ms 1612 KB Output is correct
78 Incorrect 3 ms 1612 KB Output isn't correct
79 Halted 0 ms 0 KB -