結果
問題 | No.1678 Coin Trade (Multiple) |
ユーザー | milanis48663220 |
提出日時 | 2021-09-10 22:59:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 309 ms / 5,000 ms |
コード長 | 4,277 bytes |
コンパイル時間 | 1,899 ms |
コンパイル使用メモリ | 145,444 KB |
実行使用メモリ | 30,696 KB |
最終ジャッジ日時 | 2023-09-02 20:43:06 |
合計ジャッジ時間 | 8,816 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,372 KB |
testcase_01 | AC | 1 ms
4,372 KB |
testcase_02 | AC | 2 ms
4,372 KB |
testcase_03 | AC | 50 ms
16,292 KB |
testcase_04 | AC | 160 ms
23,532 KB |
testcase_05 | AC | 94 ms
29,052 KB |
testcase_06 | AC | 80 ms
26,968 KB |
testcase_07 | AC | 142 ms
18,460 KB |
testcase_08 | AC | 104 ms
19,832 KB |
testcase_09 | AC | 102 ms
28,304 KB |
testcase_10 | AC | 48 ms
9,552 KB |
testcase_11 | AC | 127 ms
22,480 KB |
testcase_12 | AC | 42 ms
10,372 KB |
testcase_13 | AC | 240 ms
26,960 KB |
testcase_14 | AC | 87 ms
15,592 KB |
testcase_15 | AC | 101 ms
21,872 KB |
testcase_16 | AC | 50 ms
22,068 KB |
testcase_17 | AC | 101 ms
29,548 KB |
testcase_18 | AC | 2 ms
4,372 KB |
testcase_19 | AC | 1 ms
4,368 KB |
testcase_20 | AC | 1 ms
4,372 KB |
testcase_21 | AC | 2 ms
4,368 KB |
testcase_22 | AC | 2 ms
4,368 KB |
testcase_23 | AC | 2 ms
4,372 KB |
testcase_24 | AC | 2 ms
4,368 KB |
testcase_25 | AC | 2 ms
4,368 KB |
testcase_26 | AC | 2 ms
4,372 KB |
testcase_27 | AC | 1 ms
4,368 KB |
testcase_28 | AC | 1 ms
4,372 KB |
testcase_29 | AC | 2 ms
4,372 KB |
testcase_30 | AC | 2 ms
4,368 KB |
testcase_31 | AC | 2 ms
4,372 KB |
testcase_32 | AC | 1 ms
4,372 KB |
testcase_33 | AC | 1 ms
4,372 KB |
testcase_34 | AC | 2 ms
4,372 KB |
testcase_35 | AC | 2 ms
4,368 KB |
testcase_36 | AC | 2 ms
4,372 KB |
testcase_37 | AC | 1 ms
4,372 KB |
testcase_38 | AC | 1 ms
4,368 KB |
testcase_39 | AC | 2 ms
4,368 KB |
testcase_40 | AC | 1 ms
4,368 KB |
testcase_41 | AC | 2 ms
4,372 KB |
testcase_42 | AC | 1 ms
4,372 KB |
testcase_43 | AC | 2 ms
4,372 KB |
testcase_44 | AC | 2 ms
4,372 KB |
testcase_45 | AC | 1 ms
4,372 KB |
testcase_46 | AC | 2 ms
4,372 KB |
testcase_47 | AC | 2 ms
4,368 KB |
testcase_48 | AC | 295 ms
29,252 KB |
testcase_49 | AC | 294 ms
30,540 KB |
testcase_50 | AC | 294 ms
29,484 KB |
testcase_51 | AC | 293 ms
29,360 KB |
testcase_52 | AC | 309 ms
30,524 KB |
testcase_53 | AC | 297 ms
29,456 KB |
testcase_54 | AC | 294 ms
29,556 KB |
testcase_55 | AC | 298 ms
30,368 KB |
testcase_56 | AC | 307 ms
30,444 KB |
testcase_57 | AC | 302 ms
30,696 KB |
testcase_58 | AC | 213 ms
24,976 KB |
コンパイルメッセージ
main.cpp: メンバ関数 ‘void MinCostFlow::add_edge(int, int, ll, ll)’ 内: main.cpp:61:63: 警告: narrowing conversion of ‘(&((MinCostFlow*)this)->MinCostFlow::G.std::vector<std::vector<edge> >::operator[](((std::vector<std::vector<edge> >::size_type)to)))->std::vector<edge>::size()’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing] 61 | G[from].push_back((edge){to, cap, cost, G[to].size()}); | ~~~~~~~~~~^~ main.cpp:62:66: 警告: narrowing conversion of ‘((&((MinCostFlow*)this)->MinCostFlow::G.std::vector<std::vector<edge> >::operator[](((std::vector<std::vector<edge> >::size_type)from)))->std::vector<edge>::size() - 1)’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing] 62 | G[to].push_back((edge){from, 0, -cost, G[from].size()-1}); | ~~~~~~~~~~~~~~^~
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <atcoder/mincostflow> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const ll INF = 1e18; struct edge{ int to; ll cap, cost; int rev; }; class MinCostFlow{ public: int V; // 頂点数 vector<vector<edge>> G; MinCostFlow(int v){ V = v; G = vector<vector<edge>>(v, vector<edge>()); dist = vector<ll>(v); preve = vector<int>(v); prevv = vector<int>(v); } void add_edge(int from, int to, ll cap, ll cost){ G[from].push_back((edge){to, cap, cost, G[to].size()}); G[to].push_back((edge){from, 0, -cost, G[from].size()-1}); } ll min_cost_flow(int s, int t, int f){ ll res = 0; while(f > 0){ fill(dist.begin(), dist.end(), INF); dist[s] = 0; bool update = true; while(update){ update = false; for(int v = 0; v < V; v++){ if(dist[v] == INF) continue; for(int i = 0; i < G[v].size(); i++){ edge &e = G[v][i]; if(e.cap > 0 && dist[e.to] > dist[v]+e.cost){ dist[e.to] = dist[v]+e.cost; prevv[e.to] = v; preve[e.to] = i; update = true; } } } } if(dist[t] == INF){ return -1; } ll d = f; for(int v = t; v != s; v = prevv[v]){ d = min(d, G[prevv[v]][preve[v]].cap); } f -= d; res += d*dist[t]; for(int v = t; v != s; v = prevv[v]){ edge &e = G[prevv[v]][preve[v]]; e.cap -= d; G[v][e.rev].cap += d; } } return res; } private: vector<ll> dist; vector<int> prevv, preve; }; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, k; cin >> n >> k; vector<int> a(n), m(n); vector<vector<int>> b(n); for(int i = 0; i < n; i++){ cin >> a[i] >> m[i]; b[i].resize(m[i]); for(int j = 0; j < m[i]; j++) { cin >> b[i][j]; b[i][j]--; } } auto mcf = atcoder::mcf_graph<ll,ll>(2*n+2); int s = 0, t = 2*n+1; auto s_idx = [&](int i){ return i*2+1; }; auto t_idx = [&](int i){ return i*2+2; }; mcf.add_edge(s, s_idx(0), k, 0); mcf.add_edge(t_idx(n-1), t, k, 0); const ll inf = 1e10; for(int i = 0; i < n; i++){ mcf.add_edge(s_idx(i), t_idx(i), k, 0); for(int j: b[i]) { mcf.add_edge(t_idx(j), s_idx(i), 1, inf*(i-j)+a[j]-a[i]); } if(i != 0){ mcf.add_edge(t_idx(i-1), s_idx(i), k, inf); } } auto [_, cost] = mcf.flow(s, t, k); cout << inf*(n-1)*k-cost << endl; }