結果

問題 No.798 コレクション
ユーザー ikd
提出日時 2018-08-05 00:43:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 864 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 77,560 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-06-28 16:53:40
合計ジャッジ時間 4,395 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 1 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)

int main(){

  int n; cin>> n;
  vector<int> a(n), b(n); 
  rep(i, n) cin>> a[i]>> b[i];

  const int inf=1e9;
  vector<int> memo(1<<n, inf);
  function<int(int)> f=[&](int state)->int{
    if(state==0) return 0;
    if(memo[state]<inf) return memo[state];
    int &ret=memo[state];
    int cnt=n-__builtin_popcount(state),
        day=cnt-cnt/3;
    rep(i, n)if(state&(1<<i)){
      auto s=a[i]+b[i]*day, nexstate=state^(1<<i);
      if(day%2==1){
        if(nexstate==0) ret=min(ret, s+f(nexstate));
        rep(j, n)if(nexstate&(1<<j)){
          ret=min(ret, s+f(nexstate^(1<<j)));
        }
      }else{
        ret=min(ret, s+f(nexstate));
      }
    }
    return ret;
  };

  cout<< f((1<<n)-1)<< endl;
  return 0;
}
0