結果

問題 No.2064 Smallest Sequence on Grid
ユーザー pointNpointN
提出日時 2022-09-03 00:17:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,581 ms / 3,000 ms
コード長 1,360 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 146,224 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-04-28 00:02:53
合計ジャッジ時間 15,185 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 188 ms
14,848 KB
testcase_18 AC 186 ms
14,848 KB
testcase_19 AC 185 ms
14,976 KB
testcase_20 AC 1,193 ms
15,104 KB
testcase_21 AC 1,289 ms
15,104 KB
testcase_22 AC 897 ms
15,104 KB
testcase_23 AC 878 ms
15,104 KB
testcase_24 AC 871 ms
14,976 KB
testcase_25 AC 869 ms
15,104 KB
testcase_26 AC 1,581 ms
15,104 KB
testcase_27 AC 1,573 ms
15,104 KB
testcase_28 AC 185 ms
14,848 KB
testcase_29 AC 1,297 ms
15,104 KB
testcase_30 AC 169 ms
14,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#include <sstream>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int H,W; cin >> H >> W;
  vector<string> A(H); rep(i,H) cin >> A[i];
  string ans = "";
  ans += A[0][0];
  set<pair<int,int>> pos;
  pos.insert({0,0});
  rep(i,H+W-2){
    map<char,set<pair<int,int>>> mp;
    for(auto p:pos){
      int y=p.first,x=p.second;
      if(y+1<H){
        mp[A[y+1][x]].insert({y+1,x});
      }
      if(x+1<W){
        mp[A[y][x+1]].insert({y,x+1});
      }
    }
    char ad = (*mp.begin()).first;
    ans += ad;
    pos = (*mp.begin()).second;
  }
  cout << ans << endl;
  return 0;
}
0