結果

問題 No.2064 Smallest Sequence on Grid
ユーザー kokatsukokatsu
提出日時 2022-11-29 01:25:09
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,502 bytes
コンパイル時間 6,052 ms
コンパイル使用メモリ 204,152 KB
実行使用メモリ 107,072 KB
最終ジャッジ日時 2023-09-04 19:08:49
合計ジャッジ時間 12,110 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 306 ms
62,616 KB
testcase_18 AC 309 ms
61,660 KB
testcase_19 AC 306 ms
61,648 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

struct Grid {
    int x, y;

    int opCmp(Grid that) {
        if (this.x != that.x) {
            if (this.x > that.x) return 1;
            else return -1;
        }
        if (this.y != that.y) {
            if (this.y > that.y) return 1;
            else return -1;
        }
        return 0;
    }
}

void main() {
    int H, W;
    readf("%d %d\n", H, W);

    auto S = new string[](H);
    foreach (i; 0 .. H) readf("%s\n", S[i]);

    auto mn = new string[](H+W);
    mn[1] = S[0][0].to!string;
    foreach (i; 2 .. H+W) mn[i] = "{";

    Grid[] list;
    list ~= Grid(0, 0);
    foreach (i; 2 .. H+W) {
        bool[Grid] nxt;
        foreach (l; list) {
            if (l.x + 1 < H) {
                string T = mn[i-1] ~ S[l.x+1][l.y];
                if (T < mn[i]) {
                    nxt.clear;
                    nxt[Grid(l.x+1, l.y)] = true;
                    mn[i] = T;
                }
                else if (T == mn[i]) {
                    nxt[Grid(l.x+1, l.y)] = true;
                }
            }

            if (l.y + 1 < W) {
                string T = mn[i-1] ~ S[l.x][l.y+1];
                if (T < mn[i]) {
                    nxt.clear;
                    nxt[Grid(l.x, l.y+1)] = true;
                    mn[i] = T;
                }
                else if (T == mn[i]) {
                    nxt[Grid(l.x, l.y+1)] = true;
                }
            }
        }

        list = nxt.keys;
    }

    string res = mn.back;
    res.writeln;
}
0