답안 #525557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
525557 2022-02-12T00:35:12 Z mjhmjh1104 Mountains and Valleys (CCO20_day1problem3) C++17
3 / 25
397 ms 82508 KB
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int n, m, dp[20][20971520];
vector<pair<int, int>> adj[20];

int f(int x, int y) {
    if (dp[x][y] + 1) return dp[x][y];
    if (!y) return dp[x][y] = 0;
    dp[x][y] = (int)1e9;
    for (auto &i: adj[x]) dp[x][y] = min(dp[x][y], i.second + f(i.first, y & ~(1 << i.first)));
    return dp[x][y];
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) for (int j = 0; j < 1 << n; j++) dp[i][j] = -1;
    while (m--) {
        int x, y, w;
        scanf("%d%d%d", &x, &y, &w);
        adj[x].push_back({ y, w });
        adj[y].push_back({ x, w });
    }
    int res = (int)1e9;
    for (int i = 0; i < n; i++) res = min(res, f(i, (1 << n) - 1 ^ 1 << i));
    printf("%d", res);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:28:62: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   28 |     for (int i = 0; i < n; i++) res = min(res, f(i, (1 << n) - 1 ^ 1 << i));
      |                                                     ~~~~~~~~~^~~
Main.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%d%d%d", &x, &y, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 0 ms 288 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 0 ms 288 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 280 KB Output is correct
17 Correct 0 ms 292 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 552 KB Output is correct
20 Correct 1 ms 2252 KB Output is correct
21 Correct 1 ms 2212 KB Output is correct
22 Correct 247 ms 82496 KB Output is correct
23 Correct 52 ms 39312 KB Output is correct
24 Correct 45 ms 39400 KB Output is correct
25 Correct 51 ms 18928 KB Output is correct
26 Correct 72 ms 18876 KB Output is correct
27 Correct 397 ms 82508 KB Output is correct
28 Correct 18 ms 18892 KB Output is correct
29 Correct 37 ms 18852 KB Output is correct
30 Correct 27 ms 18892 KB Output is correct
31 Correct 31 ms 18852 KB Output is correct
32 Correct 8 ms 2252 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 9 ms 18892 KB Output is correct
35 Correct 10 ms 18892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 552 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 0 ms 288 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 280 KB Output is correct
17 Correct 0 ms 292 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 552 KB Output is correct
20 Correct 1 ms 2252 KB Output is correct
21 Correct 1 ms 2212 KB Output is correct
22 Correct 247 ms 82496 KB Output is correct
23 Correct 52 ms 39312 KB Output is correct
24 Correct 45 ms 39400 KB Output is correct
25 Correct 51 ms 18928 KB Output is correct
26 Correct 72 ms 18876 KB Output is correct
27 Correct 397 ms 82508 KB Output is correct
28 Correct 18 ms 18892 KB Output is correct
29 Correct 37 ms 18852 KB Output is correct
30 Correct 27 ms 18892 KB Output is correct
31 Correct 31 ms 18852 KB Output is correct
32 Correct 8 ms 2252 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 9 ms 18892 KB Output is correct
35 Correct 10 ms 18892 KB Output is correct
36 Runtime error 9 ms 492 KB Execution killed with signal 11
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 0 ms 288 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 280 KB Output is correct
17 Correct 0 ms 292 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 552 KB Output is correct
20 Correct 1 ms 2252 KB Output is correct
21 Correct 1 ms 2212 KB Output is correct
22 Correct 247 ms 82496 KB Output is correct
23 Correct 52 ms 39312 KB Output is correct
24 Correct 45 ms 39400 KB Output is correct
25 Correct 51 ms 18928 KB Output is correct
26 Correct 72 ms 18876 KB Output is correct
27 Correct 397 ms 82508 KB Output is correct
28 Correct 18 ms 18892 KB Output is correct
29 Correct 37 ms 18852 KB Output is correct
30 Correct 27 ms 18892 KB Output is correct
31 Correct 31 ms 18852 KB Output is correct
32 Correct 8 ms 2252 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 9 ms 18892 KB Output is correct
35 Correct 10 ms 18892 KB Output is correct
36 Runtime error 9 ms 492 KB Execution killed with signal 11
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 0 ms 288 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 280 KB Output is correct
17 Correct 0 ms 292 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 552 KB Output is correct
20 Correct 1 ms 2252 KB Output is correct
21 Correct 1 ms 2212 KB Output is correct
22 Correct 247 ms 82496 KB Output is correct
23 Correct 52 ms 39312 KB Output is correct
24 Correct 45 ms 39400 KB Output is correct
25 Correct 51 ms 18928 KB Output is correct
26 Correct 72 ms 18876 KB Output is correct
27 Correct 397 ms 82508 KB Output is correct
28 Correct 18 ms 18892 KB Output is correct
29 Correct 37 ms 18852 KB Output is correct
30 Correct 27 ms 18892 KB Output is correct
31 Correct 31 ms 18852 KB Output is correct
32 Correct 8 ms 2252 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 9 ms 18892 KB Output is correct
35 Correct 10 ms 18892 KB Output is correct
36 Runtime error 8 ms 552 KB Execution killed with signal 11
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 0 ms 288 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 280 KB Output is correct
17 Correct 0 ms 292 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 552 KB Output is correct
20 Correct 1 ms 2252 KB Output is correct
21 Correct 1 ms 2212 KB Output is correct
22 Correct 247 ms 82496 KB Output is correct
23 Correct 52 ms 39312 KB Output is correct
24 Correct 45 ms 39400 KB Output is correct
25 Correct 51 ms 18928 KB Output is correct
26 Correct 72 ms 18876 KB Output is correct
27 Correct 397 ms 82508 KB Output is correct
28 Correct 18 ms 18892 KB Output is correct
29 Correct 37 ms 18852 KB Output is correct
30 Correct 27 ms 18892 KB Output is correct
31 Correct 31 ms 18852 KB Output is correct
32 Correct 8 ms 2252 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 9 ms 18892 KB Output is correct
35 Correct 10 ms 18892 KB Output is correct
36 Runtime error 8 ms 552 KB Execution killed with signal 11
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 0 ms 288 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 280 KB Output is correct
17 Correct 0 ms 292 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 552 KB Output is correct
20 Correct 1 ms 2252 KB Output is correct
21 Correct 1 ms 2212 KB Output is correct
22 Correct 247 ms 82496 KB Output is correct
23 Correct 52 ms 39312 KB Output is correct
24 Correct 45 ms 39400 KB Output is correct
25 Correct 51 ms 18928 KB Output is correct
26 Correct 72 ms 18876 KB Output is correct
27 Correct 397 ms 82508 KB Output is correct
28 Correct 18 ms 18892 KB Output is correct
29 Correct 37 ms 18852 KB Output is correct
30 Correct 27 ms 18892 KB Output is correct
31 Correct 31 ms 18852 KB Output is correct
32 Correct 8 ms 2252 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 9 ms 18892 KB Output is correct
35 Correct 10 ms 18892 KB Output is correct
36 Runtime error 8 ms 552 KB Execution killed with signal 11
37 Halted 0 ms 0 KB -