結果

問題 No.1324 Approximate the Matrix
ユーザー t33f
提出日時 2020-12-22 18:38:22
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,072 bytes
コンパイル時間 3,531 ms
コンパイル使用メモリ 124,928 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-21 14:16:51
合計ジャッジ時間 2,450 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 WA * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <queue>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    int p[n][n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) cin >> p[i][j];
    auto compare = [&p](const pair<int ,int> l, const pair<int, int> r) {
        return p[l.first][l.second] < p[r.first][r.second];
    };
    using P = pair<int, int>;
    priority_queue<P, vector<P>, decltype(compare)> pq(compare);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) pq.push({i, j});
    while (k > 0) {
        auto [i, j] = pq.top();
        pq.pop();
        if (a[i] > 0 && b[j] > 0) {
            p[i][j]--;
            k--;
            a[i]--;
            b[j]--;
            pq.push({i, j});
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            ans += p[i][j] * p[i][j];
        }
    }
    cout << ans << endl;
}
0