結果

問題 No.733 分身並列コーディング
ユーザー TomoyaTomoya
提出日時 2019-03-13 21:53:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 336 ms / 1,500 ms
コード長 1,993 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 97,068 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 06:03:17
合計ジャッジ時間 7,806 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 161 ms
4,376 KB
testcase_04 AC 161 ms
4,380 KB
testcase_05 AC 256 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 259 ms
4,380 KB
testcase_08 AC 265 ms
4,376 KB
testcase_09 AC 66 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 24 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 68 ms
4,380 KB
testcase_20 AC 78 ms
4,376 KB
testcase_21 AC 25 ms
4,380 KB
testcase_22 AC 207 ms
4,380 KB
testcase_23 AC 26 ms
4,380 KB
testcase_24 AC 32 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 285 ms
4,380 KB
testcase_29 AC 269 ms
4,376 KB
testcase_30 AC 277 ms
4,380 KB
testcase_31 AC 286 ms
4,376 KB
testcase_32 AC 16 ms
4,376 KB
testcase_33 AC 14 ms
4,380 KB
testcase_34 AC 16 ms
4,380 KB
testcase_35 AC 14 ms
4,380 KB
testcase_36 AC 16 ms
4,376 KB
testcase_37 AC 14 ms
4,376 KB
testcase_38 AC 280 ms
4,380 KB
testcase_39 AC 299 ms
4,380 KB
testcase_40 AC 308 ms
4,380 KB
testcase_41 AC 15 ms
4,376 KB
testcase_42 AC 14 ms
4,376 KB
testcase_43 AC 13 ms
4,380 KB
testcase_44 AC 315 ms
4,376 KB
testcase_45 AC 295 ms
4,376 KB
testcase_46 AC 300 ms
4,380 KB
testcase_47 AC 329 ms
4,376 KB
testcase_48 AC 336 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

//解説AC
//https://www.hamayanhamayan.com/entry/2018/09/07/232917
//O(N2^N)

const int INF = 1<<29;
int T, N;
int t[1000010];
int dp[1<<17];
bool ok[1<<17];

int
main(void){  
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cin >> T >> N;
  REP(i,N) cin >> t[i];   

  REP(bit,1<<N){
    int sm = 0;
    REP(i,N) if(bit & (1<<i)) sm += t[i];
    if(sm <= T) ok[bit] = true;
  }

  REP(bit,1<<N) dp[bit] = INF;
  dp[0] = 0;
  REP(bit,1<<N){
    for(int msk = bit; msk > 0; msk = (msk-1)&bit){
      //cerr << "bit:" << bitset<9>(bit) << " msk: " << bitset<9>(msk) << endl;
      if(ok[msk]) chmin(dp[bit], dp[bit-msk]+1);
    }
  }
  cout << dp[(1<<N)-1] << endl;
  return 0;
}
0