結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 268 ms
14,976 KB
testcase_21 AC 278 ms
15,104 KB
testcase_22 AC 243 ms
14,976 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 311 ms
14,976 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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{};
  vector<ll> j_prev{};
  i_prev.push_back( 0 );
  j_prev.push_back( 0 );
  cout << S[0].substr( 0 , 1 );
  ll H_m = H - 1;
  ll W_m = W - 1;
  ll L = H_m + W_m;
  FOR( l , 0 , L ){
    ll size = i_prev.size();
    string s_min = "z";
    bool b[A] = {};
    FOR( k , 0 , size ){
      ll& i_prev_k = i_prev[k];
      b[i_prev_k] = i_prev_k <= H_m && ( l + 1 - i_prev_k ) <= W_m;
      b[i_prev_k + 1] = i_prev_k + 1 <= H_m && ( l - i_prev_k ) <= W_m;
    }
    FOR( i_curr , 0 , H_m ){
      if( b[i_curr] ){
	ll j_curr = l + 1 - i_curr;
	string s_curr = S[i_curr].substr( j_curr , 1 );
	if( s_min == s_curr ){
	  i.push_back( i_curr );
	  j.push_back( j_curr );
	} else if( s_min > s_curr ){
	  s_min = s_curr;
	  i.clear();
	  j.clear();
	  i.push_back( i_curr );
	  j.push_back( j_curr );
	}
      }
    }
    cout << s_min;
    i_prev = i;
    j_prev = j;
    i.clear();
    j.clear();
  }
  RETURN( "" );
}
0