結果
問題 | No.1678 Coin Trade (Multiple) |
ユーザー | ebi_fly |
提出日時 | 2021-09-10 23:39:08 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 210 ms / 5,000 ms |
コード長 | 4,914 bytes |
コンパイル時間 | 3,661 ms |
コンパイル使用メモリ | 209,500 KB |
実行使用メモリ | 19,368 KB |
最終ジャッジ日時 | 2024-06-12 05:10:34 |
合計ジャッジ時間 | 8,548 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 40 ms
13,008 KB |
testcase_04 | AC | 117 ms
16,596 KB |
testcase_05 | AC | 69 ms
18,484 KB |
testcase_06 | AC | 58 ms
17,848 KB |
testcase_07 | AC | 106 ms
15,772 KB |
testcase_08 | AC | 77 ms
15,188 KB |
testcase_09 | AC | 73 ms
18,588 KB |
testcase_10 | AC | 41 ms
9,580 KB |
testcase_11 | AC | 93 ms
16,452 KB |
testcase_12 | AC | 36 ms
10,224 KB |
testcase_13 | AC | 164 ms
18,076 KB |
testcase_14 | AC | 72 ms
12,848 KB |
testcase_15 | AC | 78 ms
16,712 KB |
testcase_16 | AC | 41 ms
16,232 KB |
testcase_17 | AC | 72 ms
18,668 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,944 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 1 ms
6,944 KB |
testcase_26 | AC | 2 ms
6,944 KB |
testcase_27 | AC | 2 ms
6,944 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 1 ms
6,940 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 2 ms
6,940 KB |
testcase_34 | AC | 2 ms
6,940 KB |
testcase_35 | AC | 1 ms
6,940 KB |
testcase_36 | AC | 2 ms
6,940 KB |
testcase_37 | AC | 2 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,940 KB |
testcase_39 | AC | 2 ms
6,944 KB |
testcase_40 | AC | 2 ms
6,940 KB |
testcase_41 | AC | 2 ms
6,940 KB |
testcase_42 | AC | 2 ms
6,940 KB |
testcase_43 | AC | 1 ms
6,948 KB |
testcase_44 | AC | 2 ms
6,940 KB |
testcase_45 | AC | 2 ms
6,940 KB |
testcase_46 | AC | 2 ms
6,940 KB |
testcase_47 | AC | 2 ms
6,940 KB |
testcase_48 | AC | 204 ms
18,916 KB |
testcase_49 | AC | 200 ms
19,040 KB |
testcase_50 | AC | 200 ms
19,148 KB |
testcase_51 | AC | 200 ms
19,052 KB |
testcase_52 | AC | 204 ms
18,912 KB |
testcase_53 | AC | 199 ms
19,368 KB |
testcase_54 | AC | 210 ms
19,040 KB |
testcase_55 | AC | 196 ms
19,112 KB |
testcase_56 | AC | 196 ms
19,096 KB |
testcase_57 | AC | 197 ms
19,036 KB |
testcase_58 | AC | 124 ms
15,404 KB |
ソースコード
#include <iostream> #include <algorithm> #include <utility> #include <string> #include <vector> #include <set> #include <stack> #include <queue> #include <map> #include <math.h> #include <string.h> #include <iomanip> #include <numeric> #include <cstdlib> #include <cstdint> #include <cmath> #include <functional> #include <limits> #include <cassert> #include <bitset> #include <chrono> #include <random> #include <memory> #include <atcoder/all> /* macro */ #define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++) #define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--) #define Rep(i, a, n) for (i64 i = (i64)(a); i< (i64)(n); i++) #define RRep(i, a, n) for (i64 i = ((i64)(n-i64(1))); i>=(i64)(a); i--) #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define Bit(n) (1LL<<(n)) /* macro end */ /* template */ namespace ebi { #ifdef LOCAL #define debug(...) \ std::cerr << "LINE: " << __LINE__ << " [" << #__VA_ARGS__ << "]:", \ debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << std::endl; } template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) { std::cerr << " " << h; if (sizeof...(t) > 0) std::cout << " :"; debug_out(t...); } template <typename T1, typename T2> std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) { return os << pa.first << " " << pa.second; } template <typename T> std::ostream& operator<<(std::ostream& os, std::vector<T> vec) { for (std::size_t i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } std::ostream& operator<<(std::ostream& os, atcoder::modint1000000007 a){ return os << a.val(); } std::ostream& operator<<(std::ostream& os, atcoder::modint998244353 a){ return os << a.val(); } using size_t = std::size_t; using i32 = std::int32_t; using u32 = std::uint32_t; using i64 = long long; using u64 = unsigned long long; template<class T> void fill(std::vector<T> &v) { for(T &e: v) std::cin >> e; } template<class T> struct Edge { int to; T cost; Edge(int to, T cost) : to(to), cost(cost) { } }; template<class T> std::ostream& operator<<(std::ostream& os, Edge<T> e) { return os << "[" << e.to << ", " << e.cost << "] "; } template<class T> struct Graph : std::vector<std::vector<Edge<T>>> { using std::vector<std::vector<Edge<T>>>::vector; void add_edge(int u, int v, T w, bool directed = false) { (*this)[u].emplace_back(v, w); if(directed) return; (*this)[v].emplace_back(u, w); } }; struct graph : std::vector<std::vector<int>> { using std::vector<std::vector<int>>::vector; void add_edge(int u, int v, bool directed = false) { (*this)[u].emplace_back(v); if(directed) return; (*this)[v].emplace_back(u); } }; template <class T> inline bool chmin(T &a, T b) { if (a > b){ a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b){ a = b; return true; } return false; } template <class T> T gcd(T a, T b){ if( b==0 ) return a; else return gcd(b, a%b); } template <class T> T lcm(T a, T b) { return (a*b)/gcd(a,b); } template<class T> T pow(T x, i64 n) { T res = 1; while(n>0){ if(n&1) res = res *x; x = x*x; n>>=1; } return res; } template<class T> T mod_pow(T x, i64 n, i64 mod) { T res = 1; while(n > 0) { if(n & 1) res = (res * x)%mod; x = (x*x)%mod; n >>= 1; } return res; } template<class T> T scan() { T val; std::cin >> val; return val; } constexpr i64 LNF = std::numeric_limits<i64>::max()/2; constexpr int INF = std::numeric_limits<int>::max()/2; const long double PI = acos(-1); const std::vector<int> dy = {1,0,-1,0,1,1,-1,-1}; const std::vector<int> dx = {0,1,0,-1,1,-1,1,-1}; } /* template end */ namespace ebi { using pii = std::pair<int,int>; using ld = long double; using mint = atcoder::modint998244353; constexpr i64 buffer = 1e9; void main_() { int n,k; std::cin >> n >> k; atcoder::mcf_graph<i64, i64> g(n); std::vector<i64> a(n); rep(i,0,n) { int m; std::cin >> a[i] >> m; if(i < n-1) { g.add_edge(i, i+1, k, buffer); } while(m--) { int b; std::cin >> b; b--; g.add_edge(b, i, 1, a[b]-a[i]+buffer*(i-b)); } } i64 cost = g.flow(0, n-1, k).second; i64 ans = -(cost - buffer * (n-1) * k); std::cout << ans << '\n'; } } int main() { std::cout << std::fixed << std::setprecision(15); std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int t = 1; while(t--) { ebi::main_(); } return 0; }