結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 p-adicp-adic
提出日時 2022-09-03 02:34:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 324 ms / 3,000 ms
コード長 1,255 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 206,224 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-04-28 02:09:43
合計ジャッジ時間 7,851 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 204 ms
14,848 KB
testcase_18 AC 204 ms
14,848 KB
testcase_19 AC 188 ms
14,848 KB
testcase_20 AC 280 ms
14,976 KB
testcase_21 AC 289 ms
14,976 KB
testcase_22 AC 246 ms
14,976 KB
testcase_23 AC 267 ms
14,976 KB
testcase_24 AC 259 ms
14,976 KB
testcase_25 AC 253 ms
14,976 KB
testcase_26 AC 317 ms
14,976 KB
testcase_27 AC 324 ms
15,104 KB
testcase_28 AC 190 ms
14,848 KB
testcase_29 AC 269 ms
14,976 KB
testcase_30 AC 169 ms
14,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  CIN( ll , H );
  CIN( ll , W );
  string S[A];
  FOR( i , 0 , H ){
    cin >> S[i];
  }
  vector<ll> i{};
  vector<ll> j{};
  vector<ll> i_prev{};
  i_prev.push_back( 0 );
  cout << S[0].substr( 0 , 1 );
  ll H_m = H - 1;
  ll W_m = W - 1;
  ll L = H + W_m;
  FOR( sum , 1 , L ){
    ll size = i_prev.size();
    bool b[A] = {};
    FOR( k , 0 , size ){
      ll& i_prev_k = i_prev[k];
      ll i_prev_k_p = i_prev_k + 1;
      b[i_prev_k] = i_prev_k <= H_m && sum - i_prev_k <= W_m;
      b[i_prev_k_p] = i_prev_k_p <= H_m && sum - i_prev_k_p <= W_m;
    }
    string s_min = "z";
    FOR( i_curr , 0 , H ){
      if( b[i_curr] ){
	ll j_curr = sum - i_curr;
	string s_curr = S[i_curr].substr( j_curr , 1 );
	if( s_min == s_curr ){
	  i.push_back( i_curr );
	} else if( s_min > s_curr ){
	  s_min = s_curr;
	  i.clear();
	  i.push_back( i_curr );
	}
      }
    }
    cout << s_min;
    i_prev = i;
    i.clear();
  }
  RETURN( "" );
}
0