結果

問題 No.2639 Longest Increasing Walk
ユーザー tobisatistobisatis
提出日時 2024-02-19 21:32:46
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 574 ms / 2,000 ms
コード長 2,563 bytes
コンパイル時間 5,964 ms
コンパイル使用メモリ 158,476 KB
実行使用メモリ 179,972 KB
最終ジャッジ日時 2024-02-19 21:33:01
合計ジャッジ時間 13,388 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
32,164 KB
testcase_01 AC 51 ms
32,036 KB
testcase_02 AC 54 ms
32,164 KB
testcase_03 AC 50 ms
32,036 KB
testcase_04 AC 110 ms
61,220 KB
testcase_05 AC 574 ms
81,804 KB
testcase_06 AC 503 ms
81,704 KB
testcase_07 AC 553 ms
81,888 KB
testcase_08 AC 475 ms
81,756 KB
testcase_09 AC 520 ms
81,824 KB
testcase_10 AC 338 ms
66,748 KB
testcase_11 AC 292 ms
64,644 KB
testcase_12 AC 98 ms
38,180 KB
testcase_13 AC 337 ms
69,088 KB
testcase_14 AC 246 ms
54,532 KB
testcase_15 AC 57 ms
32,164 KB
testcase_16 AC 67 ms
32,932 KB
testcase_17 AC 80 ms
44,068 KB
testcase_18 AC 248 ms
57,704 KB
testcase_19 AC 113 ms
40,100 KB
testcase_20 AC 169 ms
46,960 KB
testcase_21 AC 287 ms
64,500 KB
testcase_22 AC 167 ms
45,892 KB
testcase_23 AC 57 ms
32,420 KB
testcase_24 AC 55 ms
32,292 KB
testcase_25 AC 58 ms
32,932 KB
testcase_26 AC 56 ms
32,292 KB
testcase_27 AC 61 ms
33,060 KB
testcase_28 AC 53 ms
32,164 KB
testcase_29 AC 54 ms
32,164 KB
testcase_30 AC 53 ms
32,164 KB
testcase_31 AC 59 ms
32,164 KB
testcase_32 AC 55 ms
179,972 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (82 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

namespace AtCoder;

#nullable enable

using System.Numerics;

static class Extensions
{
    public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
}

class AtCoder
{
    object? Solve()
    {
        var h = Int();
        var w = Int();
        var a = new int[h + 2, w + 2];
        var d = new Dictionary<int, List<(int, int)>>();
        for (var i = 1; i <= h; i++) for (var j = 1; j <= w; j++)
        {
            var x = Int();
            a[i, j] = x;
            if (d.TryGetValue(x, out var ll)) ll.Add((i, j));
            else d[x] = new List<(int, int)>(){ (i, j) };
        }
        var kz = new List<int>(d.Keys);
        kz.Sort();
        kz.Reverse();
        var ans = 0;
        var g = new int[h + 2, w + 2];
        var moves = new[]{ (-1, 0), (0, -1), (0, 1), (1, 0) };
        foreach (var k in kz)
        {
            var l = d[k];
            foreach (var (i, j) in l)
            {
                var y = 0;
                foreach (var (di, dj) in moves)
                {
                    var ni = i + di;
                    var nj = j + dj;
                    if (a[ni, nj] != a[i, j]) y = Math.Max(y, g[ni, nj] + 1);
                }
                g[i, j] = y;
                ans = Math.Max(ans, y);
            }
        }
        return ans;
    }

    public static void Main() => new AtCoder().Run();
    public void Run()
    {
        var res = Solve();
        if (res != null)
        {
            if (res is bool yes) res = yes ? "Yes" : "No";
            sw.WriteLine(res);
        }
        sw.Flush();
    }

    string[] input = Array.Empty<string>();
    int iter = 0;
    readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false };

    #pragma warning disable IDE0051
    string String()
    {
        while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0);
        return input[iter++];
    }
    T Input<T>() where T : IParsable<T> => T.Parse(String(), null);
    int Int() => Input<int>();
    void Out(object? x, string? separator = null)
    {
        separator ??= Environment.NewLine;
        if (x is System.Collections.IEnumerable obj and not string)
        {
            var firstLine = true;
            foreach (var item in obj)
            {
                if (!firstLine) sw.Write(separator);
                firstLine = false;
                sw.Write(item);
            }
        }
        else sw.Write(x);
        sw.WriteLine();
    }
    #pragma warning restore IDE0051
}
0