結果

問題 No.2453 Seat Allocation
ユーザー simansiman
提出日時 2023-09-03 02:17:20
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 1,155 bytes
コンパイル時間 2,257 ms
コンパイル使用メモリ 106,016 KB
実行使用メモリ 7,824 KB
最終ジャッジ日時 2023-09-07 15:38:57
合計ジャッジ時間 7,248 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 234 ms
7,064 KB
testcase_06 AC 177 ms
4,380 KB
testcase_07 AC 38 ms
7,656 KB
testcase_08 AC 21 ms
4,380 KB
testcase_09 AC 252 ms
6,996 KB
testcase_10 AC 250 ms
7,824 KB
testcase_11 AC 254 ms
7,032 KB
testcase_12 AC 173 ms
4,380 KB
testcase_13 AC 181 ms
4,380 KB
testcase_14 AC 170 ms
4,380 KB
testcase_15 AC 181 ms
4,376 KB
testcase_16 AC 168 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 197 ms
5,364 KB
testcase_19 AC 224 ms
6,936 KB
testcase_20 AC 87 ms
5,120 KB
testcase_21 AC 133 ms
4,376 KB
testcase_22 AC 191 ms
4,584 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 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 i;
  ll a;
  ll b;

  Node(int i = -1, ll a = 0, ll b = 0) {
    this->i = i;
    this->a = a;
    this->b = b;
  }

  bool operator>(const Node &n) const {
    ll v1 = a * n.b;
    ll v2 = n.a * b;

    if (v1 == v2) {
      return i > n.i;
    } else {
      return v1 < v2;
    }
  }
};

int main() {
  int N, M;
  cin >> N >> M;

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

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

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

  vector<int> counter(N, 0);

  for (int i = 0; i < M; ++i) {
    Node node = pque.top();
    pque.pop();

    cout << node.i + 1 << endl;
    counter[node.i]++;

    if (counter[node.i] < M) {
      node.b = B[counter[node.i]];
      pque.push(node);
    }
  }

  return 0;
}
0