結果
| 問題 |
No.1678 Coin Trade (Multiple)
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-09-10 21:34:32 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 226 ms / 5,000 ms |
| コード長 | 878 bytes |
| コンパイル時間 | 5,011 ms |
| コンパイル使用メモリ | 141,352 KB |
| 最終ジャッジ日時 | 2025-01-24 09:50:39 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/mincostflow>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)
int main(){
int N,K; cin >> N >> K;
vector<i64> A(N);
vector<vector<int>> E(N);
rep(i,N){
int c; cin >> A[i] >> c;
E[i].resize(c);
rep(j,c){ cin >> E[i][j]; E[i][j]--; }
}
const i64 maxA = 1000000000;
atcoder::mcf_graph<int, i64> G(N+1);
rep(i,N) G.add_edge(i,i+1,K,maxA);
rep(i,N) for(int e : E[i]){
G.add_edge(e,i,1,maxA*(i-e)-(A[i]-A[e]));
}
i64 ans = G.flow(0,N,K).second;
ans = maxA * N * K - ans;
cout << ans << endl;
return 0;
}
struct ios_do_not_sync {
ios_do_not_sync() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia