結果

問題 No.2453 Seat Allocation
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-08-19 22:48:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 1,135 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 207,076 KB
実行使用メモリ 10,180 KB
最終ジャッジ日時 2023-09-07 15:34:16
合計ジャッジ時間 6,497 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 226 ms
8,520 KB
testcase_06 AC 164 ms
4,376 KB
testcase_07 AC 37 ms
7,960 KB
testcase_08 AC 19 ms
4,380 KB
testcase_09 AC 236 ms
8,512 KB
testcase_10 AC 242 ms
8,460 KB
testcase_11 AC 243 ms
10,180 KB
testcase_12 AC 168 ms
4,380 KB
testcase_13 AC 168 ms
4,376 KB
testcase_14 AC 163 ms
4,376 KB
testcase_15 AC 180 ms
4,380 KB
testcase_16 AC 167 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 181 ms
6,144 KB
testcase_19 AC 197 ms
9,292 KB
testcase_20 AC 80 ms
5,544 KB
testcase_21 AC 128 ms
4,460 KB
testcase_22 AC 179 ms
5,180 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct fraction{
    ll p, q;
    fraction(ll P=0, ll Q=1) : p(P), q(Q) {
        if (Q < 0){
            p *= -1;
            q *= -1;
        }
    }
    bool operator < (const fraction & other) const{
        if (p < 0) return -p*other.q > -other.p*q;
        return p*other.q < other.p*q;
    }
    bool operator == (const fraction & other) const{
        return p*other.q == other.p*q;
    }
    bool operator > (const fraction & other) const{
        if (p < 0) return -p*other.q < -other.p*q;
        return p*other.q > other.p*q;
    }
};

int main(){

    ll N, M, x;
    fraction p;
    cin >> N >> M;
    vector<ll> A(N), B(M+1), cnt(N);
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<M; i++) cin >> B[i];
    priority_queue<pair<fraction, ll>> que;

    for (int i=0; i<N; i++){
        que.push({fraction(A[i], B[cnt[0]]), -i});
    }

    while(M){
        M--;
        tie(p, x) = que.top();
        que.pop();
        cout << -x+1 << endl;
        cnt[-x]++;
        que.push({fraction(A[-x], B[cnt[-x]]), x});
    }

    return 0;
}

0