結果
| 問題 | 
                            No.2064 Smallest Sequence on Grid
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-09-02 21:38:55 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                MLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 824 bytes | 
| コンパイル時間 | 2,661 ms | 
| コンパイル使用メモリ | 210,852 KB | 
| 最終ジャッジ日時 | 2025-02-07 00:57:20 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 7 TLE * 9 MLE * 13 | 
ソースコード
#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';
}