結果

問題 No.957 植林
ユーザー yuruhiyayuruhiya
提出日時 2021-03-22 13:19:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 645 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 106,984 KB
最終ジャッジ日時 2024-05-03 03:02:52
合計ジャッジ時間 1,424 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:8:9: error: 'cin' was not declared in this scope
    8 |         cin >> h >> w;
      |         ^~~
main.cpp:2:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 | #include <atcoder/all>
  +++ |+#include <iostream>
    2 | using namespace std;
main.cpp:32:9: error: 'cout' was not declared in this scope
   32 |         cout << sum - g.flow(S, T) << '\n';
      |         ^~~~
main.cpp:32:9: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?

ソースコード

diff #

#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; ++i)

int main() {
	int h, w;
	cin >> h >> w;
	ll a[301][301], b[301], c[301];
	rep(i, h) rep(j, w) cin >> a[i][j];
	rep(i, h) cin >> b[i];
	rep(i, w) cin >> c[i];

	int size = h + w + 2, S = size - 2, T = size - 1;
	atcoder::mf_graph<ll> g(size);

	ll sum = 0;
	rep(i, h) {
		ll s = 0;
		rep(j, w) s += a[i][j];
		g.add_edge(S, i, s);
		g.add_edge(i, T, b[i]);
		sum += b[i];
	}
	rep(j, w) {
		g.add_edge(h + j, T, c[j]);
		sum += c[j];
	}
	rep(i, h) rep(j, w) {
		g.add_edge(i, h + j, a[i][j]);
	}
	cout << sum - g.flow(S, T) << '\n';
}
0