結果

問題 No.2064 Smallest Sequence on Grid
コンテスト
ユーザー kokatsu
提出日時 2022-11-29 01:13:36
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
TLE  
実行時間 -
コード長 1,442 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,195 ms
コンパイル使用メモリ 196,672 KB
実行使用メモリ 122,416 KB
最終ジャッジ日時 2026-03-06 22:24:35
合計ジャッジ時間 41,969 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20 TLE * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import std;

struct Grid {
    int x, y;

    int opCmp(Grid that) {
        if (this.x != that.x) {
            if (this.x > this.x) return 1;
            else return -1;
        }
        if (this.y != that.y) {
            if (this.y > this.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) {
        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 = [Grid(l.x+1, l.y)];
                    mn[i] = T;
                }
                else if (T == mn[i]) {
                    nxt ~= Grid(l.x+1, l.y);
                }
            }

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

        nxt.sort;
        list = nxt.uniq.array;
    }

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