結果

問題 No.291 黒い文字列
ユーザー 0w10w1
提出日時 2017-01-02 17:12:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 2,385 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 167,584 KB
実行使用メモリ 5,100 KB
最終ジャッジ日時 2023-08-22 09:25:09
合計ジャッジ時間 3,866 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,888 KB
testcase_01 AC 4 ms
4,940 KB
testcase_02 AC 8 ms
4,972 KB
testcase_03 AC 6 ms
4,860 KB
testcase_04 AC 4 ms
4,904 KB
testcase_05 AC 6 ms
4,828 KB
testcase_06 AC 7 ms
4,856 KB
testcase_07 AC 5 ms
4,864 KB
testcase_08 AC 5 ms
5,028 KB
testcase_09 AC 4 ms
5,064 KB
testcase_10 AC 14 ms
4,916 KB
testcase_11 AC 10 ms
4,848 KB
testcase_12 AC 10 ms
4,944 KB
testcase_13 AC 4 ms
4,904 KB
testcase_14 AC 7 ms
4,928 KB
testcase_15 AC 6 ms
4,920 KB
testcase_16 AC 37 ms
4,904 KB
testcase_17 AC 38 ms
4,920 KB
testcase_18 AC 37 ms
4,832 KB
testcase_19 AC 45 ms
4,912 KB
testcase_20 AC 51 ms
5,020 KB
testcase_21 AC 34 ms
4,896 KB
testcase_22 AC 54 ms
5,028 KB
testcase_23 AC 67 ms
4,956 KB
testcase_24 AC 44 ms
4,920 KB
testcase_25 AC 36 ms
4,888 KB
testcase_26 AC 35 ms
4,920 KB
testcase_27 AC 34 ms
5,100 KB
testcase_28 AC 34 ms
4,860 KB
testcase_29 AC 35 ms
4,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

string S;

void init(){
  cin >> S;
}

int dp[ 2 ][ 20 + 1 ][ 20 + 1 ][ 20 + 1 ][ 20 + 1 ];

void preprocess(){
  memset( dp, -1, sizeof( dp ) );
  dp[ 0 ][ 0 ][ 0 ][ 0 ][ 0 ] = 0;
  for( int i = 0; i < S.size(); ++i ){
    for( int j = 0; j <= 20; ++j ){
      for( int k = 0; k <= 20; ++k ){
        for( int l = 0; l <= 20; ++l ){
          for( int m = 0; m <= 20; ++m ){
	          int v = dp[ i & 1 ][ j ][ k ][ l ][ m ];
	          if( v == -1 ) continue;
	          if( ( S[ i ] == 'K' or S[ i ] == '?' ) and j + 1 <= 20 ){
	            upmax( dp[ ~i & 1 ][ j + 1 ][ k ][ l ][ m ], v );
	          }
	          if( ( S[ i ] == 'U' or S[ i ] == '?' ) and j - 1 >= 0 and k + 1 <= 20 ){
	            upmax( dp[ ~i & 1 ][ j - 1 ][ k + 1 ][ l ][ m ], v );
	          }
	          if( ( S[ i ] == 'R' or S[ i ] == '?' ) and k - 1 >= 0 and l + 1 <= 20 ){
	            upmax( dp[ ~i & 1 ][ j ][ k - 1 ][ l + 1 ][ m ], v );
	          }
	          if( ( S[ i ] == 'O' or S[ i ] == '?' ) and l - 1 >= 0 and m + 1 <= 20 ){
	            upmax( dp[ ~i & 1 ][ j ][ k ][ l - 1 ][ m + 1 ], v );
	          }
	          if( ( S[ i ] == 'I' or S[ i ] == '?' ) and m - 1 >= 0 ){
	            upmax( dp[ ~i & 1 ][ j ][ k ][ l ][ m - 1 ], v + 1 );
	          }
	          upmax( dp[ ~i & 1 ][ j ][ k ][ l ][ m ], v );
          }
        }
      }
    }
    memset( dp[ i & 1 ], -1, sizeof( dp[ i & 1 ] ) );
  }
}

void solve(){
  int ans = 0;
  for( int i = 0; i <= 20; ++i ){
    for( int j = 0; j <= 20; ++j ){
      for( int k = 0; k <= 20; ++k ){
        for( int l = 0; l <= 20; ++l ){
          upmax( ans, dp[ ( int ) S.size() & 1 ][ i ][ j ][ k ][ l ] );
        }
      }
    }
  }
  cout << ans << endl;           
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0