結果

問題 No.2623 Room Allocation
ユーザー ayataka5ayataka5
提出日時 2024-02-09 23:10:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,393 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 210,412 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-02-09 23:10:48
合計ジャッジ時間 4,558 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 46 ms
7,984 KB
testcase_07 AC 45 ms
7,984 KB
testcase_08 AC 47 ms
7,984 KB
testcase_09 AC 46 ms
7,984 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 93 ms
9,216 KB
testcase_15 AC 83 ms
6,676 KB
testcase_16 AC 22 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 82 ms
6,676 KB
testcase_19 AC 78 ms
6,676 KB
testcase_20 AC 84 ms
6,676 KB
testcase_21 AC 83 ms
6,676 KB
testcase_22 AC 62 ms
6,676 KB
testcase_23 AC 35 ms
6,676 KB
testcase_24 AC 97 ms
6,676 KB
testcase_25 AC 66 ms
6,676 KB
testcase_26 AC 7 ms
6,676 KB
testcase_27 AC 88 ms
9,216 KB
testcase_28 AC 32 ms
6,676 KB
testcase_29 AC 16 ms
6,676 KB
testcase_30 AC 88 ms
9,216 KB
testcase_31 AC 6 ms
6,676 KB
testcase_32 AC 6 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    vector P(N, 0);
    vector c(N, 'A');
    for(int i = 0; i < N; i++) cin >> P[i] >> c[i];
    vector A(min(N, X+Y), 0LL), B(min(N, X+Y), 0LL);
    for(int i = 0; i < N; i++) {
        if(c[i] == 'A') A[i % (X+Y)] += (long long)P[i];
        else B[i % (X+Y)] += (long long)P[i];
    }
    long long res(0LL);
    int x(0), y(0);
    vector d(size(A), 'A');
    for(int i = 0; i < size(A); i++) {
        if(A[i] < B[i]) { y++; d[i] = 'B'; }
        if(B[i] < A[i]) { x++; d[i] = 'A'; }
        if(A[i] == B[i]) {
            if(x < y) { x++; d[i] = 'A'; }
            else { y++; d[i] = 'B'; }
        }
        res += max(A[i], B[i]);
    }
    vector C(min(N, X+Y), 0LL);
    for(int i = 0; i < size(A); i++) C[i] = abs(A[i]-B[i]);
    if(X < x) {
        priority_queue<long long> pq;
        for(int i = 0; i < size(A); i++) {
            if(d[i] == 'A') pq.push(-C[i]);
        }
        for(int i = 0; i < x-X; i++) {
            res += pq.top();
            pq.pop();
        }
    }
    if(Y < y) {
        priority_queue<long long> pq;
        for(int i = 0; i < size(A); i++) {
            if(d[i] == 'B') pq.push(-C[i]);
        }
        for(int i = 0; i < y-Y; i++) {
            res += pq.top();
            pq.pop();
        }
    }
    cout << res << endl;
    return 0;
}
0