結果

問題 No.733 分身並列コーディング
コンテスト
ユーザー mamekin
提出日時 2018-09-15 13:27:30
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
(最新)
TLE  
(最初)
実行時間 1,186 ms / 1,500 ms
コード長 1,402 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 710 ms
コンパイル使用メモリ 144,484 KB
実行使用メモリ 494,172 KB
最終ジャッジ日時 2026-04-01 13:45:24
合計ジャッジ時間 15,999 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const char INF = CHAR_MAX / 2;

int main()
{
    int t, n;
    cin >> t >> n;
    vector<int> v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i];

    vector<vector<char> > dp(1<<n, vector<char>(t+1, INF));
    dp[0][0] = 0;
    for(int i=0; i<(1<<n); ++i){
        bitset<17> bs(i);
        for(int a=0; a<=t; ++a){
            if(dp[i][a] == INF)
                continue;

            for(int x=0; x<n; ++x){
                if(bs[x])
                    continue;
                bs[x] = true;
                int j = bs.to_ulong();
                bs[x] = false;

                if(a < v[x])
                    dp[j][t-v[x]] = min<char>(dp[j][t-v[x]], dp[i][a] + 1);
                else
                    dp[j][a-v[x]] = min(dp[j][a-v[x]], dp[i][a]);
            }
        }
    }

    int ans = *min_element(dp.back().begin(), dp.back().end());
    cout << ans << endl;

    return 0;
}
0