#ifdef DEBUG #define _GLIBCXX_DEBUG #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ); signal( SIGABRT , &AlertAbort ) #define DEXPR( LL , BOUND , VALUE , DEBUG_VALUE ) CEXPR( LL , BOUND , DEBUG_VALUE ) #define CERR( MESSAGE ) cerr << MESSAGE << endl; #define COUT( ANSWER ) cout << "出力: " << ANSWER << endl #define ASSERT( A , MIN , MAX ) CERR( "ASSERTチェック: " << ( MIN ) << ( ( MIN ) <= A ? "<=" : ">" ) << A << ( A <= ( MAX ) ? "<=" : ">" ) << ( MAX ) ); assert( ( MIN ) <= A && A <= ( MAX ) ) #define LIBRARY_SEARCH bool searched_library = false; LibrarySearch( searched_library ); if( searched_library ){ QUIT; }; #define START_WATCH( PROCESS_NAME ) StartWatch( PROCESS_NAME ) #define STOP_WATCH( HOW_MANY_TIMES ) StopWatch( HOW_MANY_TIMES ) #else #pragma GCC optimize ( "O3" ) #pragma GCC optimize( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define DEXPR( LL , BOUND , VALUE , DEBUG_VALUE ) CEXPR( LL , BOUND , VALUE ) #define CERR( MESSAGE ) #define COUT( ANSWER ) cout << ANSWER << "\n" #define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) ) #define LIBRARY_SEARCH #define START_WATCH( PROCESS_NAME ) #define STOP_WATCH( HOW_MANY_TIMES ) #endif // #define RANDOM_TEST #include using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; #define ATT __attribute__( ( target( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) ) ) #define TYPE_OF( VAR ) decay_t #define CEXPR( LL , BOUND , VALUE ) constexpr LL BOUND = VALUE #define CIN( LL , A ) LL A; cin >> A #define CIN_ASSERT( A , MIN , MAX ) TYPE_OF( MAX ) A; SET_ASSERT( A , MIN , MAX ) #define GETLINE( A ) string A; getline( cin , A ) #define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR ) #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ ) #define FOREQINV( VAR , INITIAL , FINAL ) for( TYPE_OF( INITIAL ) VAR = INITIAL ; VAR >= FINAL ; VAR -- ) #define AUTO_ITR( ARRAY ) auto itr_ ## ARRAY = ARRAY .begin() , end_ ## ARRAY = ARRAY .end() #define FOR_ITR( ARRAY ) for( AUTO_ITR( ARRAY ) , itr = itr_ ## ARRAY ; itr_ ## ARRAY != end_ ## ARRAY ; itr_ ## ARRAY ++ , itr++ ) #define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT_ ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES ) #define SET_PRECISION( DECIMAL_DIGITS ) cout << fixed << setprecision( DECIMAL_DIGITS ) #define TEST_CASE_NUM( BOUND ) DEXPR( int , bound_T , BOUND , min( BOUND , 100 ) ); int T = 1; if constexpr( bound_T > 1 ){ SET_ASSERT( T , 1 , bound_T ); } #define START_MAIN REPEAT( T ){ if constexpr( bound_T > 1 ){ CERR( "testcase " << VARIABLE_FOR_REPEAT_T << ":" ); } #define FINISH_MAIN goto END_MAIN; END_MAIN: CERR( "" ); } #define QUIT return 0 #ifdef DEBUG inline void AlertAbort( int n ) { CERR( "abort関数が呼ばれました。assertマクロのメッセージが出力されていない場合はオーバーフローの有無を確認をしてください。" ); } void StartWatch( const string& process_name = "nothing" ); void StopWatch( const int& how_many_times = 1 ); #endif #if defined( DEBUG ) && defined( RANDOM_TEST ) ll GetRand( const ll& Rand_min , const ll& Rand_max ); #define SET_ASSERT( A , MIN , MAX ) CERR( #A << " = " << ( A = GetRand( MIN , MAX ) ) ) #define RETURN( ANSWER ) if( ( ANSWER ) == guchoku ){ CERR( ( ANSWER ) << " == " << guchoku ); goto END_MAIN; } else { CERR( ( ANSWER ) << " != " << guchoku ); QUIT; } #else #define SET_ASSERT( A , MIN , MAX ) cin >> A; ASSERT( A , MIN , MAX ) #define RETURN( ANSWER ) COUT( ( ANSWER ) ); goto END_MAIN #endif template inline T Absolute( const T& a ){ return a > 0 ? a : -a; } template inline T Residue( const T& a , const T& p ){ return a >= 0 ? a % p : p - 1 - ( ( - ( a + 1 ) ) % p ); } #define POWER( ANSWER , ARGUMENT , EXPONENT ) \ static_assert( ! is_same::value && ! is_same::value ); \ TYPE_OF( ARGUMENT ) ANSWER{ 1 }; \ { \ TYPE_OF( ARGUMENT ) ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT ); \ TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT ); \ while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){ \ if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){ \ ANSWER *= ARGUMENT_FOR_SQUARE_FOR_POWER; \ } \ ARGUMENT_FOR_SQUARE_FOR_POWER *= ARGUMENT_FOR_SQUARE_FOR_POWER; \ EXPONENT_FOR_SQUARE_FOR_POWER /= 2; \ } \ } \ #define POWER_MOD( ANSWER , ARGUMENT , EXPONENT , MODULO ) \ ll ANSWER{ 1 }; \ { \ ll ARGUMENT_FOR_SQUARE_FOR_POWER = ( ( MODULO ) + ( ( ARGUMENT ) % ( MODULO ) ) ) % ( MODULO ); \ TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT ); \ while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){ \ if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){ \ ANSWER = ( ANSWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % ( MODULO ); \ } \ ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT_FOR_SQUARE_FOR_POWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % ( MODULO ); \ EXPONENT_FOR_SQUARE_FOR_POWER /= 2; \ } \ } \ #define FACTORIAL_MOD( ANSWER , ANSWER_INV , INVERSE , MAX_INDEX , CONSTEXPR_LENGTH , MODULO ) \ static ll ANSWER[CONSTEXPR_LENGTH]; \ static ll ANSWER_INV[CONSTEXPR_LENGTH]; \ static ll INVERSE[CONSTEXPR_LENGTH]; \ { \ ll VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1; \ ANSWER[0] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL; \ FOREQ( i , 1 , MAX_INDEX ){ \ ANSWER[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= i ) %= ( MODULO ); \ } \ ANSWER_INV[0] = ANSWER_INV[1] = INVERSE[1] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1; \ FOREQ( i , 2 , MAX_INDEX ){ \ ANSWER_INV[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= INVERSE[i] = ( MODULO ) - ( ( ( ( MODULO ) / i ) * INVERSE[ ( MODULO ) % i ] ) % ( MODULO ) ) ) %= ( MODULO ); \ } \ } \ // 二分探索テンプレート // EXPRESSIONがANSWERの広義単調関数の時、EXPRESSION >= TARGETの整数解を格納。 #define BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , DESIRED_INEQUALITY , TARGET , INEQUALITY_FOR_CHECK , UPDATE_U , UPDATE_L , UPDATE_ANSWER ) \ static_assert( ! is_same::value && ! is_same::value ); \ ll ANSWER = MINIMUM; \ if( MINIMUM <= MAXIMUM ){ \ ll VARIABLE_FOR_BINARY_SEARCH_L = MINIMUM; \ ll VARIABLE_FOR_BINARY_SEARCH_U = MAXIMUM; \ ANSWER = ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2; \ ll VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH; \ while( VARIABLE_FOR_BINARY_SEARCH_L != VARIABLE_FOR_BINARY_SEARCH_U ){ \ VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( EXPRESSION ) - ( TARGET ); \ CERR( "二分探索中: " << VARIABLE_FOR_BINARY_SEARCH_L << "<=" << ANSWER << "<=" << VARIABLE_FOR_BINARY_SEARCH_U << ":" << EXPRESSION << "-" << TARGET << "=" << VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH ); \ if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH INEQUALITY_FOR_CHECK 0 ){ \ VARIABLE_FOR_BINARY_SEARCH_U = UPDATE_U; \ } else { \ VARIABLE_FOR_BINARY_SEARCH_L = UPDATE_L; \ } \ ANSWER = UPDATE_ANSWER; \ } \ CERR( "二分探索終了: " << VARIABLE_FOR_BINARY_SEARCH_L << "<=" << ANSWER << "<=" << VARIABLE_FOR_BINARY_SEARCH_U << ":" << EXPRESSION << ( EXPRESSION > TARGET ? ">" : EXPRESSION < TARGET ? "<" : "=" ) << TARGET ); \ CERR( ( EXPRESSION DESIRED_INEQUALITY TARGET ? "二分探索成功" : "二分探索失敗" ) ); \ assert( EXPRESSION DESIRED_INEQUALITY TARGET ); \ } else { \ CERR( "二分探索失敗: " << MINIMUM << ">" << MAXIMUM ); \ assert( MINIMUM <= MAXIMUM ); \ } \ // 単調増加の時にEXPRESSION >= TARGETの最小解を格納。 #define BS1( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET ) \ BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , TARGET , >= , ANSWER , ANSWER + 1 , ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \ // 単調増加の時にEXPRESSION <= TARGETの最大解を格納。 #define BS2( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET ) \ BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , TARGET , > , ANSWER - 1 , ANSWER , ( VARIABLE_FOR_BINARY_SEARCH_L + 1 + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \ // 単調減少の時にEXPRESSION >= TARGETの最大解を格納。 #define BS3( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET ) \ BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , TARGET , < , ANSWER - 1 , ANSWER , ( VARIABLE_FOR_BINARY_SEARCH_L + 1 + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \ // 単調減少の時にEXPRESSION <= TARGETの最小解を格納。 #define BS4( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET ) \ BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , TARGET , <= , ANSWER , ANSWER + 1 , ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \ // t以下の値が存在すればその最大値のiterator、存在しなければend()を返す。 template inline typename set::iterator MaximumLeq( set& S , const T& t ) { const auto end = S.end(); if( S.empty() ){ return end; } auto itr = S.upper_bound( t ); return itr == end ? S.find( *( S.rbegin() ) ) : itr == S.begin() ? end : --itr; } // t未満の値が存在すればその最大値のiterator、存在しなければend()を返す。 template inline typename set::iterator MaximumLt( set& S , const T& t ) { const auto end = S.end(); if( S.empty() ){ return end; } auto itr = S.lower_bound( t ); return itr == end ? S.find( *( S.rbegin() ) ) : itr == S.begin() ? end : --itr; } // t以上の値が存在すればその最小値のiterator、存在しなければend()を返す。 template inline typename set::iterator MinimumGeq( set& S , const T& t ) { return S.lower_bound( t ); } // tより大きい値が存在すればその最小値のiterator、存在しなければend()を返す。 template inline typename set::iterator MinimumGt( set& S , const T& t ) { return S.upper_bound( t ); } #define SFINAE_FOR_LOOP_DETECTION_BODY( DEFAULT ) enable_if_t >* DEFAULT // 写像f:T->Uとcast U->Tの合成のループ検出を行う。 // fとcastの合成の像の要素数がlength_max以下の場合にのみサポート。 // 反復合成O(loop_start+(n-loop_start)%loop_length) // 像の要素数取得O(1)(ただしループ検出前の時のみO(loop_start+loop_length)) // ループ始点取得O(1)(ただしループ検出前の時のみO(loop_start+loop_length)) // ループ長取得O(1)(ただしループ検出前の時のみO(loop_start+loop_length)) template class LoopDetectionBody { private: T m_init; map m_memory; vector m_memory_inv; protected: int m_value[length_max]; int m_length; int m_loop_start; int m_loop_length; public: template inline LoopDetectionBody( const T& init ); template T IteratedComposition( const INT& n ); // 像の要素数取得 inline const int& GetLength() noexcept; // ループ始点取得 inline const int& GetLoopStart() noexcept; // ループ長取得 inline const int& GetLoopLength() noexcept; private: inline void SetInit(); void SearchLoop(); virtual T e( const int& i ); virtual int e_inv( const T& t ); virtual void SetValue( const int& i ); }; template class LoopDetection : public LoopDetectionBody { private: int m_value_inv[length_max]; public: inline LoopDetection( const int& init ); private: inline int e( const int& i ); inline int e_inv( const int& t ); void SetValue( const int& i ); }; template class MemorisationLoopDetection : public LoopDetectionBody { public: inline MemorisationLoopDetection( const T& init ); }; template class EnumerationLoopDetection : public LoopDetectionBody { private: int m_value_inv[length_max]; public: inline EnumerationLoopDetection( const T& init ); private: inline T e( const int& i ); inline int e_inv( const T& t ); void SetValue( const int& i ); }; template template inline LoopDetectionBody::LoopDetectionBody( const T& init ) : m_init( init ) , m_memory() , m_memory_inv() , m_value() , m_length() , m_loop_start( -1 ) , m_loop_length( -1 ) {} template inline LoopDetection::LoopDetection( const int& init ) : LoopDetectionBody( init ) , m_value_inv() { for( int i = 0 ; i < length_max ; i++ ){ m_value_inv[i] = -1; } } template inline MemorisationLoopDetection::MemorisationLoopDetection( const T& init ) : LoopDetectionBody( init ) {} template inline EnumerationLoopDetection::EnumerationLoopDetection( const T& init ) : LoopDetectionBody( init ) , m_value_inv() { for( int i = 0 ; i < length_max ; i++ ){ m_value_inv[i] = -1; } } template template T LoopDetectionBody::IteratedComposition( const INT& n ) { if( m_length == 0 ){ SetInit(); } if( n < m_length ){ return e( m_value[n] ); } if( m_loop_start != -1 ){ return e( m_value[ m_loop_start + ( n - m_loop_start ) % m_loop_length ] ); } SetValue( e_inv( f( e( m_value[m_length - 1] ) ) ) ); return IteratedComposition( n ); } template inline const int& LoopDetectionBody::GetLength() noexcept { if( m_loop_length == -1 ){ SearchLoop(); } return m_length; } template inline const int& LoopDetectionBody::GetLoopStart() noexcept { if( m_loop_start == -1 ){ SearchLoop(); } return m_loop_start; } template inline const int& LoopDetectionBody::GetLoopLength() noexcept { if( m_loop_length == -1 ){ SearchLoop(); } return m_loop_length; } template inline void LoopDetectionBody::SetInit() { assert( m_length == 0 ); SetValue( e_inv( m_init ) ); } template void LoopDetectionBody::SearchLoop() { assert( m_loop_length == -1 ); int n = 0; while( m_loop_length == -1 ){ IteratedComposition( n++ ); } return; } template T LoopDetectionBody::e( const int& i ) { assert( i < m_length ); return m_memory_inv[i]; } template inline int LoopDetection::e( const int& i ) { return i; } template inline T EnumerationLoopDetection::e( const int& i ) { return enum_T( i ); } template int LoopDetectionBody::e_inv( const T& t ) { if( m_memory.count( t ) == 0 ){ assert( m_length < length_max ); m_value[m_length] = m_length; m_memory_inv.push_back( t ); return m_memory[t] = m_length++; } m_loop_length = m_length - ( m_loop_start = m_memory[t] ); return m_loop_start; } template inline int LoopDetection::e_inv( const int& t ) { return t; } template inline int EnumerationLoopDetection::e_inv( const T& t ) { return enum_T_inv( t ); } template void LoopDetectionBody::SetValue( const int& i ) {} template void LoopDetection::SetValue( const int& i ) { using base = LoopDetectionBody; int& m_value_inv_i = m_value_inv[i]; if( m_value_inv_i != -1 ){ base::m_loop_length = base::m_length - ( base::m_loop_start = m_value_inv_i ); } else { base::m_value[base::m_length] = i; m_value_inv_i = base::m_length++; } return; } template void EnumerationLoopDetection::SetValue( const int& i ) { using base = LoopDetectionBody; int& m_value_inv_i = m_value_inv[i]; if( m_value_inv_i != -1 ){ base::m_loop_length = base::m_length - ( base::m_loop_start = m_value_inv_i ); } else { base::m_value[base::m_length] = i; m_value_inv_i = base::m_length++; } return; } DEXPR( int , bound_HW , 1000000 , 100 ); // 0が6個 int H , W , H_minus , W_minus , HW; inline pair EnumHW( const int& v ) { return { v / W , v % W }; } inline int EnumHW_inv( const int& h , const int& w ) { return h * W + w; } using type = tuple; type f( const type& t ) { auto [i,j,D,R] = t; if( D ){ if( i + 1 < H ){ i++; } else { D = !D; } } else { if( i > 0 ){ i--; } else { D = !D; } } if( R ){ if( j + 1 < W ){ j++; } else { R = !R; } } else { if( j > 0 ){ j--; } else { R = !R; } } return { i , j ,D , R }; } type enum_type( const int& t ){ auto [i,j] = EnumHW( t / 4 ); return { i , j , t % 4 / 2 , t % 2 }; } int enum_type_inv( const type& t ){ auto&& [i,j,D,R] = t; return EnumHW_inv( i , j ) * 4 + D * 2 + R; } int main() { UNTIE; // LIBRARY_SEARCH; TEST_CASE_NUM( 1 ); START_MAIN; cin >> H >> W; H_minus = H - 1; W_minus = W - 1; HW = H * W; assert( HW <= bound_HW ); CIN( ll , K ); EnumerationLoopDetection ld{ { 0 , 0 , true , true } }; const int& loop_start = ld.GetLoopStart(); const int& loop_length = ld.GetLoopLength(); bool b[H][W] = {}; type t = { 0 , 0 , true , true }; if( K < loop_start ){ REPEAT( K ){ auto& [i,j,D,R] = t; b[i][j] = !b[i][j]; t = f( t ); } } else { REPEAT( loop_start ){ auto& [i,j,D,R] = t; b[i][j] = !b[i][j]; t = f( t ); } K -= loop_start; if( ( K / loop_length ) % 2 == 1 ){ REPEAT( loop_length ){ auto& [i,j,D,R] = t; b[i][j] = !b[i][j]; t = f( t ); } } K %= loop_length; REPEAT( K ){ auto& [i,j,D,R] = t; b[i][j] = !b[i][j]; t = f( t ); } } FOR( i , 0 , H ){ FOR( j , 0 , W ){ cout << ( b[i][j] ? "#" : "." ); } cout << "\n"; } FINISH_MAIN; QUIT; }