結果

問題 No.2398 ヒドラ崩し
ユーザー 👑 p-adicp-adic
提出日時 2022-11-25 02:46:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,732 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 70,228 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 13:27:56
合計ジャッジ時間 2,758 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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"; QUIT 


int 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 );
}
0