답안 #429526

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

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

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);
    }
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            if (i==j) {
                dist[i][j]=0;
            }
            else {
                dist[i][j]=INF;
            }
        }
    }
    for(int ind=0;ind<n*n;ind++) {
        int xpos=0;
        int ypos=0;
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++) {
                dist2[i][j]=dist[i][j];
                if (!vis[i][j]) {
                    if (vis[xpos][ypos]||dist[i][j]<dist[xpos][ypos]) {
                        xpos=i;
                        ypos=j;
                    }
                }
            }
        }
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++) {
                for(int k=0;k<4;k++) {
                    if ((arr[i][xpos]&(1<<k))&&(arr[ypos][j]&(1<<(7-k)))) {
                        dist[i][j]=min(dist[i][j],dist2[xpos][ypos]+2);
                    }
                }
            }
        }
        for(int i=0;i<n;i++) {
            dist[xpos][i]=min(dist[xpos][i],dist2[xpos][ypos]+dist2[ypos][i]);
            dist[i][ypos]=min(dist[i][ypos],dist2[i][xpos]+dist2[xpos][ypos]);
        }
        vis[xpos][ypos]=true;
    }
    printf("%lld\n",dist[s][t]>INF/2?-1:dist[s][t]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d %d %d %d",&n,&m,&s,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%d %d %c",&u,&v,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 348 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 2 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 2 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 32 ms 460 KB Output is correct
26 Correct 58 ms 460 KB Output is correct
27 Correct 54 ms 484 KB Output is correct
28 Correct 50 ms 460 KB Output is correct
29 Correct 56 ms 460 KB Output is correct
30 Correct 59 ms 500 KB Output is correct
31 Correct 64 ms 460 KB Output is correct
32 Correct 65 ms 484 KB Output is correct
33 Correct 57 ms 488 KB Output is correct
34 Correct 54 ms 500 KB Output is correct
35 Correct 58 ms 460 KB Output is correct
36 Correct 58 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 2 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 32 ms 460 KB Output is correct
26 Correct 58 ms 460 KB Output is correct
27 Correct 54 ms 484 KB Output is correct
28 Correct 50 ms 460 KB Output is correct
29 Correct 56 ms 460 KB Output is correct
30 Correct 59 ms 500 KB Output is correct
31 Correct 64 ms 460 KB Output is correct
32 Correct 65 ms 484 KB Output is correct
33 Correct 57 ms 488 KB Output is correct
34 Correct 54 ms 500 KB Output is correct
35 Correct 58 ms 460 KB Output is correct
36 Correct 58 ms 460 KB Output is correct
37 Execution timed out 814 ms 700 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1095 ms 972 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 2 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 32 ms 460 KB Output is correct
26 Correct 58 ms 460 KB Output is correct
27 Correct 54 ms 484 KB Output is correct
28 Correct 50 ms 460 KB Output is correct
29 Correct 56 ms 460 KB Output is correct
30 Correct 59 ms 500 KB Output is correct
31 Correct 64 ms 460 KB Output is correct
32 Correct 65 ms 484 KB Output is correct
33 Correct 57 ms 488 KB Output is correct
34 Correct 54 ms 500 KB Output is correct
35 Correct 58 ms 460 KB Output is correct
36 Correct 58 ms 460 KB Output is correct
37 Execution timed out 814 ms 700 KB Time limit exceeded
38 Halted 0 ms 0 KB -