結果

問題 No.2320 Game World for PvP
ユーザー shobonvipshobonvip
提出日時 2023-05-26 22:22:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 4,479 ms
コンパイル使用メモリ 270,008 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 12:15:59
合計ジャッジ時間 6,387 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef modint998244353 mint;
typedef long long ll;

int main(){
	int n, s, t; cin >> n >> s >> t;
	ll base = 0;
	vector<int> e(s), r(t);
	vector<bool> plain(n, true);
	vector<vector<ll>> c(n, vector<ll>(n));
	for (int i=0; i<s; i++){
		cin >> e[i];
		e[i]--;
		plain[e[i]] = false;
	}
	for (int i=0; i<t; i++){
		cin >> r[i];
		r[i]--;
		plain[r[i]] = false;
	}
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			cin >> c[i][j];
		}
	}
	for (int i=0; i<s; i++){
		for (int j=i+1; j<s; j++){
			base += c[e[i]][e[j]];
		}
	}
	for (int i=0; i<t; i++){
		for (int j=i+1; j<t; j++){
			base += c[r[i]][r[j]];
		}
	}
	mf_graph<ll> mf(n+2);
	for (int i=0; i<n; i++){
		if (!plain[i]) continue;
		{
			ll cost = 0;
			for (int j=0; j<t; j++){
				cost += c[r[j]][i];
			}
			mf.add_edge(n, i, cost);
			base += cost;
		}
		{
			ll cost = 0;
			for (int j=0; j<s; j++){
				cost += c[e[j]][i];
			}
			mf.add_edge(i, n+1, cost);
			base += cost;
		}
	}
	for (int i=0; i<n; i++){
		if (!plain[i]) continue;
		for (int j=0; j<n; j++){
			if (!plain[j]) continue;
			if (i == j) continue;
			mf.add_edge(i, j, c[i][j]);
			if (i < j) base += c[i][j];
		}
	}
	//cout << base << endl;
	cout << base - mf.flow(n, n+1) << endl;

}
0