結果

問題 No.200 カードファイト!
ユーザー parukiparuki
提出日時 2016-08-20 19:33:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,115 bytes
コンパイル時間 2,413 ms
コンパイル使用メモリ 182,408 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 10:54:56
合計ジャッジ時間 3,208 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

struct FlowEdge{
    int to, cap, rev;
    FlowEdge(int to_, int cap_, int rev_):to(to_),cap(cap_),rev(rev_){ }
};
class FordFulkerson{
public:
    FordFulkerson(){}

    FordFulkerson(int n) : G(n), used(n){}

    void add(int from, int to, int cap){
        G[from].emplace_back(to, cap, (int)G[to].size() );
        G[to].emplace_back(from, 0, (int)G[from].size() - 1 );
    }

    int get(int s, int t){
        int f = 1, res = 0;
        while (f){
            fill(begin(used), end(used), false);
            f = dfs(s, t, INT_MAX);
            res += f;
        }
        return res;
    }
private:

    vector<vector<FlowEdge>> G;
    vector<bool> used;

    int dfs(int v, int t, int f){
        if (v == t) return f;
        used[v] = 1;
        for (auto &e : G[v]){
            if (!used[e.to] && e.cap > 0){
                int d = dfs(e.to, t, min(e.cap, f));
                if (d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
};

int maxBipartiteMatching(int n, int m, const vector<int> &u, const vector<int> &v){
    const int source = 0, sink = 1, offN = 2, offM = n + 2;
    const int V = n + m + 2, cap = 1;
    FordFulkerson maxFlow(V);
    for(int i = 0; i < n; ++i){
        maxFlow.add(source, i + offN, cap);
    }
    for(int i = 0; i < m; ++i){
        maxFlow.add(i + offM, sink, cap);
    }
    for(int i = 0; i < (int)u.size(); ++i){
        maxFlow.add(u[i] + offN, v[i] + offM, cap);
    }
    return maxFlow.get(source, sink);
}

int main(){
    int N, A, B;
    cin >> N >> A;
    vi aa(A);
    rep(i, A)cin >> aa[i];
    cin >> B;
    vi bb(B);
    rep(i, B)cin >> bb[i];

    sort(all(aa), greater<int>());
    sort(all(bb));

    vector<pii> aaa, bbb;
    for(int i = 0; i < N; i += A)
        aaa.emplace_back(i, min(N - 1, i + A));
    for(int i = 0; i < N; i += B)
        bbb.emplace_back(i, min(N - 1, i + B));

    vi u, v;
    each(pa, aaa){
        int al, ar;
        tie(al, ar) = pa;
        each(pb, bbb){
            int bl, br;
            tie(bl, br) = pb;
            if(bl <= ar && al <= br){
                FOR(i, al, ar + 1){
                    FOR(j, bl, br + 1){
                        int a = i%A, b = j%B;
                        if(aa[a] > bb[b]){
                            u.push_back(i);
                            v.push_back(j);
                        }
                    }
                }
            }
        }
    }

    int ans = maxBipartiteMatching(N, N, u, v);
    cout << ans << endl;
}
0