結果

問題 No.68 よくある棒を切る問題 (2)
ユーザー simansiman
提出日時 2023-06-13 21:59:24
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 427 ms / 5,000 ms
コード長 1,100 bytes
コンパイル時間 5,486 ms
コンパイル使用メモリ 106,972 KB
実行使用メモリ 9,200 KB
最終ジャッジ日時 2023-09-04 09:24:38
合計ジャッジ時間 16,312 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 414 ms
9,200 KB
testcase_01 AC 415 ms
9,152 KB
testcase_02 AC 417 ms
9,108 KB
testcase_03 AC 418 ms
9,104 KB
testcase_04 AC 423 ms
9,096 KB
testcase_05 AC 427 ms
9,116 KB
testcase_06 AC 415 ms
8,616 KB
testcase_07 AC 414 ms
8,816 KB
testcase_08 AC 411 ms
8,612 KB
testcase_09 AC 415 ms
8,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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