結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 kakel-sankakel-san
提出日時 2022-09-04 00:15:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 964 ms / 3,000 ms
コード長 1,702 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 70,372 KB
実行使用メモリ 73,988 KB
最終ジャッジ日時 2023-08-11 03:27:16
合計ジャッジ時間 11,847 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
21,916 KB
testcase_01 AC 63 ms
21,984 KB
testcase_02 AC 63 ms
21,896 KB
testcase_03 AC 64 ms
21,928 KB
testcase_04 AC 65 ms
21,988 KB
testcase_05 AC 63 ms
21,988 KB
testcase_06 AC 65 ms
19,936 KB
testcase_07 AC 64 ms
21,940 KB
testcase_08 AC 67 ms
24,000 KB
testcase_09 AC 66 ms
21,976 KB
testcase_10 AC 66 ms
21,872 KB
testcase_11 AC 66 ms
21,868 KB
testcase_12 AC 65 ms
21,868 KB
testcase_13 AC 66 ms
21,820 KB
testcase_14 AC 66 ms
21,864 KB
testcase_15 AC 66 ms
21,984 KB
testcase_16 AC 66 ms
23,976 KB
testcase_17 AC 146 ms
47,992 KB
testcase_18 AC 148 ms
49,940 KB
testcase_19 AC 150 ms
47,984 KB
testcase_20 AC 728 ms
73,988 KB
testcase_21 AC 774 ms
71,992 KB
testcase_22 AC 541 ms
70,208 KB
testcase_23 AC 547 ms
71,860 KB
testcase_24 AC 544 ms
73,980 KB
testcase_25 AC 538 ms
71,948 KB
testcase_26 AC 956 ms
71,896 KB
testcase_27 AC 964 ms
71,972 KB
testcase_28 AC 144 ms
50,048 KB
testcase_29 AC 781 ms
64,360 KB
testcase_30 AC 142 ms
48,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static string[] SList(int n) => Enumerable.Repeat(0, n).Select(_ => ReadLine()).ToArray();
    static void Main()
    {
        var c = NList;
        var (h, w) = (c[0], c[1]);
        var s = SList(h);
        WriteLine(Small(h, w, s));
    }
    static string Small(int h, int w, string[] s)
    {
        var res = new List<char>();
        res.Add(s[0][0]);
        var q = new List<(int x, int y)>();
        q.Add((0, 0));
        var prevmin = s[0][0];
        for (var t = 0; t < h + w - 2; ++t)
        {
            var next = new List<(int x, int y)>();
            var min = '{';
            foreach (var pos in q)
            {
                if (pos.x + 1 < h) min = (char)Math.Min(min, s[pos.x + 1][pos.y]);
                if (pos.y + 1 < w) min = (char)Math.Min(min, s[pos.x][pos.y + 1]);
            }
            foreach (var pos in q)
            {
                if (pos.y + 1 < w && s[pos.x][pos.y + 1] == min)
                {
                    if (next.Count == 0 || next[next.Count - 1].x != pos.x)
                    {
                        next.Add((pos.x, pos.y + 1));
                    }
                }
                if (pos.x + 1 < h && s[pos.x + 1][pos.y] == min)
                {
                    next.Add((pos.x + 1, pos.y));
                }
            }
            res.Add(min);
            q = next;
        }
        return (string.Concat(res));
    }
}
0