結果
問題 | No.2398 ヒドラ崩し |
ユーザー |
👑 |
提出日時 | 2022-11-25 02:46:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,732 bytes |
コンパイル時間 | 716 ms |
コンパイル使用メモリ | 68,912 KB |
最終ジャッジ日時 | 2025-02-08 23:37:48 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include <iostream>#include <string>#include <stdio.h>#include <stdint.h>#include <cassert>using namespace std;#define MAIN main#define TYPE_OF( VAR ) remove_const<remove_reference<decltype( VAR )>::type >::type#define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr )#define CEXPR( LL , BOUND , VALUE ) constexpr const 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"; QUITint g( const string& H ){CEXPR( int , length , 100000 );int size = H.size();ASSERT( size , 2 , length );static const string L = "(";int count_mex = 0;bool exceptional = false;int count_mex_exceptional = 0;int height = 0;FOREQINV( i , size - 1 , 0 ){if( H.substr( i , 1 ) == L ){height--;if( height == -1 ){break;} else if( height > 0 ? H.substr( i - 1 , 1 ) == L : false ){exceptional = true;height--;i--;while( height > 0 && i > 0 ? H.substr( i - 1 , 1 ) == L : false ){count_mex_exceptional++;height--;i--;}break;} else {if( height > 0 ){height = 1;}count_mex++;}} else {height++;}}if( exceptional ){if( count_mex == 0 ){return count_mex_exceptional % 2 == 0 ? 2 : 3;} else {return count_mex % 2 == 0 ? 1 : 0;}}return count_mex % 2 == 0 ? 0 : 1;}int MAIN(){UNTIE;CIN( string , H );RETURN( g( H ) == 0 ? 1 : 0 );}