結果
| 問題 |
No.957 植林
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-20 01:20:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,694 bytes |
| コンパイル時間 | 1,303 ms |
| コンパイル使用メモリ | 77,596 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-07 02:22:27 |
| 合計ジャッジ時間 | 5,229 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 WA * 32 RE * 10 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <climits>
using namespace std;
typedef long long ll;
/* {{{ Variables */
ll H, W;
vector<vector<ll>> G;
vector<ll> R, C;
/* }}} */
int argmax(vector<ll> v) {
int len = v.size();
ll max_val = LLONG_MIN;
int max_arg = -1;
for (int i = 0; i < len; ++i) {
if (max_val < v[i]) {
max_val = v[i];
max_arg = i;
}
}
return max_arg;
}
int main(int argc, char *argv[])
{
/* {{{ Input */
cin >> H >> W;
for (int i = 0; i < H; ++i) {
ll g;
G.emplace_back(vector<ll>());
for (int j = 0; j < W; ++j) {
cin >> g;
G[i].emplace_back(g);
}
}
for (int i = 0; i < H; ++i) {
ll r;
cin >> r;
R.emplace_back(r);
}
for (int i = 0; i < W; ++i) {
ll c;
cin >> c;
C.emplace_back(c);
}
/* }}} */
/* {{{ Output */
vector<ll> ROW(R), COL(C);
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
ROW[i] -= G[i][j];
COL[j] -= G[i][j];
}
}
ll cost_sum = 0;
while (1) {
ll r_argmax = argmax(ROW);
ll c_argmax = argmax(COL);
ll cost;
if (ROW[r_argmax] > COL[c_argmax]) {
cost = ROW[r_argmax];
ROW[r_argmax] = LLONG_MIN;
for (int i = 0; i < W; ++i) {
COL[i] += G[r_argmax][i];
G[r_argmax][i] = 0;
}
} else {
cost = COL[c_argmax];
COL[c_argmax] = LLONG_MIN;
for (int i = 0; i < H; ++i) {
ROW[i] += G[i][c_argmax];
G[i][c_argmax] = 0;
}
}
if (cost < 0) {
break;
}
cost_sum += cost;
}
cout << cost_sum << endl;
/* }}} */
return 0;
}