結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー | 👑 p-adic |
提出日時 | 2022-09-02 22:05:21 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,438 bytes |
コンパイル時間 | 2,079 ms |
コンパイル使用メモリ | 202,732 KB |
実行使用メモリ | 13,768 KB |
最終ジャッジ日時 | 2024-04-27 21:39:29 |
合計ジャッジ時間 | 7,752 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,768 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | TLE | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; #define CIN( LL , A ) LL A; cin >> A #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( int VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; return 0 constexpr const ll A = 3000; void Solve( string ( &S )[A] , ll& i , ll& j , string& s , const ll& H_m , const ll& W_m ); int main(){ CIN( ll , H ); CIN( ll , W ); string S[A]; FOR( i , 0 , H ){ cin >> S[i]; } string s{}; ll i = 0; ll j = 0; ll H_m = H - 1; ll W_m = W - 1; Solve( S , i , j , s , H_m , W_m ); s += S[i].substr( j , 1 ); RETURN( s ); } void Solve( string ( &S )[A] , ll& i , ll& j , string& s , const ll& H_m , const ll& W_m ) { while( i != H_m || j != W_m ){ s += S[i].substr( j , 1 ); if( i == H_m ){ j++; } else if( j == W_m ){ i++; } else { auto ci = S[i+1].substr( j , 1 ).c_str()[0]; auto cj = S[i].substr( j+1 , 1 ).c_str()[0]; if( ci < cj ){ i++; } else if( cj < ci ){ j++; } else { string si{}; string sj{}; ll i_copy_i = i + 1; ll j_copy_i = j; ll i_copy_j = i; ll j_copy_j = j + 1; Solve( S , i_copy_i , j_copy_i , si , H_m , W_m ); Solve( S , i_copy_j , j_copy_j , sj , H_m , W_m ); if( si < sj ){ s += si; i = i_copy_i; j = j_copy_i; } else { s += sj; i = i_copy_j; j = j_copy_j; } } } } return; }