結果

問題 No.9 モンスターのレベル上げ
コンテスト
ユーザー siman
提出日時 2021-05-26 19:15:31
言語 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
結果
WA  
実行時間 -
コード長 1,224 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 810 ms
コンパイル使用メモリ 150,528 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-04 19:28:51
合計ジャッジ時間 4,127 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:33:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   33 |   int A[N];
      |         ^
main.cpp:33:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:31:7: note: declared here
   31 |   int N;
      |       ^
main.cpp:34:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   34 |   int B[N];
      |         ^
main.cpp:34:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:31:7: note: declared here
   31 |   int N;
      |       ^
2 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;

struct Monster {
  int power;
  int cnt;

  Monster(int power = -1, int cnt = -1) {
    this->power = power;
    this->cnt = cnt;
  }

  bool operator>(const Monster &n) const {
    return power > n.power;
  }
};

int main() {
  int N;
  cin >> N;
  int A[N];
  int B[N];

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

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

  int ans = INT_MAX;
  for (int i = 0; i < N; ++i) {
    priority_queue <Monster, vector<Monster>, greater<Monster>> pque;

    for (int j = 0; j < N; ++j) {
      pque.push(Monster(B[j], 0));
    }

    for (int j = 0; j < N; ++j) {
      int id = (j + i) % N;
      Monster m = pque.top();
      pque.pop();
      m.cnt++;
      m.power += A[id] / 2;
      pque.push(m);
    }

    int max_cnt = 0;

    while (not pque.empty()) {
      Monster m = pque.top();
      pque.pop();
      max_cnt = max(max_cnt, m.cnt);
    }

    ans = min(ans, max_cnt);
  }

  cout << ans << endl;

  return 0;
}
0