답안 #525344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
525344 2022-02-11T11:35:53 Z 79brue Mountains and Valleys (CCO20_day1problem3) C++14
3 / 25
7000 ms 82348 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m;
int dist[22][22];

int DP[1048576][20];

int main(){
    scanf("%d %d", &n, &m);
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            dist[i][j] = 1e9;
        }
    }

    for(int i=1; i<=m; i++){
        int x, y, c;
        scanf("%d %d %d", &x, &y, &c);
        dist[x][y] = dist[y][x] = c;
    }

    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    for(int i=0; i<(1<<n); i++) for(int j=0; j<=n; j++) DP[i][j] = 1e9;
    for(int i=0; i<n; i++) DP[(1<<i)][i] = 0;

    for(int d=1; d<(1<<n); d++){
        for(int i=0; i<n; i++){
            if((d>>i)&1){
//                printf("%d %d: %d\n", d, i, DP[d][i]);
                for(int j=0; j<n; j++){
                    DP[(d|(1<<j))][j] = min(DP[(d|(1<<j))][j], DP[d][i] + dist[i][j]);
                }
            }
        }
    }

    int ans = 1e9;
    for(int i=0; i<n; i++) ans = min(ans, DP[(1<<n)-1][i]);

    printf("%d", ans);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
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 %d", &x, &y, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 9 ms 2764 KB Output is correct
21 Correct 10 ms 2764 KB Output is correct
22 Correct 448 ms 82348 KB Output is correct
23 Correct 197 ms 41292 KB Output is correct
24 Correct 212 ms 41316 KB Output is correct
25 Correct 99 ms 20812 KB Output is correct
26 Correct 92 ms 20796 KB Output is correct
27 Correct 493 ms 82348 KB Output is correct
28 Correct 106 ms 20764 KB Output is correct
29 Correct 91 ms 20812 KB Output is correct
30 Correct 95 ms 20828 KB Output is correct
31 Correct 105 ms 20812 KB Output is correct
32 Correct 8 ms 2764 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 92 ms 20804 KB Output is correct
35 Correct 92 ms 20808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 9 ms 2764 KB Output is correct
21 Correct 10 ms 2764 KB Output is correct
22 Correct 448 ms 82348 KB Output is correct
23 Correct 197 ms 41292 KB Output is correct
24 Correct 212 ms 41316 KB Output is correct
25 Correct 99 ms 20812 KB Output is correct
26 Correct 92 ms 20796 KB Output is correct
27 Correct 493 ms 82348 KB Output is correct
28 Correct 106 ms 20764 KB Output is correct
29 Correct 91 ms 20812 KB Output is correct
30 Correct 95 ms 20828 KB Output is correct
31 Correct 105 ms 20812 KB Output is correct
32 Correct 8 ms 2764 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 92 ms 20804 KB Output is correct
35 Correct 92 ms 20808 KB Output is correct
36 Execution timed out 7005 ms 204 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 9 ms 2764 KB Output is correct
21 Correct 10 ms 2764 KB Output is correct
22 Correct 448 ms 82348 KB Output is correct
23 Correct 197 ms 41292 KB Output is correct
24 Correct 212 ms 41316 KB Output is correct
25 Correct 99 ms 20812 KB Output is correct
26 Correct 92 ms 20796 KB Output is correct
27 Correct 493 ms 82348 KB Output is correct
28 Correct 106 ms 20764 KB Output is correct
29 Correct 91 ms 20812 KB Output is correct
30 Correct 95 ms 20828 KB Output is correct
31 Correct 105 ms 20812 KB Output is correct
32 Correct 8 ms 2764 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 92 ms 20804 KB Output is correct
35 Correct 92 ms 20808 KB Output is correct
36 Execution timed out 7005 ms 204 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 9 ms 2764 KB Output is correct
21 Correct 10 ms 2764 KB Output is correct
22 Correct 448 ms 82348 KB Output is correct
23 Correct 197 ms 41292 KB Output is correct
24 Correct 212 ms 41316 KB Output is correct
25 Correct 99 ms 20812 KB Output is correct
26 Correct 92 ms 20796 KB Output is correct
27 Correct 493 ms 82348 KB Output is correct
28 Correct 106 ms 20764 KB Output is correct
29 Correct 91 ms 20812 KB Output is correct
30 Correct 95 ms 20828 KB Output is correct
31 Correct 105 ms 20812 KB Output is correct
32 Correct 8 ms 2764 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 92 ms 20804 KB Output is correct
35 Correct 92 ms 20808 KB Output is correct
36 Runtime error 2 ms 332 KB Execution killed with signal 11
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 9 ms 2764 KB Output is correct
21 Correct 10 ms 2764 KB Output is correct
22 Correct 448 ms 82348 KB Output is correct
23 Correct 197 ms 41292 KB Output is correct
24 Correct 212 ms 41316 KB Output is correct
25 Correct 99 ms 20812 KB Output is correct
26 Correct 92 ms 20796 KB Output is correct
27 Correct 493 ms 82348 KB Output is correct
28 Correct 106 ms 20764 KB Output is correct
29 Correct 91 ms 20812 KB Output is correct
30 Correct 95 ms 20828 KB Output is correct
31 Correct 105 ms 20812 KB Output is correct
32 Correct 8 ms 2764 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 92 ms 20804 KB Output is correct
35 Correct 92 ms 20808 KB Output is correct
36 Runtime error 2 ms 332 KB Execution killed with signal 11
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 9 ms 2764 KB Output is correct
21 Correct 10 ms 2764 KB Output is correct
22 Correct 448 ms 82348 KB Output is correct
23 Correct 197 ms 41292 KB Output is correct
24 Correct 212 ms 41316 KB Output is correct
25 Correct 99 ms 20812 KB Output is correct
26 Correct 92 ms 20796 KB Output is correct
27 Correct 493 ms 82348 KB Output is correct
28 Correct 106 ms 20764 KB Output is correct
29 Correct 91 ms 20812 KB Output is correct
30 Correct 95 ms 20828 KB Output is correct
31 Correct 105 ms 20812 KB Output is correct
32 Correct 8 ms 2764 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 92 ms 20804 KB Output is correct
35 Correct 92 ms 20808 KB Output is correct
36 Runtime error 2 ms 332 KB Execution killed with signal 11
37 Halted 0 ms 0 KB -