結果
問題 | No.845 最長の切符 |
ユーザー | ok |
提出日時 | 2019-06-29 00:01:14 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 56 ms / 3,000 ms |
コード長 | 1,158 bytes |
コンパイル時間 | 541 ms |
コンパイル使用メモリ | 72,532 KB |
実行使用メモリ | 18,812 KB |
最終ジャッジ日時 | 2023-09-14 22:48:24 |
合計ジャッジ時間 | 2,190 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
7,748 KB |
testcase_01 | AC | 3 ms
9,776 KB |
testcase_02 | AC | 4 ms
11,580 KB |
testcase_03 | AC | 2 ms
5,448 KB |
testcase_04 | AC | 2 ms
7,488 KB |
testcase_05 | AC | 3 ms
7,536 KB |
testcase_06 | AC | 2 ms
7,472 KB |
testcase_07 | AC | 2 ms
7,488 KB |
testcase_08 | AC | 3 ms
11,572 KB |
testcase_09 | AC | 3 ms
9,708 KB |
testcase_10 | AC | 5 ms
13,720 KB |
testcase_11 | AC | 3 ms
9,552 KB |
testcase_12 | AC | 3 ms
11,588 KB |
testcase_13 | AC | 3 ms
9,520 KB |
testcase_14 | AC | 3 ms
11,588 KB |
testcase_15 | AC | 14 ms
15,984 KB |
testcase_16 | AC | 51 ms
18,764 KB |
testcase_17 | AC | 13 ms
15,976 KB |
testcase_18 | AC | 26 ms
18,300 KB |
testcase_19 | AC | 8 ms
15,800 KB |
testcase_20 | AC | 52 ms
18,812 KB |
testcase_21 | AC | 56 ms
18,736 KB |
testcase_22 | AC | 13 ms
16,040 KB |
testcase_23 | AC | 6 ms
13,696 KB |
testcase_24 | AC | 51 ms
18,740 KB |
testcase_25 | AC | 1 ms
4,376 KB |
testcase_26 | AC | 49 ms
18,812 KB |
testcase_27 | AC | 2 ms
5,436 KB |
testcase_28 | AC | 49 ms
18,744 KB |
testcase_29 | AC | 2 ms
4,376 KB |
ソースコード
#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> using namespace std; #define int long long #define rep(i,n) for(int i = 0; i < (n); i++) #define endl "\n" const long long INF = (long long)1e18; const long long MOD = (long long)1e9 + 7; string yn(bool f){return f?"Yes":"No";} string YN(bool f){return f?"YES":"NO";} #define MAX 20 signed main(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); int N, M; int a, b, c; int ans = 0; static int cost[MAX][MAX]; static int dp[MAX][(1<<17)]; cin>>N>>M; for(int i = 0; i < M; i++){ cin>>a>>b>>c; a--, b--; cost[a][b] = max(cost[a][b], c); cost[b][a] = max(cost[b][a], c); } for(int i = 1; i < (1<<N); i++){ for(int j = 0; j < N; j++){ if(!(i&(1<<j))) continue; int bit = i&(~(1<<j)); int maximum = 0; for(int k = 0; k < N; k++){ if(!(bit&(1<<k))) continue; if(!cost[k][j]) continue; // if(dp[k][bit] <= 0) continue; maximum = max(maximum, dp[k][bit] + cost[k][j]); } dp[j][i] = maximum; ans = max(maximum, ans); } } cout<<ans<<endl; return 0; }