結果
問題 | No.1678 Coin Trade (Multiple) |
ユーザー | chineristAC |
提出日時 | 2021-09-10 23:06:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 266 ms / 5,000 ms |
コード長 | 1,463 bytes |
コンパイル時間 | 3,621 ms |
コンパイル使用メモリ | 194,344 KB |
最終ジャッジ日時 | 2025-01-24 12:11:18 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <algorithm> #include <cmath> #include <iomanip> #include <random> #include <stdio.h> #include <fstream> #include <functional> #include <atcoder/all> using namespace std; using namespace atcoder; #define rep(i,n,c) for (int i=0;i<n;i+=c) #define append push_back #define all(x) (x).begin(), (x).end() template<class T> using vec = vector<T>; template<class T> using vvec = vec<vec<T>>; template<class T> using vvvec = vec<vvec<T>>; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; template<class T> bool chmin(T &a, T b){ if (a>b){ a = b; return true; } return false; } template<class T> bool chmax(T &a, T b){ if (a<b){ a = b; return true; } return false; } template<class T> T sum(vec<T> x){ T res=0; for (auto e:x){ res += e; } return res; } template<class T> void printv(vec<T> x){ for (auto e:x){ cout<<e<<" "; } cout<<"\n"; } int main(){ int N,K; cin>>N>>K; mcf_graph<ll,ll> G(N); vec<ll> A(N); ll INF_COST = 2000000000; int M,b; for (int i=0;i<N;i++){ cin>>A[i]>>M; for (int j=0;j<M;j++){ cin>>b; G.add_edge(b-1,i,1,A[b-1]-A[i]+INF_COST*(i-b+1)); } if (i!=N-1){ G.add_edge(i,i+1,K,INF_COST); } } auto f = G.flow(0,N-1,K); assert (f.first==K); ll res = INF_COST*K*(N-1) - f.second; cout<<res<<endl; }