結果

問題 No.107 モンスター
ユーザー simansiman
提出日時 2021-06-08 19:19:23
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,043 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 105,360 KB
実行使用メモリ 7,860 KB
最終ジャッジ日時 2023-08-17 22:33:06
合計ジャッジ時間 2,089 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 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,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,412 KB
testcase_14 AC 5 ms
5,512 KB
testcase_15 AC 5 ms
5,484 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 5 ms
7,796 KB
testcase_19 AC 4 ms
7,840 KB
testcase_20 AC 4 ms
4,452 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 5 ms
5,620 KB
testcase_23 AC 6 ms
7,792 KB
testcase_24 AC 6 ms
7,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  int D[N];

  for (int i = 0; i < N; ++i) {
    cin >> D[i];
  }

  int dp[1 << N][N + 1];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 100;

  for (int mask = 0; mask < (1 << N); ++mask) {
    for (int level = 0; level < N; ++level) {
      if (dp[mask][level] == 0) continue;

      for (int i = 0; i < N; ++i) {
        int d = D[i];
        if (mask >> i & 1) continue;
        int nmask = mask | (1 << i);
        int nlevel = (d < 0) ? level + 1 : level;
        int nh = dp[mask][level] + d;
        nh = min(nh, 100 * (level + 1));

        dp[nmask][nlevel] = max(dp[nmask][nlevel], nh);
      }
    }
  }

  int ans = 0;

  for (int level = 0; level <= N; ++level) {
    ans = max(ans, dp[(1 << N) - 1][level]);
  }

  cout << ans << endl;

  return 0;
}
0