結果

問題 No.2064 Smallest Sequence on Grid
ユーザー Nzt3Nzt3
提出日時 2022-09-02 21:38:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 824 bytes
コンパイル時間 2,825 ms
コンパイル使用メモリ 217,500 KB
実行使用メモリ 503,724 KB
最終ジャッジ日時 2024-04-27 21:07:03
合計ジャッジ時間 8,211 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 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 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 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
  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){
        v.push_back({A[x+1][y],{x+1,y}});
      }
      if(y+1<W){
        v.push_back({A[x][y+1],{x,y+1}});
      }
    }
    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