結果

問題 No.68 よくある棒を切る問題 (2)
コンテスト
ユーザー siman
提出日時 2023-06-13 21:59:24
言語 C++17(clang)
(clang++ 21.1.8 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 406 ms / 5,000 ms
コード長 1,100 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,582 ms
コンパイル使用メモリ 149,120 KB
実行使用メモリ 9,648 KB
最終ジャッジ日時 2026-03-06 13:48:33
合計ジャッジ時間 10,758 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:35:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   35 |   int L[N];
      |         ^
main.cpp:35:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:33:7: note: declared here
   33 |   int N;
      |       ^
1 warning generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int id;
  int cnt;
  double length;

  Node(int id = -1, int cnt = 0, double length = -1) {
    this->id = id;
    this->cnt = cnt;
    this->length = length;
  }

  bool operator>(const Node &n) const {
    return length < n.length;
  }
};

int main() {
  int N;
  cin >> N;
  int L[N];
  priority_queue <Node, vector<Node>, greater<Node>> pque;
  for (int i = 0; i < N; ++i) {
    cin >> L[i];
    pque.push(Node(i, 1, L[i]));
  }

  double ans[500001];
  for (int i = 1; i <= 500000; ++i) {
    Node node = pque.top();
    pque.pop();

    ans[i] = node.length;
    double new_length = L[node.id] * 1.0 / (node.cnt + 1);
    pque.push(Node(node.id, node.cnt + 1, new_length));
  }

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int k;
    cin >> k;

    cout << fixed << setprecision(10) << ans[k] << endl;
  }

  return 0;
}
0