結果

問題 No.1324 Approximate the Matrix
コンテスト
ユーザー t33f
提出日時 2020-12-22 18:38:22
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,072 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,311 ms
コンパイル使用メモリ 140,032 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-09 19:31:15
合計ジャッジ時間 2,975 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 WA * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:11: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
    8 |     int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i];
      |           ^
main.cpp:8:11: note: read of non-const variable 'n' is not allowed in a constant expression
main.cpp:7:9: note: declared here
    7 |     int n, k; cin >> n >> k;
      |         ^
main.cpp:8:17: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
    8 |     int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i];
      |                 ^
main.cpp:8:17: note: read of non-const variable 'n' is not allowed in a constant expression
main.cpp:7:9: note: declared here
    7 |     int n, k; cin >> n >> k;
      |         ^
main.cpp:10:14: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   10 |     int p[n][n];
      |              ^
main.cpp:10:14: note: read of non-const variable 'n' is not allowed in a constant expression
main.cpp:7:9: note: declared here
    7 |     int n, k; cin >> n >> k;
      |         ^
main.cpp:10:11: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   10 |     int p[n][n];
      |           ^
main.cpp:10:11: note: read of non-const variable 'n' is not allowed in a constant expression
main.cpp:7:9: note: declared here
    7 |     int n, k; cin >> n >> k;
      |         ^
4 warnings generated.

ソースコード

diff #
raw source code

#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