結果

問題 No.2064 Smallest Sequence on Grid
ユーザー umezoumezo
提出日時 2022-09-03 19:44:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,194 ms / 3,000 ms
コード長 1,052 bytes
コンパイル時間 2,281 ms
コンパイル使用メモリ 214,084 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-04-28 16:57:03
合計ジャッジ時間 20,095 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 182 ms
13,056 KB
testcase_18 AC 180 ms
13,056 KB
testcase_19 AC 180 ms
13,056 KB
testcase_20 AC 1,747 ms
13,568 KB
testcase_21 AC 1,851 ms
13,440 KB
testcase_22 AC 1,391 ms
13,312 KB
testcase_23 AC 1,177 ms
13,440 KB
testcase_24 AC 1,186 ms
13,440 KB
testcase_25 AC 1,187 ms
13,312 KB
testcase_26 AC 2,192 ms
13,568 KB
testcase_27 AC 2,194 ms
13,440 KB
testcase_28 AC 180 ms
13,056 KB
testcase_29 AC 1,828 ms
11,776 KB
testcase_30 AC 260 ms
12,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

using pii=pair<int,int>;

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int h,w;
  cin>>h>>w;
  vector<string> S(h);
  rep(i,h) cin>>S[i];
  
  vector<char> ans(h+w-1);
  ans[0]=S[0][0];
  set<pii> se;
  se.insert({0,0});
  for(int k=1;k<h+w-1;k++){
    char tmp='|';
    rep(i,h){
      int j=k-i;
      if(j<0 || j>=w) continue;
      bool b=false;
      if(i>0 && se.count({i-1,j})) b=true;
      if(j>0 && se.count({i,j-1})) b=true;
      if(b==false) continue;
      tmp=min(tmp,S[i][j]);
    }
    ans[k]=tmp;
    set<pii> se2;
    rep(i,h){
      int j=k-i;
      if(j<0 || j>=w) continue;
      if(S[i][j]!=tmp) continue;
      bool b=false;
      if(i>0 && se.count({i-1,j})) b=true;
      if(j>0 && se.count({i,j-1})) b=true;
      if(b==false) continue;
      se2.insert({i,j});
    }
    swap(se,se2);
  }
  rep(i,h+w-1) cout<<ans[i];
  cout<<endl;
  
  return 0;
}
0