結果

問題 No.102 トランプを奪え
ユーザー 0w10w1
提出日時 2016-12-12 21:21:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,087 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 166,596 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-19 21:43:48
合計ジャッジ時間 2,157 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 3 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 8 ms
4,376 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;

int N1, N2, N3, N4;

void init(){
  cin >> N1 >> N2 >> N3 >> N4;
}

int tot;
int dp[ 13 + 1 ][ 13 + 1 ][ 13 + 1 ][ 13 + 1 ][ 2 ];
int vis[ 13 + 1 ][ 13 + 1 ][ 13 + 1 ][ 13 + 1 ][ 2 ];

int dfs( int a, int b, int c, int d, int e ){
  int &res = dp[ a ][ b ][ c ][ d ][ e ];
  if( vis[ a ][ b ][ c ][ d ][ e ] )
    return res;
  vis[ a ][ b ][ c ][ d ][ e ] = 1;
  res = -INF;
  int s = a + b + c + d;
  for( int i = 1; i <= 3 and a + i <= N1; ++i ){
    dfs( a + i, b, c, d, e ^ 1 );
    if( dp[ a + i ][ b ][ c ][ d ][ e ^ 1 ] == -INF ) continue;
    if( a > 0 )
      upmax( res, ( tot - s ) - ( dp[ a + i ][ b ][ c ][ d ][ e ^ 1 ] + i ) );
    else
      upmax( res, ( ( tot - s ) - ( dp[ a + i ][ b ][ c ][ d ][ e ^ 1 ] + i ) ) / 2 );
  }
  for( int i = 1; i <= 3 and b + i <= N2; ++i ){
    dfs( a, b + i, c, d, e ^ 1 );
    if( dp[ a ][ b + i ][ c ][ d ][ e ^ 1 ] == -INF ) continue;
    if( b > 0 )
      upmax( res, ( tot - s ) - ( dp[ a ][ b + i ][ c ][ d ][ e ^ 1 ] + i ) );
    else
      upmax( res, ( ( tot - s ) - ( dp[ a ][ b + i ][ c ][ d ][ e ^ 1 ] + i ) ) / 2 );
  }
  for( int i = 1; i <= 3 and c + i <= N3; ++i ){
    dfs( a, b, c + i, d, e ^ 1 );
    if( dp[ a ][ b ][ c + i ][ d ][ e ^ 1 ] == -INF ) continue;
    if( c > 0 )
      upmax( res, ( tot - s ) - ( dp[ a ][ b ][ c + i ][ d ][ e ^ 1 ] + i ) );
    else
      upmax( res, ( ( tot - s ) - ( dp[ a ][ b ][ c + i ][ d ][ e ^ 1 ] + i ) ) / 2 );
  }
  for( int i = 1; i <= 3 and d + i <= N4; ++i ){
    dfs( a, b, c, d + i, e ^ 1 );
    if( dp[ a ][ b ][ c ][ d + i ][ e ^ 1 ] == -INF ) continue;
    if( d > 0 )
      upmax( res, ( tot - s ) - ( dp[ a ][ b ][ c ][ d + i ][ e ^ 1 ] + i ) );
    else
      upmax( res, ( ( tot - s ) - ( dp[ a ][ b ][ c ][ d + i ][ e ^ 1 ] + i ) ) / 2 );
  }
  // cout << a << " " << b << " " << c << " " << d << " " << e << " " << res << endl;
  return res;
}

void preprocess(){
  tot = N1 + N2 + N3 + N4;
  vis[ N1 ][ N2 ][ N3 ][ N4 ][ 0 ] = 1;
  dp[ N1 ][ N2 ][ N3 ][ N4 ][ 0 ] = 0;
  vis[ N1 ][ N2 ][ N3 ][ N4 ][ 1 ] = 1;
  dp[ N1 ][ N2 ][ N3 ][ N4 ][ 1 ] = -INF;
  dfs( 0, 0, 0, 0, 0 );
  dfs( 0, 0, 0, 0, 1 );
}

void solve(){
  int f = dp[ 0 ][ 0 ][ 0 ][ 0 ][ 0 ];
  if( dp[ 0 ][ 0 ][ 0 ][ 0 ][ 1 ] != -INF )
    upmax( f, tot - dp[ 0 ][ 0 ][ 0 ][ 0 ][ 1 ] );
  if( f * 2 == tot )
    cout << "Draw" << endl;
  else if( f * 2 < tot )
    cout << "Jiro" << endl;
  else
    cout << "Taro" << endl;
}

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