結果
| 問題 | 
                            No.2064 Smallest Sequence on Grid
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kokatsu
                         | 
                    
| 提出日時 | 2022-11-29 01:36:40 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2,467 ms / 3,000 ms | 
| コード長 | 1,402 bytes | 
| コンパイル時間 | 2,502 ms | 
| コンパイル使用メモリ | 209,404 KB | 
| 実行使用メモリ | 55,080 KB | 
| 最終ジャッジ日時 | 2024-06-22 16:54:24 | 
| 合計ジャッジ時間 | 22,406 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 29 | 
ソースコード
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]);
    string res = S[0][0].to!string;
    Grid[] list;
    list ~= Grid(0, 0);
    foreach (i; 2 .. H+W) {
        bool[Grid] nxt;
        dchar mn = 'z';
        foreach (l; list) {
            if (l.x + 1 < H) {
                if (S[l.x+1][l.y] < mn) {
                    nxt.clear;
                    nxt[Grid(l.x+1, l.y)] = true;
                    mn = S[l.x+1][l.y];
                }
                else if (S[l.x+1][l.y] == mn) {
                    nxt[Grid(l.x+1, l.y)] = true;
                }
            }
            if (l.y + 1 < W) {
                if (S[l.x][l.y+1] < mn) {
                    nxt.clear;
                    nxt[Grid(l.x, l.y+1)] = true;
                    mn = S[l.x][l.y+1];
                }
                else if (S[l.x][l.y+1] == mn) {
                    nxt[Grid(l.x, l.y+1)] = true;
                }
            }
        }
        res ~= mn;
        list = nxt.keys;
    }
    res.writeln;
}
            
            
            
        
            
kokatsu