結果
問題 | No.200 カードファイト! |
ユーザー | 夕叢霧香(ゆうむらきりか) |
提出日時 | 2018-01-22 16:49:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,387 bytes |
コンパイル時間 | 1,288 ms |
コンパイル使用メモリ | 97,776 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-06-07 17:21:45 |
合計ジャッジ時間 | 2,199 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
6,832 KB |
testcase_01 | AC | 9 ms
7,552 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 4 ms
6,940 KB |
testcase_06 | AC | 8 ms
6,940 KB |
testcase_07 | AC | 6 ms
6,940 KB |
testcase_08 | AC | 5 ms
6,944 KB |
testcase_09 | WA | - |
testcase_10 | AC | 3 ms
6,944 KB |
testcase_11 | AC | 3 ms
6,940 KB |
testcase_12 | AC | 3 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 3 ms
6,940 KB |
testcase_20 | AC | 4 ms
6,940 KB |
testcase_21 | AC | 3 ms
6,944 KB |
testcase_22 | AC | 3 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 3 ms
6,944 KB |
testcase_25 | AC | 3 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 3 ms
6,940 KB |
testcase_28 | AC | 18 ms
11,392 KB |
コンパイルメッセージ
main.cpp: In instantiation of 'void Dinic<T>::add_edge(int, int, T) [with T = long long int]': main.cpp:128:23: required from here main.cpp:71:58: warning: narrowing conversion of '(&((Dinic<long long int>*)this)->Dinic<long long int>::graph.std::vector<std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> >, std::allocator<std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> > > >::operator[](((std::vector<std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> >, std::allocator<std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> > > >::size_type)to)))->std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> >::size()' from 'std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing] 71 | graph[from].push_back((edge) {to, cap, graph[to].size()}); | ~~~~~~~~~~~~~~^~ main.cpp:72:61: warning: narrowing conversion of '((&((Dinic<long long int>*)this)->Dinic<long long int>::graph.std::vector<std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> >, std::allocator<std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> > > >::operator[](((std::vector<std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> >, std::allocator<std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> > > >::size_type)from)))->std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> >::size() - 1)' from 'std::vector<Dinic<long long int>::edge, std::allocator<Dinic<long long int>::edge> >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing] 72 | graph[to].push_back((edge) {from, 0, graph[from].size() - 1}); | ~~~~~~~~~~
ソースコード
#include<algorithm> #include<iostream> #include<queue> #include<vector> using namespace std; typedef long long lint; typedef vector<int>vi; typedef pair<int,int>pii; #define rep(i,n)for(int i=0;i<(int)(n);++i) // https://github.com/koba-e964/contest/blob/master/comm/dinic.cpp /** * Dinic's algorithm for maximum flow problem. * Header requirement: vector, queue * Verified by: ABC010-D(http://abc010.contest.atcoder.jp/submissions/602810) * ARC031-D(http://arc031.contest.atcoder.jp/submissions/1050071) * POJ 3155(http://poj.org/problem?id=3155) */ template<class T = int> class Dinic { private: struct edge { int to; T cap; int rev; // rev is the position of reverse edge in graph[to] }; std::vector<std::vector<edge> > graph; std::vector<int> level; std::vector<int> iter; /* Perform bfs and calculate distance from s */ void bfs(int s) { level.assign(level.size(), -1); std::queue<int> que; level[s] = 0; que.push(s); while (! que.empty()) { int v = que.front(); que.pop(); for (int i = 0; i < graph[v].size(); ++i) { edge &e = graph[v][i]; if (e.cap > 0 && level[e.to] == -1) { level[e.to] = level[v] + 1; que.push(e.to); } } } } /* search augment path by dfs. if f == -1, f is treated as infinity. */ T dfs(int v, int t, T f) { if (v == t) { return f; } for (int &i = iter[v]; i < graph[v].size(); ++i) { edge &e = graph[v][i]; if (e.cap > 0 && level[v] < level[e.to]) { T newf = f == -1 ? e.cap : std::min(f, e.cap); T d = dfs(e.to, t, newf); if (d > 0) { e.cap -= d; graph[e.to][e.rev].cap += d; return d; } } } return 0; } public: /* v is the number of vertices (labeled from 0 .. v-1) */ Dinic(int v) : graph(v), level(v, -1), iter(v, 0) {} void add_edge(int from, int to, T cap) { graph[from].push_back((edge) {to, cap, graph[to].size()}); graph[to].push_back((edge) {from, 0, graph[from].size() - 1}); } T max_flow(int s, int t) { T flow = 0; while (1) { bfs(s); if (level[t] < 0) { return flow; } iter.assign(iter.size(), 0); T f; while ((f = dfs(s, t, -1)) > 0) { flow += f; } } } std::pair<T,std::vector<int> > max_flow_cut(int s, int t) { T flow = 0; while (1) { bfs(s); if (level[t] < 0) { std::vector<int> ret; for (int i = 0; i < graph.size(); ++i) { if (level[i] < 0) { ret.push_back(i); } } return std::pair<T, std::vector<int> >(flow, ret); } iter.assign(iter.size(), 0); T f; while ((f = dfs(s, t, -1)) > 0) { flow += f; } } } }; int main(){ int n,a,c; cin>>n>>a; vi b(a); rep(i,a)cin>>b[i]; rep(i,a)b[i]--; cin>>c; vi d(c); rep(i,c)cin>>d[i]; rep(i,c)d[i]--; sort(b.rbegin(),b.rend()); sort(d.begin(),d.end()); vi tb(n),td(n); for(int i=0;i<n;++i){ tb[i]=b[i%a]; td[i]=d[i%c]; } Dinic<lint> din(202*n+2); rep(i,n)din.add_edge(0,2+i,1); rep(i,n)din.add_edge(2+n+i,1,1); rep(i,n){ for(int k=i/a*a;k<min(n,(i/a+1)*a);++k){ rep(j,tb[i]) din.add_edge(2+i,2+(2+j)*n+k,1); } } rep(i,100*n)din.add_edge(2+2*n+i,2+102*n+i,1); rep(i,n){ for(int k=i/c*c;k<min(n,(i/c+1)*c);++k){ din.add_edge(2+(2+td[i]+100)*n+k,2+n+i,1); } } cout<<din.max_flow(0,1)<<endl; }