結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 kakel-sankakel-san
提出日時 2022-09-04 00:09:29
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,610 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 115,152 KB
実行使用メモリ 55,916 KB
最終ジャッジ日時 2024-04-28 20:24:35
合計ジャッジ時間 5,323 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
23,484 KB
testcase_01 AC 34 ms
25,644 KB
testcase_02 AC 32 ms
25,220 KB
testcase_03 AC 33 ms
27,648 KB
testcase_04 AC 34 ms
25,476 KB
testcase_05 AC 33 ms
27,392 KB
testcase_06 AC 34 ms
27,524 KB
testcase_07 AC 33 ms
27,524 KB
testcase_08 AC 33 ms
25,736 KB
testcase_09 AC 34 ms
25,604 KB
testcase_10 AC 33 ms
23,472 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 113 ms
51,316 KB
testcase_27 WA -
testcase_28 AC 115 ms
51,188 KB
testcase_29 AC 100 ms
44,916 KB
testcase_30 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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) continue;
                    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