結果

問題 No.2064 Smallest Sequence on Grid
ユーザー tnakao0123tnakao0123
提出日時 2022-09-04 02:49:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 162 ms / 3,000 ms
コード長 974 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 42,812 KB
実行使用メモリ 20,736 KB
最終ジャッジ日時 2024-04-28 22:24:33
合計ジャッジ時間 5,328 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 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 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 82 ms
20,672 KB
testcase_18 AC 87 ms
20,548 KB
testcase_19 AC 83 ms
20,548 KB
testcase_20 AC 162 ms
20,676 KB
testcase_21 AC 152 ms
20,608 KB
testcase_22 AC 135 ms
20,608 KB
testcase_23 AC 84 ms
20,728 KB
testcase_24 AC 84 ms
20,736 KB
testcase_25 AC 84 ms
20,600 KB
testcase_26 AC 96 ms
20,732 KB
testcase_27 AC 96 ms
20,480 KB
testcase_28 AC 72 ms
20,604 KB
testcase_29 AC 81 ms
20,480 KB
testcase_30 AC 74 ms
19,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2064.cc:  No.2064 Smallest Sequence on Grid - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_H = 3000;
const int MAX_W = 3000;
const int MAX_L = MAX_H + MAX_W - 1;

/* typedef */

/* global variables */

char fs[MAX_H][MAX_W + 4], t[MAX_L + 4];
bool used[MAX_H][MAX_W];

/* subroutines */

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) scanf("%s", fs[i]);

  int l = h + w - 1;
  used[0][0] = true;

  for (int k = 0; k < l; k++) {
    int i0 = min(k, h - 1), j0 = k - i0;
    char minc = 'z' + 1;
    for (int i = i0, j = j0; i >= 0 && j < w; i--, j++)
      if (used[i][j]) minc = min(minc, fs[i][j]);
    t[k] = minc;

    for (int i = i0, j = j0; i >= 0 && j < w; i--, j++)
      if (used[i][j] && fs[i][j] == minc) {
	if (i + 1 < h) used[i + 1][j] = true;
	if (j + 1 < w) used[i][j + 1] = true;
      }
  }

  puts(t);
  return 0;
}
0