結果
| 問題 | No.798 コレクション |
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2018-08-05 00:43:43 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 864 bytes |
| 記録 | |
| コンパイル時間 | 480 ms |
| コンパイル使用メモリ | 95,544 KB |
| 実行使用メモリ | 15,816 KB |
| 最終ジャッジ日時 | 2026-03-17 15:51:57 |
| 合計ジャッジ時間 | 22,970 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 3 RE * 2 TLE * 7 |
ソースコード
#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;
}
ikd