結果

問題 No.2064 Smallest Sequence on Grid
ユーザー Nzt3Nzt3
提出日時 2022-09-02 21:40:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 616 ms / 3,000 ms
コード長 950 bytes
コンパイル時間 2,575 ms
コンパイル使用メモリ 220,112 KB
実行使用メモリ 13,764 KB
最終ジャッジ日時 2023-08-10 03:37:02
合計ジャッジ時間 9,504 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 98 ms
13,656 KB
testcase_18 AC 98 ms
13,496 KB
testcase_19 AC 100 ms
13,624 KB
testcase_20 AC 466 ms
13,668 KB
testcase_21 AC 497 ms
13,684 KB
testcase_22 AC 363 ms
13,580 KB
testcase_23 AC 364 ms
13,620 KB
testcase_24 AC 355 ms
13,620 KB
testcase_25 AC 357 ms
13,616 KB
testcase_26 AC 610 ms
13,764 KB
testcase_27 AC 616 ms
13,704 KB
testcase_28 AC 99 ms
13,480 KB
testcase_29 AC 516 ms
12,184 KB
testcase_30 AC 92 ms
12,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H,W;
  cin>>H>>W;
  vector<vector<char>>A(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++)cin>>A[i][j];
  }
  queue<array<int,2>>bfs;
  bfs.push({0,0});
  string ans="";
  ans+=A[0][0];
  vector<vector<bool>>vst(H,vector<bool>(W));
  while(bfs.size()){
    int s=bfs.size();
    vector<pair<char,array<int,2>>>v;
    for(int i=0;i<s;i++){
      int x=bfs.front()[0],y=bfs.front()[1];
      bfs.pop();
      if(x+1<H&&!vst[x+1][y]){
        v.push_back({A[x+1][y],{x+1,y}});
        vst[x+1][y]=true;
      }
      if(y+1<W&&!vst[x][y+1]){
        v.push_back({A[x][y+1],{x,y+1}});
        vst[x][y+1]=true;
      }
    }
    sort(v.begin(),v.end());
    if(v.empty())break;
    char c=v[0].first;
    ans+=c;
    for(auto i:v){
      if(i.first==c){
        bfs.push(i.second);
      }
    }
  }
  cout<<ans<<'\n';
}
0