結果

問題 No.200 カードファイト!
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2015-02-22 23:16:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,964 bytes
コンパイル時間 1,107 ms
コンパイル使用メモリ 102,948 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-05 11:54:16
合計ジャッジ時間 2,826 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,388 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void ae(int, int, int, int)’:
main.cpp:49:53: warning: narrowing conversion of ‘G[to].std::vector<edge>::size()’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ inside { } [-Wnarrowing]
   G[from].push_back((edge){to, cap, cost, G[to].size()});
                                           ~~~~~~~~~~^~
main.cpp:50:57: warning: narrowing conversion of ‘(G[from].std::vector<edge>::size() - 1)’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ inside { } [-Wnarrowing]
   G[to].push_back((edge){from, 0, -cost, G[from].size() - 1});
                                          ~~~~~~~~~~~~~~~^~~

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))

#define MOD 1000000007

int m[55][55];

#define MAX_V 102
#define INF 1000000000

typedef pair<int, int> P;
struct edge{int to, cap, cost, rev;};
int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V];
int preve[MAX_V];

void ae(int from, int to, int cap, int cost){
  G[from].push_back((edge){to, cap, cost, G[to].size()});
  G[to].push_back((edge){from, 0, -cost, G[from].size() - 1});
}

int minCostFlow(int s, int t, int f){
  int res = 0;
  memset(h,0,sizeof(h));
  while(f > 0){
    priority_queue<P, vector<P>, greater<P> > que;
    for(int i = 0; i < V; i++){
      dist[i] = INF;
    }
    dist[s] = 0;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      int v = p.second;
      if(dist[v] < p.first)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 + h[v] - h[e.to]){
          dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
          prevv[e.to] = v;
          preve[e.to] = i;
          que.push(P(dist[e.to], e.to));
        }
      }
    }
    if(dist[t] == INF){
      return -1;
    }
    for(int v = 0; v < V; v++){
      h[v] += dist[v];
    }
    int d = f;
    for(int v = t; v != s; v = prevv[v]){
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * h[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;
}

int main(){
  int n;
  cin>>n;
  int a;
  cin>>a;
  vector<int> b;
  rep(i,0,a){
    int b1;
    cin>>b1;
    b.pb(b1);
  }
  int c;
  cin>>c;
  vector<int> d;
  rep(i,0,c){
    int d1;
    cin>>d1;
    d.pb(d1);
  }
  sort(all(b),greater<int>());
  sort(all(d));
  vector<int> A;
  vector<int> B;
  vector<int> C;
  vector<int> D;
  rep(i,0,50){
    rep(j,0,b.sz){
      A.pb(b[j]);
      B.pb(i);
    }
    rep(j,0,d.sz){
      C.pb(d[j]);
      D.pb(i);
    }
  }
  clr(m,0);
  rep(i,0,n){
    m[B[i]][D[i]]=1;
  }
  rep(i,0,n){
    ae(n*2,i,1,0);
    ae(n+i,n*2+1,1,0);
  }
  rep(i,0,n){
    rep(j,0,n){
      if(m[B[i]][D[j]]==1){
        if(A[i]<=C[j]){
          ae(i,n+j,1,1);
        }
        else{
          ae(i,n+j,1,0);
        }
      }
    }
  }
  V=n*2+2;
  cout << n - minCostFlow(n*2, n*2+1, n) << endl;
  return 0;
}

/*
最小費用流です。
*/
0