結果

問題 No.733 分身並列コーディング
ユーザー chocoruskchocorusk
提出日時 2018-09-18 13:58:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,322 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 73,896 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-25 09:47:03
合計ジャッジ時間 17,214 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 893 ms
4,376 KB
testcase_08 AC 891 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 12 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 93 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 283 ms
4,380 KB
testcase_20 AC 283 ms
4,380 KB
testcase_21 AC 93 ms
4,380 KB
testcase_22 AC 890 ms
4,380 KB
testcase_23 AC 93 ms
4,376 KB
testcase_24 AC 94 ms
4,380 KB
testcase_25 WA -
testcase_26 AC 2 ms
4,380 KB
testcase_27 WA -
testcase_28 AC 894 ms
4,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 31 ms
4,376 KB
testcase_33 AC 31 ms
4,376 KB
testcase_34 AC 30 ms
4,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 31 ms
4,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 889 ms
4,376 KB
testcase_41 AC 31 ms
4,376 KB
testcase_42 AC 31 ms
4,380 KB
testcase_43 AC 31 ms
4,376 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 889 ms
4,376 KB
testcase_47 AC 898 ms
4,380 KB
testcase_48 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF=1e7;
int main()
{
  int n, T;
  cin>>T; cin>>n;
  int t[17];
  int sum=0;
  for(int i=0; i<n; i++){
    cin>>t[i];
    sum+=t[i];
  }
  if(sum<=T){
    cout<<1<<endl;
    return 0;
  }
  bool nuee=1;
  for(int i=0; i<n; i++){
    for(int j=0; j<i; j++){
      if(t[i]+t[j]<=T){
        swap(t[i], t[n-1]);
        nuee=0;
        break;
      }
    }
    if(!nuee) break;
  }
  if(nuee){
    cout<<n<<endl;
    return 0;
  }
  int dp[1<<17];
  for(int i=1; i<(1<<n); i++){
    int s=0;
    for(int j=0; j<n; j++){
      if(i&(1<<j)) s+=t[j];
    }
    if(s<=T) dp[i]=1;
    else dp[i]=INF;
  }
  int p3=1;
  for(int i=0; i<n-2; i++) p3*=3;
  for(int i=0; i<p3; i++){
    int a=0, a1=0, i1=i, i2=0;
    while(i1>0){
      if(i1%3==1){
        a+=(1<<i2);
      }else if(i1%3==2){
        a1+=(1<<i2);
      }
      i2++;
      i1/=3;
    }
    if(a==0 || a1==0) continue;
    dp[a+a1]=min(dp[a+a1], dp[a]+dp[a1]);
  }
  int ans=INF;
  for(int i=1; i<(1<<n)-1; i++){
    ans=min(ans, dp[i]+dp[(1<<n)-1-i]);
  }
  cout<<ans<<endl;
	return 0;
}
0