結果

問題 No.845 最長の切符
ユーザー LayCurseLayCurse
提出日時 2019-06-28 21:42:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 3,000 ms
コード長 2,018 bytes
コンパイル時間 2,337 ms
コンパイル使用メモリ 199,500 KB
実行使用メモリ 7,636 KB
最終ジャッジ日時 2023-09-14 21:45:55
合計ジャッジ時間 3,993 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
5,592 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
5,680 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
5,560 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
5,424 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
5,648 KB
testcase_15 AC 13 ms
6,068 KB
testcase_16 AC 51 ms
7,460 KB
testcase_17 AC 12 ms
5,960 KB
testcase_18 AC 26 ms
6,528 KB
testcase_19 AC 7 ms
5,812 KB
testcase_20 AC 58 ms
7,636 KB
testcase_21 AC 51 ms
7,388 KB
testcase_22 AC 13 ms
5,988 KB
testcase_23 AC 4 ms
5,656 KB
testcase_24 AC 53 ms
7,520 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 5 ms
7,468 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 5 ms
7,576 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int M;
int d[16][16];
int dp[16][65537];
int main(){
  int Lj4PdHRW, i, j, k, res;
  rd(N);
  rd(M);
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      d[i][j] = -1;
    }
  }
  for(Lj4PdHRW=0;Lj4PdHRW<M;Lj4PdHRW++){
    rd(i);
    rd(j);
    rd(k);
    chmax(d[i-1][j-1], k);
    chmax(d[j-1][i-1], k);
  }
  for(i=0;i<N;i++){
    for(j=0;j<1<<N;j++){
      dp[i][j] = -1;
    }
  }
  for(i=0;i<N;i++){
    dp[i][1<<i] = 0;
  }
  res = 0;
  for(k=0;k<1<<N;k++){
    for(i=0;i<N;i++){
      if(dp[i][k] >= 0){
        for(j=0;j<N;j++){
          if(d[i][j]>0 && !(k&1<<j)){
            chmax(res,chmax(dp[j][k^(1<<j)], dp[i][k] + d[i][j]));
          }
        }
      }
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190626-1

// --- original code ---
// int N, M, d[16][16];
// int dp[16][65537];
// {
//   int i, j, k, res;
// 
//   rd(N,M);
//   rep(i,N) rep(j,N) d[i][j] = -1;
//   rep(M){
//     rd(i,j,k);
//     d[i-1][j-1] >?= k;
//     d[j-1][i-1] >?= k;
//   }
// 
//   rep(i,N) rep(j,1<<N) dp[i][j] = -1;
//   rep(i,N) dp[i][1<<i] = 0;
// 
//   res = 0;
//   rep(k,1<<N) rep(i,N) if(dp[i][k] >= 0) rep(j,N) if(d[i][j]>0 && !(k&1<<j)){
//     res >?= dp[j][k^(1<<j)] >?= dp[i][k] + d[i][j];
//   }
// 
//   wt(res);
// }
0