結果

問題 No.2539 スライムゲーム
ユーザー 👑 p-adicp-adic
提出日時 2022-11-06 22:21:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 1,737 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 68,792 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-10 20:50:04
合計ジャッジ時間 3,062 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 1 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 3 ms
6,676 KB
testcase_29 AC 3 ms
6,676 KB
testcase_30 AC 4 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 3 ms
6,676 KB
testcase_34 AC 3 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 3 ms
6,676 KB
testcase_37 AC 3 ms
6,676 KB
testcase_38 AC 4 ms
6,676 KB
testcase_39 AC 4 ms
6,676 KB
testcase_40 AC 4 ms
6,676 KB
testcase_41 AC 4 ms
6,676 KB
testcase_42 AC 4 ms
6,676 KB
testcase_43 AC 4 ms
6,676 KB
testcase_44 AC 4 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>
using namespace std;
using ll = long long;
#define MAIN main
#define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) 
#define TYPE_OF( VAR ) decay_t<decltype( VAR )>
#define CEXPR( LL , BOUND , VALUE ) constexpr LL BOUND = VALUE
#define CIN( LL , A ) LL A; cin >> A 
#define ASSERT( A , MIN , MAX ) assert( MIN <= A && A <= MAX ) 
#define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX ) 
#define FOREQINV( VAR , INITIAL , FINAL ) for( TYPE_OF( INITIAL ) VAR = INITIAL ; VAR >= FINAL ; VAR -- ) 
#define QUIT return 0 
#define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT 

ll HereditaryNotation( const string& s , const int& l , int r , ll& bound )
{
  CEXPR( char , R , ')' );
  ll answer = 0;
  bool found;
  while( l < r ){
    if( bound <= 0 ){
      return -1;
    }
    found = false;
    if( s[r-1] == R ){
      int layer = 1;
      FOREQINV( m , r - 2 , l ){
	if( s[m] == R ){
	  layer++;
	} else {
	  layer--;
	}
	if( layer == 0 ){
	  ll exponent = 0;
	  ll power = 1;
	  while( power <= bound ){
	    power *= 2;
	    exponent++;
	  }
	  exponent--;
	  if( ( exponent = HereditaryNotation( s , m + 1 , r - 1 , exponent ) ) == -1 ){
	    return -1;
	  }
	  ( power = 1 ) <<= exponent;
	  r = m;
	  answer += power;
	  bound -= power;
	  found = true;
	  break;
	}
      }
    }
    if( ! found ){
      return answer + 1;
    }
  }
  return answer;
}

int MAIN()
{
  UNTIE;
  CEXPR( int , bound_L , 100000 );
  CIN( string , S );
  int L = S.size();
  ASSERT( L , 1 , bound_L );
  ll bound = 1000000000000000000;
  ll answer = HereditaryNotation( S , 0 , L , bound );
  if( answer == -1 ){
    RETURN( "INFTY" );
  }
  RETURN( answer );
}
0