結果

問題 No.2226 Hello, Forgotten World!
ユーザー 👑 p-adicp-adic
提出日時 2022-12-10 21:31:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 4,155 bytes
コンパイル時間 1,359 ms
コンパイル使用メモリ 86,376 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-24 21:22:05
合計ジャッジ時間 1,982 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 117 ms
6,940 KB
testcase_02 AC 21 ms
6,944 KB
testcase_03 AC 24 ms
6,940 KB
testcase_04 AC 5 ms
6,940 KB
testcase_05 AC 25 ms
6,940 KB
testcase_06 AC 10 ms
6,940 KB
testcase_07 AC 15 ms
6,944 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 15 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 入力フォーマットチェック
#pragma GCC optimize ( "O3" )
#pragma GCC target ( "avx" )
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdint.h>
#include <cassert>
using namespace std;

using ll = long long;

#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 GETLINE( A ) string A; getline( cin , A ) 
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) 
#define FOREQINV( VAR , INITIAL , FINAL ) for( TYPE_OF( INITIAL ) VAR = INITIAL ; VAR >= FINAL ; VAR -- ) 
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES ) 
#define QUIT return 0 
#define COUT( ANSWER ) cout << ( ANSWER ) << "\n"; 

// 入力フォーマットチェック用
// 余分な改行を許さない
// #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; cin >> VARIABLE_FOR_CHECK_REDUNDANT_INPUT; assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin );
#define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; getline( cin , VARIABLE_FOR_CHECK_REDUNDANT_INPUT ); assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin );
// |N| <= BOUNDを満たすNをSから構築
#define STOI( S , N , BOUND ) TYPE_OF( BOUND ) N = 0; { bool VARIABLE_FOR_POSITIVITY_FOR_STOI = true;  assert( S != "" ); if( S.substr( 0 , 1 ) == "-" ){ VARIABLE_FOR_POSITIVITY_FOR_STOI = false; S = S.substr( 1 ); assert( S != "" ); } assert( S.substr( 0 , 1 ) != " " ); while( S == "" ? false : S.substr( 0 , 1 ) != " " ){ assert( N < BOUND / 10 ? true : N == BOUND / 10 && stoi( S.substr( 0 , 1 ) ) <= BOUND % 10 ); N = N * 10 + stoi( S.substr( 0 , 1 ) ); S = S.substr( 1 ); } if( ! VARIABLE_FOR_POSITIVITY_FOR_STOI ){ N *= -1; } if( S != "" ){ S = S.substr( 1 ); } } 
// 1行で入力される変数の個数が適切か確認(半角空白の個数+1を調べる)
#define COUNT_VARIABLE( S , VARIABLE_NUMBER ) { int size = S.size(); int count = 0; for( int i = 0 ; i < size ; i++ ){ if( S.substr( i , 1 ) == " " ){ count++; } } assert( count + 1 == VARIABLE_NUMBER ); } 

int main()
{
  UNTIE;
  CEXPR( int , bound_T , 20 );
  GETLINE( T_str );
  COUNT_VARIABLE( T_str , 1 );
  STOI( T_str , T , bound_T );
  int length;
  CEXPR( int , ten , 10 );
  string helloworld[ten] = { "h" , "e" , "l" , "l" , "o" , "w" , "o" , "r" , "l" , "d" };
  string helowrd[7] = { "h" , "e" , "l" , "o" , "w" , "r" , "d" };
  string abc = "abcdefghijklmnopqrstuvwxyz?";
  string q = "?";
  string a = "a";
  string c , answer , answer_new;
  CEXPR( int , bound_N , 1000 );
  REPEAT( T ){
    GETLINE( N_str );
    COUNT_VARIABLE( N_str , 1 );
    STOI( N_str , N , bound_N );
    GETLINE( S );
    COUNT_VARIABLE( S , 1 );
    assert( int( S.size() ) == N );
    length = 0;
    answer = "";
    FOREQINV( i , N - 1 , 0 ){
      c = S.substr( i , 1 );
      bool valid_input = false;
      FOR( j , 0 , 27 ){
	if( c == abc.substr( j , 1 ) ){
	  valid_input = true;
	  break;
	}
      }
      assert( valid_input );
      if( c == helloworld[ten - 1 - length] || c == q ){
	length++;
	if( length == ten ){
	  answer_new = "";
	  FOR( j , 0 , i ){
	    c = S.substr( j , 1 );
	    answer_new += ( c == q ? a : c );
	  }
	  FOR( j , 0 , ten ){
	    answer_new += helloworld[j];
	  }
	  FOR( j , i + ten , N ){
	    c = S.substr( j , 1 );
	    answer_new += ( c == q ? a : c );
	  }
	  if( answer == "" || answer > answer_new ){
	    answer = answer_new;
	  }
	  i += ten - 1;
	  length = 0;
	}
      } else if( length != 0 ){
	FOR( j , 0 , 7 ){
	  if( c == helowrd[j] ){
	    i += length;
	    break;
	  }
	}
	length = 0;
      }
    }
    if( answer == "" ){
      COUT( -1 );
    } else {
      COUT( answer );
    }
  }
  CHECK_REDUNDANT_INPUT;
  QUIT;
}
0