結果

問題 No.107 モンスター
コンテスト
ユーザー siman
提出日時 2021-06-08 19:19:23
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,043 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 684 ms
コンパイル使用メモリ 151,296 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2026-05-21 07:16:11
合計ジャッジ時間 2,019 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:19:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   19 |   int D[N];
      |         ^
main.cpp:19:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int N;
      |       ^
main.cpp:25:18: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   25 |   int dp[1 << N][N + 1];
      |                  ^~~~~
main.cpp:25:18: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int N;
      |       ^
main.cpp:25:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   25 |   int dp[1 << N][N + 1];
      |          ^~~~~~
main.cpp:25:15: note: read of non-const variable 'N' is not allowed in a constant expression
   25 |   int dp[1 << N][N + 1];
      |               ^
main.cpp:17:7: note: declared here
   17 |   int N;
      |       ^
3 warnings generated.

ソースコード

diff #
raw source code

#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