結果

問題 No.2157 崖
ユーザー 👑 kakel-sankakel-san
提出日時 2023-09-05 22:28:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 3,895 ms / 6,000 ms
コード長 1,985 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 61,668 KB
実行使用メモリ 56,604 KB
最終ジャッジ日時 2023-09-05 22:28:35
合計ジャッジ時間 26,843 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,688 KB
testcase_01 AC 63 ms
19,712 KB
testcase_02 AC 65 ms
21,744 KB
testcase_03 AC 65 ms
21,784 KB
testcase_04 AC 64 ms
21,824 KB
testcase_05 AC 66 ms
21,828 KB
testcase_06 AC 65 ms
21,844 KB
testcase_07 AC 66 ms
23,708 KB
testcase_08 AC 66 ms
19,804 KB
testcase_09 AC 67 ms
23,824 KB
testcase_10 AC 63 ms
21,696 KB
testcase_11 AC 64 ms
21,840 KB
testcase_12 AC 65 ms
21,908 KB
testcase_13 AC 2,653 ms
52,452 KB
testcase_14 AC 1,299 ms
54,824 KB
testcase_15 AC 3,895 ms
55,788 KB
testcase_16 AC 3,805 ms
53,312 KB
testcase_17 AC 1,108 ms
54,072 KB
testcase_18 AC 1,086 ms
52,260 KB
testcase_19 AC 3,583 ms
55,452 KB
testcase_20 AC 1,424 ms
56,604 KB
testcase_21 AC 1,423 ms
55,176 KB
testcase_22 AC 1,029 ms
51,596 KB
testcase_23 AC 63 ms
23,720 KB
testcase_24 AC 67 ms
25,924 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 d = NArr(n);
        for (var i = 0; i < n; ++i) Array.Sort(d[i]);
        var ok = 1_000_000_000;
        var ng = -1;
        if (!Asakatu(d, ok))
        {
            WriteLine(-1);
            return;
        }
        while (ok - ng > 1)
        {
            var mid = (ok + ng) / 2;
            if (Asakatu(d, mid)) ok = mid;
            else ng = mid;
        }
        WriteLine(ok);
    }
    static bool Asakatu(int[][] d, int cliff)
    {
        var cur = Enumerable.Repeat(1, d[0].Length).ToArray();
        for (var i = 1; i < d.Length; ++i)
        {
            var next = new int[d[i].Length];
            for (var j = 0; j < cur.Length; ++j) if (cur[j] > 0)
            {
                var p = LowerBound(0, d[i - 1][j], d[i]);
                var q = LowerBound(0, d[i - 1][j] + cliff + 1, d[i]);
                if (p < next.Length) ++next[p];
                if (q < next.Length) --next[q];
            }
            for (var j = 1; j < next.Length; ++j) next[j] += next[j - 1];
            cur = next;
        }
        return cur.Any(ci => ci > 0);
    }
    static int LowerBound(int left, int min, int[] list)
    {
        if (list[left] >= min) return left;
        var ng = left;
        var ok = list.Length;
        while (ok - ng > 1)
        {
            var center = (ng + ok) / 2;
            if (list[center] < min) ng = center;
            else ok = center;
        }
        return ok;
    }
}
0