結果
| 問題 |
No.2320 Game World for PvP
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2023-05-26 22:22:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 1,315 bytes |
| コンパイル時間 | 4,423 ms |
| コンパイル使用メモリ | 259,448 KB |
| 最終ジャッジ日時 | 2025-02-13 07:14:10 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#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;
}
shobonvip