結果

問題 No.5006 Hidden Maze
ユーザー 👑 p-adicp-adic
提出日時 2022-08-20 11:24:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 7,219 bytes
コンパイル時間 637 ms
実行使用メモリ 22,692 KB
スコア 0
平均クエリ数 1002.00
最終ジャッジ日時 2022-08-20 11:25:02
合計ジャッジ時間 13,673 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
22,216 KB
testcase_01 AC 71 ms
22,264 KB
testcase_02 AC 71 ms
21,768 KB
testcase_03 AC 72 ms
22,216 KB
testcase_04 AC 77 ms
22,444 KB
testcase_05 AC 78 ms
22,632 KB
testcase_06 AC 72 ms
21,892 KB
testcase_07 AC 72 ms
21,992 KB
testcase_08 AC 70 ms
22,432 KB
testcase_09 AC 70 ms
21,940 KB
testcase_10 AC 69 ms
21,916 KB
testcase_11 AC 71 ms
21,992 KB
testcase_12 AC 71 ms
22,216 KB
testcase_13 AC 69 ms
22,564 KB
testcase_14 AC 67 ms
21,916 KB
testcase_15 AC 71 ms
22,552 KB
testcase_16 AC 72 ms
22,620 KB
testcase_17 AC 72 ms
21,892 KB
testcase_18 AC 75 ms
22,264 KB
testcase_19 AC 76 ms
21,992 KB
testcase_20 AC 71 ms
21,916 KB
testcase_21 AC 70 ms
21,748 KB
testcase_22 AC 72 ms
21,892 KB
testcase_23 AC 71 ms
22,620 KB
testcase_24 AC 75 ms
21,992 KB
testcase_25 AC 71 ms
22,216 KB
testcase_26 AC 73 ms
21,892 KB
testcase_27 AC 72 ms
22,444 KB
testcase_28 AC 72 ms
21,880 KB
testcase_29 AC 73 ms
21,892 KB
testcase_30 AC 76 ms
22,552 KB
testcase_31 AC 81 ms
21,928 KB
testcase_32 AC 71 ms
21,992 KB
testcase_33 AC 73 ms
21,892 KB
testcase_34 AC 71 ms
21,892 KB
testcase_35 AC 70 ms
21,904 KB
testcase_36 AC 70 ms
22,048 KB
testcase_37 AC 70 ms
21,768 KB
testcase_38 AC 76 ms
21,892 KB
testcase_39 AC 72 ms
21,952 KB
testcase_40 AC 72 ms
22,444 KB
testcase_41 AC 71 ms
21,780 KB
testcase_42 AC 74 ms
22,588 KB
testcase_43 AC 79 ms
21,904 KB
testcase_44 AC 75 ms
21,892 KB
testcase_45 AC 71 ms
21,992 KB
testcase_46 AC 71 ms
22,612 KB
testcase_47 AC 73 ms
21,892 KB
testcase_48 AC 71 ms
22,444 KB
testcase_49 AC 70 ms
22,564 KB
testcase_50 AC 74 ms
22,216 KB
testcase_51 AC 72 ms
22,612 KB
testcase_52 AC 76 ms
22,624 KB
testcase_53 AC 73 ms
21,952 KB
testcase_54 AC 75 ms
21,768 KB
testcase_55 AC 80 ms
22,588 KB
testcase_56 AC 76 ms
21,940 KB
testcase_57 AC 74 ms
22,584 KB
testcase_58 AC 74 ms
22,632 KB
testcase_59 AC 76 ms
22,564 KB
testcase_60 AC 77 ms
21,980 KB
testcase_61 AC 75 ms
21,892 KB
testcase_62 AC 77 ms
21,768 KB
testcase_63 AC 74 ms
21,980 KB
testcase_64 AC 79 ms
22,264 KB
testcase_65 AC 72 ms
21,756 KB
testcase_66 AC 74 ms
21,892 KB
testcase_67 AC 76 ms
22,552 KB
testcase_68 AC 76 ms
21,940 KB
testcase_69 AC 75 ms
21,812 KB
testcase_70 AC 75 ms
21,904 KB
testcase_71 AC 75 ms
22,588 KB
testcase_72 AC 75 ms
22,600 KB
testcase_73 AC 76 ms
22,004 KB
testcase_74 AC 75 ms
21,928 KB
testcase_75 AC 76 ms
22,216 KB
testcase_76 AC 76 ms
21,928 KB
testcase_77 AC 75 ms
22,644 KB
testcase_78 AC 73 ms
21,992 KB
testcase_79 AC 76 ms
22,612 KB
testcase_80 AC 76 ms
22,612 KB
testcase_81 AC 76 ms
22,612 KB
testcase_82 AC 75 ms
21,892 KB
testcase_83 AC 78 ms
21,856 KB
testcase_84 AC 76 ms
21,904 KB
testcase_85 AC 76 ms
22,264 KB
testcase_86 AC 77 ms
21,992 KB
testcase_87 AC 77 ms
22,264 KB
testcase_88 AC 77 ms
21,820 KB
testcase_89 AC 74 ms
21,880 KB
testcase_90 AC 71 ms
22,692 KB
testcase_91 AC 77 ms
21,880 KB
testcase_92 AC 76 ms
22,620 KB
testcase_93 AC 69 ms
21,892 KB
testcase_94 AC 69 ms
21,904 KB
testcase_95 AC 69 ms
22,576 KB
testcase_96 AC 70 ms
21,880 KB
testcase_97 AC 69 ms
21,892 KB
testcase_98 AC 69 ms
21,892 KB
testcase_99 AC 72 ms
22,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <list>
#include <vector>
#include <string>
#include <stdio.h>
#include <stdint.h>
#include <iomanip>
using namespace std;

