結果
| 問題 |
No.200 カードファイト!
|
| コンテスト | |
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2018-01-22 16:46:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,334 bytes |
| コンパイル時間 | 1,481 ms |
| コンパイル使用メモリ | 95,472 KB |
| 最終ジャッジ日時 | 2025-01-05 07:46:26 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 1 |
コンパイルメッセージ
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(102*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,n){
for(int k=i/c*c;k<min(n,(i/c+1)*c);++k){
din.add_edge(2+(2+td[i])*n+k,2+n+i,1);
}
}
cout<<din.max_flow(0,1)<<endl;
}
夕叢霧香(ゆうむらきりか)