結果

問題 No.2064 Smallest Sequence on Grid
ユーザー umezoumezo
提出日時 2022-09-02 23:01:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 942 bytes
コンパイル時間 1,919 ms
コンパイル使用メモリ 213,388 KB
実行使用メモリ 264,388 KB
最終ジャッジ日時 2024-04-27 22:40:32
合計ジャッジ時間 7,605 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
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 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 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 #

#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 pci=pair<char,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];
  
  string ans;
  ans+=S[0][0];
  queue<pair<int,int>> que;
  que.push({0,0});
  rep(k,h+w-2){
    priority_queue<pci, vector<pci>, greater<pci>> pq;
    while(que.size()){
      auto c=que.front(); que.pop();
      int i=c.first,j=c.second;
      if(i+1<h) pq.push({S[i+1][j],{i+1,j}});
      if(j+1<w) pq.push({S[i][j+1],{i,j+1}});
    }
    auto a=pq.top(); pq.pop();
    ans+=a.first;
    que.push({a.second.first,a.second.second});
    while(pq.size() && pq.top().first==a.first){
      auto b=pq.top(); pq.pop();
      que.push({b.second.first,b.second.second});
    } 
  }
  cout<<ans<<endl;
  
  return 0;
}
0