結果

問題 No.200 カードファイト!
ユーザー yaoshimaxyaoshimax
提出日時 2015-04-30 13:16:08
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,516 bytes
コンパイル時間 2,284 ms
コンパイル使用メモリ 93,008 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 04:38:37
合計ジャッジ時間 3,008 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

using namespace std;

//これは何?
//最小費用流を計算するためのライブラリ。
//枝を定義する構造体edge
//枝を追加するaddedge
//最小費用流を計算するmincost関数からなる。
//なお、グラフはvector<edge> graph[]として表現される。

struct edge{ int to; int cap; int cost; int rev;};

int mincost( vector<edge> graph[], int size, int start, int end, int F ){
  bool changed = true;
  int prev[size];
  int prevind[size];
  int dist[size];
  int cost = 0;
  while( F > 0 ){
    memset( prev, -1, sizeof(prev));
    memset( prevind, -1, sizeof(prev));
    for( int i = 0 ; i < size; i++ ) dist[i] = INT_MAX/2;
    dist[start]=0;
    changed = true;
    while( changed ){
      changed = false;
      for( int  i = 0 ; i < size; i++ ){
        for( int j = 0 ; j < (int)graph[i].size(); j++ ){
          //cout << i <<"-"<< graph[i][j].to <<",";
          edge e = graph[i][j];
          if( e.cap > 0 && dist[i]+e.cost < dist[e.to] ){
            changed = true;
            dist[e.to] = dist[i]+e.cost;
            prev[e.to] = i;
            prevind[e.to] = j;
          }
        }
      }
    }
    //for( int i = 0 ; i < size; i++ ) cout << dist[i]<< " , " ;
    //cout << endl;
    if( dist[end] == INT_MAX/2){
      return -1;
    }
    // calc flaw
    int f = INT_MAX;
    int p = end;
    while( p != start ){
      f = min(f, graph[prev[p]][prevind[p]].cap );
      p = prev[p];
    }
    //cout << endl;
    f =min( F, f );
    // exec flaw
    p = end;
    while( p != start){
      graph[prev[p]][prevind[p]].cap -= f;
      int ind = graph[prev[p]][prevind[p]].rev;
      graph[p][ind].cap += f;
      cost += f*graph[prev[p]][prevind[p]].cost;
      p = prev[p];
    }
    F-=f;
  }
  return cost;
}

void addedge( vector<edge> graph[],int from, int to, int cap, int cost ){
  //枝を追加する。逆向きには容量0でコストが真逆な枝を追加しておく。
  graph[from].push_back( (edge){to,cap,cost,(int)graph[to].size()} );
  graph[to].push_back( (edge){from,0,-cost, (int)graph[from].size()-1} );
  return;
}

int main(){
   int N,A,C;
   vector<edge> graph[250];
   cin >> N;
   cin >> A;
   int B[A];
   for( int i = 0 ; i <A ;i++){
      cin >> B[i];
   }
   cin >> C;
   int D[C];
   for( int i = 0 ; i < C; i++ ){
      cin >> D[i];
   }
   sort(B,B+A);
   reverse(B,B+A);
   sort(D,D+C);
   for( int i = 0 ; i < N; i++ ){
      addedge(graph,0,i+1,1,0);
      addedge(graph,N+i+1,249,1,0);
   }
   for( int i = 0 ; i <N; i++ ){
      int start = (i/A)*A;
      int end = min(start+A,N-1);
      for( int j = 0 ; j < N; j++ ){
         int start2 = (j/C)*C;
         int end2 = min(start2+C,N-1);
         //if(i==38 && j==0) cout << start<<"-"<<end<<"vs"<<start2<<"-"<<end2<<endl;
         if( end<start2 || end2<start) continue;
         if(B[i%A] <= D[j%C]){
            //cout << i<<"--1->"<<N+j<<endl;
            addedge(graph,i+1,N+1+j,1,1);
         }
         else{
            //cout << i<<"--0->"<<N+j<<endl;
            addedge(graph,i+1,N+1+j,1,0);
         }
      }
   }
   cout << N-mincost(graph,250,0,249,N)<<endl;
   return 0;
}
0