답안 #429552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429552 2021-06-16T06:30:43 Z 조영욱(#7653) Brackets (CPSPC17_brackets) C++17
100 / 100
209 ms 10656 KB
#include <bits/stdc++.h>
using namespace std;

char str[8]={'(','{','[','<','>',']','}',')'};
bool vis[200][200][5];
long long dist[200][200][5];
int arr[200][200];
int n,m;
const long long INF=2e18;
typedef pair<long long,long long> P;
typedef pair<P,P> PP;
typedef pair<P,int> Pi;

int main(void) {
    int s,t;
    scanf("%d %d %d %d",&n,&m,&s,&t);
    s--;
    t--;
    for(int i=0;i<m;i++) {
        int u,v;
        char c;
        scanf("%d %d %c",&u,&v,&c);
        u--;
        v--;
        int val=-1;
        for(int j=0;j<8;j++) {
            if (str[j]==c){
                val=j;
                break;
            }
        }
        if (val!=-1)
        arr[u][v]|=(1<<val);
    }
    priority_queue<PP,vector<PP>,greater<PP>> pq;
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            for(int k=0;k<5;k++) {
                if (i==j&&k==4) {
                    dist[i][j][k]=0;
                    pq.push(PP(P(0,k),P(i,j)));
                }
                else {
                    dist[i][j][k]=INF;
                }
            }
        }
    }
    while (!pq.empty()) {
        Pi now;
        do {
            now=Pi(pq.top().second,pq.top().first.second);
            pq.pop();
        } while (!pq.empty()&&vis[now.first.first][now.first.second][now.second]);
        int xpos=now.first.first;
        int ypos=now.first.second;
        int type=now.second;
        if (vis[xpos][ypos][type]) {
            break;
        }
        vis[xpos][ypos][type]=true;
        if (now.second==4) {
            for(int i=0;i<n;i++) {
                for(int k=0;k<4;k++) {
                    if ((arr[i][xpos]&(1<<k))) {
                        if (dist[xpos][ypos][type]+1<dist[i][ypos][k]) {
                            dist[i][ypos][k]=dist[xpos][ypos][type]+1;
                            pq.push(PP(P(dist[i][ypos][k],k),P(i,ypos)));
                        }
                    }
                }
            }
            for(int i=0;i<n;i++) {
                if (dist[xpos][ypos][4]+dist[ypos][i][4]<dist[xpos][i][4]) {
                    dist[xpos][i][4]=dist[xpos][ypos][4]+dist[ypos][i][4];
                    pq.push(PP(P(dist[xpos][i][4],4),P(xpos,i)));
                }
                if (dist[i][xpos][4]+dist[xpos][ypos][4]<dist[i][ypos][4]) {
                    dist[i][ypos][4]=dist[i][xpos][4]+dist[xpos][ypos][4];
                    pq.push(PP(P(dist[i][ypos][4],4),P(i,ypos)));
                }
            }
        }
        else {
            for(int i=0;i<n;i++) {
                if (arr[ypos][i]&(1<<(7-type))) {
                    if (dist[xpos][ypos][type]+1<dist[xpos][i][4]) {
                        dist[xpos][i][4]=dist[xpos][ypos][type]+1;
                        pq.push(PP(P(dist[xpos][i][4],4),P(xpos,i)));
                    }
                }
            }
        }
    }
    printf("%lld\n",dist[s][t][4]>INF/2?-1:dist[s][t][4]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d %d %d %d",&n,&m,&s,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%d %d %c",&u,&v,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 5 ms 972 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 6 ms 972 KB Output is correct
30 Correct 7 ms 972 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 1 ms 588 KB Output is correct
35 Correct 7 ms 1224 KB Output is correct
36 Correct 6 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 5 ms 972 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 6 ms 972 KB Output is correct
30 Correct 7 ms 972 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 1 ms 588 KB Output is correct
35 Correct 7 ms 1224 KB Output is correct
36 Correct 6 ms 972 KB Output is correct
37 Correct 4 ms 1228 KB Output is correct
38 Correct 36 ms 2388 KB Output is correct
39 Correct 3 ms 1228 KB Output is correct
40 Correct 1 ms 1228 KB Output is correct
41 Correct 29 ms 2372 KB Output is correct
42 Correct 1 ms 1228 KB Output is correct
43 Correct 1 ms 1228 KB Output is correct
44 Correct 3 ms 1228 KB Output is correct
45 Correct 32 ms 2372 KB Output is correct
46 Correct 37 ms 2372 KB Output is correct
47 Correct 5 ms 1484 KB Output is correct
48 Correct 31 ms 2372 KB Output is correct
49 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 4324 KB Output is correct
2 Correct 74 ms 3332 KB Output is correct
3 Correct 69 ms 4328 KB Output is correct
4 Correct 73 ms 4276 KB Output is correct
5 Correct 66 ms 3268 KB Output is correct
6 Correct 66 ms 3288 KB Output is correct
7 Correct 66 ms 3268 KB Output is correct
8 Correct 72 ms 4416 KB Output is correct
9 Correct 68 ms 3268 KB Output is correct
10 Correct 67 ms 3268 KB Output is correct
11 Correct 69 ms 3268 KB Output is correct
12 Correct 66 ms 3276 KB Output is correct
13 Correct 76 ms 3268 KB Output is correct
14 Correct 11 ms 2380 KB Output is correct
15 Correct 13 ms 2380 KB Output is correct
16 Correct 2 ms 2124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 5 ms 972 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 6 ms 972 KB Output is correct
30 Correct 7 ms 972 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 1 ms 588 KB Output is correct
35 Correct 7 ms 1224 KB Output is correct
36 Correct 6 ms 972 KB Output is correct
37 Correct 4 ms 1228 KB Output is correct
38 Correct 36 ms 2388 KB Output is correct
39 Correct 3 ms 1228 KB Output is correct
40 Correct 1 ms 1228 KB Output is correct
41 Correct 29 ms 2372 KB Output is correct
42 Correct 1 ms 1228 KB Output is correct
43 Correct 1 ms 1228 KB Output is correct
44 Correct 3 ms 1228 KB Output is correct
45 Correct 32 ms 2372 KB Output is correct
46 Correct 37 ms 2372 KB Output is correct
47 Correct 5 ms 1484 KB Output is correct
48 Correct 31 ms 2372 KB Output is correct
49 Correct 1 ms 972 KB Output is correct
50 Correct 73 ms 4324 KB Output is correct
51 Correct 74 ms 3332 KB Output is correct
52 Correct 69 ms 4328 KB Output is correct
53 Correct 73 ms 4276 KB Output is correct
54 Correct 66 ms 3268 KB Output is correct
55 Correct 66 ms 3288 KB Output is correct
56 Correct 66 ms 3268 KB Output is correct
57 Correct 72 ms 4416 KB Output is correct
58 Correct 68 ms 3268 KB Output is correct
59 Correct 67 ms 3268 KB Output is correct
60 Correct 69 ms 3268 KB Output is correct
61 Correct 66 ms 3276 KB Output is correct
62 Correct 76 ms 3268 KB Output is correct
63 Correct 11 ms 2380 KB Output is correct
64 Correct 13 ms 2380 KB Output is correct
65 Correct 2 ms 2124 KB Output is correct
66 Correct 3 ms 2124 KB Output is correct
67 Correct 197 ms 10560 KB Output is correct
68 Correct 202 ms 10656 KB Output is correct
69 Correct 209 ms 6324 KB Output is correct
70 Correct 9 ms 2380 KB Output is correct
71 Correct 16 ms 2220 KB Output is correct
72 Correct 157 ms 6404 KB Output is correct
73 Correct 160 ms 6460 KB Output is correct
74 Correct 21 ms 2216 KB Output is correct
75 Correct 180 ms 6412 KB Output is correct
76 Correct 8 ms 2380 KB Output is correct
77 Correct 4 ms 1740 KB Output is correct
78 Correct 15 ms 2352 KB Output is correct
79 Correct 168 ms 6336 KB Output is correct
80 Correct 198 ms 10544 KB Output is correct
81 Correct 23 ms 2216 KB Output is correct
82 Correct 10 ms 1480 KB Output is correct
83 Correct 161 ms 6376 KB Output is correct