結果

問題 No.1678 Coin Trade (Multiple)
ユーザー 👑 NachiaNachia
提出日時 2021-09-10 21:34:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 5,000 ms
コード長 878 bytes
コンパイル時間 1,443 ms
コンパイル使用メモリ 106,812 KB
実行使用メモリ 20,336 KB
最終ジャッジ日時 2023-09-02 16:09:15
合計ジャッジ時間 8,311 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 44 ms
13,024 KB
testcase_04 AC 125 ms
17,324 KB
testcase_05 AC 76 ms
19,732 KB
testcase_06 AC 65 ms
19,308 KB
testcase_07 AC 120 ms
14,900 KB
testcase_08 AC 88 ms
15,912 KB
testcase_09 AC 84 ms
19,748 KB
testcase_10 AC 42 ms
9,160 KB
testcase_11 AC 99 ms
16,604 KB
testcase_12 AC 38 ms
9,932 KB
testcase_13 AC 181 ms
19,000 KB
testcase_14 AC 76 ms
13,004 KB
testcase_15 AC 87 ms
16,392 KB
testcase_16 AC 45 ms
17,032 KB
testcase_17 AC 86 ms
19,932 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 226 ms
20,196 KB
testcase_49 AC 220 ms
20,228 KB
testcase_50 AC 226 ms
20,336 KB
testcase_51 AC 224 ms
19,988 KB
testcase_52 AC 213 ms
20,100 KB
testcase_53 AC 214 ms
20,188 KB
testcase_54 AC 221 ms
20,316 KB
testcase_55 AC 227 ms
20,272 KB
testcase_56 AC 223 ms
20,216 KB
testcase_57 AC 240 ms
20,316 KB
testcase_58 AC 127 ms
17,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
0