結果

問題 No.733 分身並列コーディング
ユーザー tnakao0123tnakao0123
提出日時 2018-09-15 06:41:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 114 ms / 1,500 ms
コード長 1,300 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 82,120 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2023-09-22 07:06:18
合計ジャッジ時間 6,154 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,732 KB
testcase_01 AC 6 ms
12,680 KB
testcase_02 AC 6 ms
12,668 KB
testcase_03 AC 96 ms
12,804 KB
testcase_04 AC 114 ms
12,672 KB
testcase_05 AC 83 ms
12,648 KB
testcase_06 AC 6 ms
12,684 KB
testcase_07 AC 82 ms
12,796 KB
testcase_08 AC 83 ms
12,592 KB
testcase_09 AC 53 ms
12,728 KB
testcase_10 AC 10 ms
12,692 KB
testcase_11 AC 10 ms
12,772 KB
testcase_12 AC 6 ms
12,736 KB
testcase_13 AC 5 ms
12,928 KB
testcase_14 AC 27 ms
12,648 KB
testcase_15 AC 8 ms
12,668 KB
testcase_16 AC 5 ms
12,624 KB
testcase_17 AC 5 ms
12,624 KB
testcase_18 AC 10 ms
12,640 KB
testcase_19 AC 52 ms
12,596 KB
testcase_20 AC 50 ms
12,748 KB
testcase_21 AC 27 ms
12,680 KB
testcase_22 AC 104 ms
12,664 KB
testcase_23 AC 26 ms
12,592 KB
testcase_24 AC 25 ms
12,672 KB
testcase_25 AC 5 ms
12,652 KB
testcase_26 AC 5 ms
12,644 KB
testcase_27 AC 8 ms
12,684 KB
testcase_28 AC 90 ms
12,656 KB
testcase_29 AC 96 ms
12,620 KB
testcase_30 AC 98 ms
12,640 KB
testcase_31 AC 96 ms
12,672 KB
testcase_32 AC 15 ms
12,916 KB
testcase_33 AC 14 ms
12,812 KB
testcase_34 AC 14 ms
12,728 KB
testcase_35 AC 15 ms
12,676 KB
testcase_36 AC 14 ms
12,680 KB
testcase_37 AC 14 ms
12,612 KB
testcase_38 AC 93 ms
12,652 KB
testcase_39 AC 94 ms
12,684 KB
testcase_40 AC 93 ms
12,900 KB
testcase_41 AC 15 ms
12,696 KB
testcase_42 AC 14 ms
12,624 KB
testcase_43 AC 14 ms
12,616 KB
testcase_44 AC 90 ms
12,684 KB
testcase_45 AC 93 ms
12,592 KB
testcase_46 AC 96 ms
12,692 KB
testcase_47 AC 94 ms
12,688 KB
testcase_48 AC 93 ms
12,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 733.cc:  No.733 分身並列コーディング - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 17;
const int NBITS = 1 << MAX_N;
const int INF = 0x7f7f7f7f;

/* typedef */

/* global variables */

int ts[MAX_N];
int dp[NBITS][MAX_N + 1];

/* subroutines */

inline void setmin(int &a, int b) { if (a > b) a = b; }

/* main */

int main() {
  int t, n;
  scanf("%d%d", &t, &n);
  for (int i = 0; i < n; i++) scanf("%d", &ts[i]);

  int nbits = 1 << n;
  memset(dp, 0x7f, sizeof(dp));
  memset(dp[0], 0, sizeof(dp[0]));

  for (int bits = 0; bits < nbits; bits++)
    for (int i = 0; i <= n; i++)
      if (dp[bits][i] < INF) {
	if (i < n && dp[bits][i] <= t) dp[bits][i + 1] = 0;

	for (int j = 0, bj = 1; j < n; j++, bj <<= 1)
	  if (! (bits & bj))
	    setmin(dp[bits | bj][i], dp[bits][i] + ts[j]);
      }

  int mini = 0;
  for (; mini <= n; mini++)
    if (dp[nbits - 1][mini] == 0) break;

  printf("%d\n", mini);
  return 0;
}
0