結果

問題 No.2463 ストレートフラッシュ
ユーザー 👑 kakel-sankakel-san
提出日時 2023-09-14 23:16:28
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 1,392 bytes
コンパイル時間 1,051 ms
コンパイル使用メモリ 68,232 KB
実行使用メモリ 40,468 KB
最終ジャッジ日時 2023-09-14 23:16:39
合計ジャッジ時間 9,131 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
21,876 KB
testcase_01 AC 63 ms
21,932 KB
testcase_02 AC 63 ms
23,812 KB
testcase_03 AC 65 ms
21,972 KB
testcase_04 AC 64 ms
21,932 KB
testcase_05 AC 66 ms
21,812 KB
testcase_06 AC 64 ms
23,824 KB
testcase_07 AC 67 ms
21,848 KB
testcase_08 AC 65 ms
21,956 KB
testcase_09 AC 66 ms
21,832 KB
testcase_10 AC 64 ms
22,020 KB
testcase_11 AC 64 ms
21,876 KB
testcase_12 AC 65 ms
23,728 KB
testcase_13 AC 265 ms
36,200 KB
testcase_14 AC 297 ms
37,536 KB
testcase_15 AC 300 ms
35,172 KB
testcase_16 AC 306 ms
37,784 KB
testcase_17 AC 346 ms
39,488 KB
testcase_18 AC 397 ms
38,392 KB
testcase_19 AC 366 ms
38,312 KB
testcase_20 AC 371 ms
38,480 KB
testcase_21 AC 363 ms
40,468 KB
testcase_22 AC 345 ms
38,368 KB
testcase_23 AC 345 ms
38,588 KB
testcase_24 AC 361 ms
40,432 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 int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var map = NArr(n * m);
        var pos = new int[n, m];
        for (var i = 0; i < map.Length; ++i) pos[map[i][0] - 1, map[i][1] - 1] = i + 1;
        var ans = int.MaxValue;
        for (var i = 0; i + 4 <= n; ++i) for (var j = 0; j < m; ++j)
        {
            var p = new int[] { pos[i, j], pos[(i + 1) % n, j], pos[(i + 2) % n, j], pos[(i + 3) % n, j], pos[(i + 4) % n, j] };
            Array.Sort(p);
            ans = Math.Min(ans, Draw(p));
        }
        WriteLine(ans - 1);
    }
    static int Draw(int[] p)
    {
        var i = 0;
        var ans = 0;
        var draw = 0;
        while (i < p.Length)
        {
            var ntime = (p[i] - draw + p.Length - i - 1) / (p.Length - i);
            ans += ntime;
            draw += ntime * (p.Length - i);
            while(i < p.Length && p[i] <= draw) ++i;
        }
        return ans;
    }
}
0