using uint = unsigned int;
using ll = long long;

#define CIN( LL , A ) LL A; cin >> A 
#define GETLINE( A ) string A; getline( cin , A ) 
#define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR ) 
#define FOR_LL( VAR , INITIAL , FINAL_PLUS_ONE ) for( ll VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) 
#define FOR_ITR( ARRAY , ITR , END ) for( auto ITR = ARRAY .begin() , END = ARRAY .end() ; ITR != END ; ITR ++ ) 
#define REPEAT( HOW_MANY_TIMES ) FOR_LL( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES ) 
#define RETURN( ANSWER ) cout << ( ANSWER ) << endl; return 0 
#define DOUBLE( PRECISION , ANSWER ) cout << fixed << setprecision( PRECISION ) << ( ANSWER ) << endl; return 0 
#define MIN( A , B ) A < B ? A : B;
#define MAX( A , B ) A < B ? B : A;
template <typename T> inline T Distance( const T& a , const T& b ){ return a < b ? b - a : a - b; }

#include <initializer_list>

// 自分のライブラリ(https://github.com/p-adic/cpp)よりソースコードをコピーして編集している。
template <typename T , uint D>
class AffineSpace
{

private:
  T m_v[D];

public:
  inline AffineSpace();
  inline AffineSpace( const initializer_list<T> init );
  template <uint E> inline AffineSpace( const T (&v)[E] );
  template <uint E> inline AffineSpace( const AffineSpace<T,E>& x );
  // E < Dの場合のみサポート
  template <typename... ARGS> inline AffineSpace( const uint& E , const ARGS&... args );

  template <uint E> inline AffineSpace<T,D>& operator=( const AffineSpace<T,E>& x );
  T& operator[]( const uint& i );
  const T& operator[]( const uint& i ) const;
  
private:
  template <uint E> void Set( const T (&v)[E] );
  void Substitute( const initializer_list<T> init );
  template <uint E> void Substitute( const T (&v)[E] );
  template <uint E> void Substitute( const AffineSpace<T,E>& x );

};

template <typename T , uint D> inline AffineSpace<T,D>::AffineSpace() : m_v() {};
template <typename T , uint D> inline AffineSpace<T,D>::AffineSpace( const initializer_list<T> init ) : m_v() { Substitute( init ); }
template <typename T , uint D> template <uint E> inline AffineSpace<T,D>::AffineSpace( const T (&v)[E] ) : m_v() { Substitute<E>( v ); }
template <typename T , uint D> template <uint E> inline AffineSpace<T,D>::AffineSpace( const AffineSpace<T,E>& x ) : m_v() { Substitute<E>( x ); }
template <typename T , uint D> template <typename... ARGS> inline AffineSpace<T,D>::AffineSpace( const uint& E , const ARGS&... args ) : AffineSpace( args... ) { m_v[E]++; }

template <typename T , uint D> template <uint E> inline AffineSpace<T,D>& AffineSpace<T,D>::operator=( const AffineSpace<T,E>& x ) { Set<E>( x.m_v ); return *this; }

template <typename T , uint D> inline T& AffineSpace<T,D>::operator[]( const uint& i ) { return m_v[i]; }
template <typename T , uint D> inline const T& AffineSpace<T,D>::operator[]( const uint& i ) const { return m_v[i]; }

template <typename T , uint D> template <uint E>
void AffineSpace<T,D>::Set( const T (&v)[E] )
{

  Substitute( v );
  constexpr const uint min = E < D ? E : D;

  for( uint i = min ; i < D ; i++ ){

    m_v[i] = 0;
    
  }

  return;
  
}

template <typename T , uint D>
void AffineSpace<T,D>::Substitute( const initializer_list<T> init )
{

  const uint size = init.size();
  const uint min = size < D ? size : D;
  auto itr = init.begin();

  for( uint i = 0 ; i < min ; i++ ){

    m_v[i] = *itr;
    itr++;
    
  }

  return;
  

}

template <typename T , uint D> template <uint E>
void AffineSpace<T,D>::Substitute( const T (&v)[E] )
{

  constexpr const uint min = E < D ? E : D;

  for( uint i = 0 ; i < min ; i++ ){

    m_v[i] = v[i];
    
  }

  return;
  
}

