結果
問題 | No.2539 スライムゲーム |
ユーザー | 👑 p-adic |
提出日時 | 2022-11-06 22:21:16 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 1,000 ms |
コード長 | 1,737 bytes |
コンパイル時間 | 1,183 ms |
コンパイル使用メモリ | 68,608 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-26 00:52:23 |
合計ジャッジ時間 | 2,592 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 45 |
ソースコード
#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 ); }