結果

問題 No.291 黒い文字列
ユーザー どららどらら
提出日時 2015-10-16 23:49:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,387 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-29 02:02:26
合計ジャッジ時間 2,049 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;


class Dinic {
  int MAX_V;
  int INF;
  struct edge{ int to, cap, rev, icap, flow; };

  vector< vector<edge> > G;
  vector<int> level; //sからの距離
  vector<int> iter; //どこまで調べたか

  void max_flow_bfs(int s){
    fill(level.begin(), level.end(), -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
      int v = que.front(); que.pop();
      for(int i=0; i<G[v].size(); i++){
        edge &e = G[v][i];
        if(e.cap>0 && level[e.to]<0){
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }
  int max_flow_dfs(int v, int t, int f){
    if(v==t) return f;
    for(int &i=iter[v]; i<G[v].size(); i++){
      edge &e = G[v][i];
      if(e.cap>0 && level[v]<level[e.to]){
        int d = max_flow_dfs(e.to, t, min(f, e.cap));
        if(d>0){
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          e.flow += d;
          return d;
        }
      }
    }
    return 0;
  }

public:
  Dinic(int N):MAX_V(N),G(N),level(N),iter(N){
    INF = 99999999;
  }

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

  int get_flow(int from, int to){ //untried
    rep(i,G[from].size()){
      if(G[from][i].to == to){
        return G[from][i].flow;
      }
    }
    return -1;
  }

  int max_flow(int s, int t){
    int flow = 0;
    while(true){
      max_flow_bfs(s);
      if(level[t]<0) return flow;
      fill(iter.begin(), iter.end(), 0);
      int f;
      while((f = max_flow_dfs(s, t, INF))>0){
        flow += f;
      }
    }
  }
  
  int min_cut(int s, int t, vector<int>& S, vector<int>& T){
    S.clear();
    T.clear();

    int maxf = max_flow(s, t);
    for(int i=0; i<level.size(); i++){
      if(level[i] >= 0) S.push_back(i);
      else T.push_back(i);
    }

    return maxf;
  }
};

int main(){
  ios::sync_with_stdio(false);

  string S;
  cin >> S;

  Dinic dinic(S.length()*5 + 2);
  int s = S.length()*5;
  int t = S.length()*5+1;

  rep(i,S.length()){
    if(S[i] == 'K' || S[i] == '?'){
      dinic.add_edge(s, i*5, 1);
      REP(j,i+1,S.length()){
        if(S[j] == 'U' || S[j] == '?') dinic.add_edge(i*5, j*5+1, 1);
      }
    }

    if(S[i] == 'U' || S[i] == '?'){
      REP(j,i+1,S.length()){
        if(S[j] == 'R' || S[j] == '?') dinic.add_edge(i*5+1, j*5+2, 1);
      }
    }

    if(S[i] == 'R' || S[i] == '?'){
      REP(j,i+1,S.length()){
        if(S[j] == 'O' || S[j] == '?') dinic.add_edge(i*5+2, j*5+3, 1);
      }
    }

    if(S[i] == 'O' || S[i] == '?'){
      REP(j,i+1,S.length()){
        if(S[j] == 'I' || S[j] == '?') dinic.add_edge(i*5+3, j*5+4, 1);
      }
    }

    if(S[i] == 'I' || S[i] == '?'){
      dinic.add_edge(i*5+4, t, 1);
    }

  }

  cout << dinic.max_flow(s,t) << endl;
  
  return 0;
}
0