template <typename T , uint D> template <uint E>
void AffineSpace<T,D>::Substitute( const AffineSpace<T,E>& x )
{

  constexpr const uint min = E < D ? E : D;

  for( uint i = 0 ; i < min ; i++ ){

    m_v[i] = x[i];
    
  }

  return;
  
}

#define H 20 
#define W 20 
#define H_minus 19 
#define W_minus 19 
#define T 1001 
#define K 401 

int main()
{

  constexpr const ll D = 0;
  constexpr const ll R = 1;
  constexpr const ll U = 2;
  constexpr const ll L = 3;
  const string direction[4] = { "D" , "R" , "U" , "L" };
  CIN( ll , H_dummy );
  CIN( ll , W_dummy );
  CIN( ll , p );
  bool wall[H][W][4] = {};
  FOR_LL( i , 0 , H ){
    wall[i][0][L] = true;
    wall[i][W-1][R] = true;
  }
  FOR_LL( j , 0 , W ){
    wall[0][j][U] = true;
    wall[H-1][j][D] = true;
  }
  ll fixed_length = 0;
  ll strategy[K] = {};
  ll coord_x[K] = {};
  ll coord_y[K] = {};
  FOR_LL( t , 0 , T ){
    FOR_LL( k , fixed_length + 1 , K ){
      const ll& x = coord_x[k];
      const ll& y = coord_y[k];
      bool (&w)[4] = wall[y][x];
      bool searching = true;
      const ll& s_k_prev = strategy[k-1];
      ll& s_k = strategy[k];
      s_k = ( s_k_prev + 3 ) % 4;
      for( ll d = 0 ; d < 4 && searching ; d++ ){
	if( ! w[s_k] ){
	  searching = false;
	} else {
	  s_k = ( s_k + 1 ) % 4;
	}
      }
      if( searching ){
	for( ll d = 0 ; d < 4 ; d++ ){
	  w[d] = ( x == 0 && d == L ) || ( x == W_minus && d == R ) || ( y == 0 && d == U ) || ( y == H_minus && d == D );
	  if( x > 0 ){
	    wall[y][x-1][R] = true;
	  }
	  if( x < H_minus ){
	    wall[y][x+1][L] = true;
	  }
	  if( y > 0 ){
	    wall[y-1][x][D] = true;
	  }
	  if( y < W_minus ){
	    wall[y+1][x][W] = true;
	  }
	}
	s_k = ( s_k_prev + 3 ) % 4;
	for( ll d = 0 ; d < 4 && searching ; d++ ){
	  if( ! w[s_k] ){
	    searching = false;
	  } else {
	    s_k = ( s_k + 1 ) % 4;
	  }
	}
      }
      coord_x[k+1] = x + ( s_k == L ? -1 : s_k == R ? 1 : 0 );
      coord_y[k+1] = y + ( s_k == U ? -1 : s_k == D ? 1 : 0 );
    }
    FOR_LL( k , 1 , K ){
      cout << direction[strategy[k]];
    }
    cout << endl;
    CIN( ll , length );
    if( length == -1 ){
      RETURN( 0 );
    }
    if( fixed_length < length ){
      fixed_length = length;
      ll K0 = fixed_length + 1;
      if( K0 < K ){
	const ll& x = coord_x[K0];
	const ll& y = coord_y[K0];
	const ll& s_K0 = strategy[K0];
	wall[y][x][s_K0] = true;
	if( s_K0 == D || y < H_minus ){
	  wall[y+1][x][U] = true;
	}
	if( s_K0 == R || x < W_minus ){
	  wall[y][x+1][L] = true;
	}
	if( s_K0 == U || y > 0 ){
	  wall[y-1][x][D] = true;
	}
	if( s_K0 == L || x > 0 ){
	  wall[y][x-1][R] = true;
	}
      }
      FOR_LL( k , 1 , K0 ){
	const ll& x = coord_x[k];
	const ll& y = coord_y[k];
	FOR_LL( m , k + 1 , K0 ){
	  if( coord_x[m] == x && coord_y[m] == y ){
	    const ll& s_k = strategy[k];
	    wall[y][x][s_k] = true;
	    if( s_k == D || y < H_minus ){
	      wall[y+1][x][U] = true;
	    }
	    if( s_k == R || x < W_minus ){
	      wall[y][x+1][L] = true;
	    }
	    if( s_k == U || y > 0 ){
	      wall[y-1][x][D] = true;
	    }
	    if( s_k == L || x > 0 ){
	      wall[y][x-1][R] = true;
	    }
	    ll d = m - k;
	    fixed_length -= d;
	    K0 -= d;
	    FOR_LL( n , k + 1 , K0 ){
	      strategy[n] = strategy[n + d];
	      coord_x[n] = coord_x[n + d];
	      coord_y[n] = coord_y[n + d];
	    }
	  }
	}
      }
    }
  }
  return 0;
}
0