結果

問題 No.2227 King Kraken's Attack
ユーザー kakel-sankakel-san
提出日時 2023-02-24 23:30:54
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,340 bytes
コンパイル時間 993 ms
コンパイル使用メモリ 107,648 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-10-02 11:29:59
合計ジャッジ時間 27,730 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
18,944 KB
testcase_01 AC 27 ms
18,944 KB
testcase_02 AC 27 ms
18,688 KB
testcase_03 AC 32 ms
18,816 KB
testcase_04 AC 26 ms
18,688 KB
testcase_05 AC 28 ms
18,944 KB
testcase_06 AC 27 ms
18,688 KB
testcase_07 AC 27 ms
18,944 KB
testcase_08 AC 29 ms
18,944 KB
testcase_09 AC 29 ms
19,072 KB
testcase_10 AC 29 ms
18,944 KB
testcase_11 AC 29 ms
18,688 KB
testcase_12 AC 29 ms
18,688 KB
testcase_13 AC 28 ms
18,816 KB
testcase_14 AC 28 ms
18,688 KB
testcase_15 AC 29 ms
18,944 KB
testcase_16 AC 27 ms
19,072 KB
testcase_17 AC 1,516 ms
18,816 KB
testcase_18 AC 1,536 ms
18,816 KB
testcase_19 AC 27 ms
18,944 KB
testcase_20 AC 1,411 ms
18,816 KB
testcase_21 AC 1,450 ms
18,944 KB
testcase_22 AC 382 ms
18,944 KB
testcase_23 AC 57 ms
18,944 KB
testcase_24 AC 791 ms
18,944 KB
testcase_25 AC 1,409 ms
18,688 KB
testcase_26 AC 1,660 ms
18,816 KB
testcase_27 AC 1,518 ms
18,816 KB
testcase_28 AC 1,413 ms
18,688 KB
testcase_29 AC 1,405 ms
18,560 KB
testcase_30 AC 1,461 ms
19,072 KB
testcase_31 AC 1,244 ms
18,944 KB
testcase_32 AC 634 ms
18,944 KB
testcase_33 AC 526 ms
19,072 KB
testcase_34 AC 395 ms
19,072 KB
testcase_35 AC 672 ms
18,816 KB
testcase_36 AC 660 ms
18,816 KB
testcase_37 AC 517 ms
18,944 KB
testcase_38 AC 359 ms
19,072 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 1,240 ms
18,944 KB
testcase_42 AC 312 ms
18,944 KB
testcase_43 AC 611 ms
18,816 KB
testcase_44 AC 1,123 ms
19,072 KB
testcase_45 AC 28 ms
18,816 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Test()
    {
        var r = new Random();
        var count = 0;
        var max = 2000;
        while (true)
        {
            var h = r.Next(max) + 1;
            var w = r.Next(max) + 1;
            var la = r.Next(max) + 1;
            var lb = r.Next(max) + 1;
            var ka = r.Next(max);
            var kb = r.Next(max);
            // 愚直解
            var s1 = All(h, w, la, lb, ka, kb);
            // 作成解
            var s2 = Attack(h, w, la, lb, ka, kb);
            if (s1 != s2)
            {
                WriteLine($"{h} {w} {la} {lb} {ka} {kb}");
                WriteLine(s1);
                WriteLine(s2);
                return;
            }
            ++count;
            if (count % 10 == 0) WriteLine(count);
        }
    }
    static long All(long h, long w, long la, long lb, long ka, long kb)
    {
        var ans = long.MaxValue;
        for (var ai = 0; Math.Max(ai, ai * ka) <= h * w + ka; ++ai) for (var bi = 0; Math.Max(bi, bi * kb) <= h * w + kb; ++bi)
        {
            var hs = Math.Min(h, ai * la);
            var ws = Math.Min(w, bi * lb);
            if (hs * ws + ai * ka + bi * kb >= h * w) ans = Math.Min(ans, ai + bi);
        }
        return ans;
    }
    static void Solve()
    {
        var c = NList;
        var (h, w, la, lb, ka, kb) = (c[0], c[1], c[2], c[3], c[4], c[5]);
        WriteLine(Attack(h, w, la, lb, ka, kb));
    }
    static long Attack(long h, long w, long la, long lb, long ka, long kb)
    {
        var horimax = (h + la - 1) / la;
        var vertmax = (w + lb - 1) / lb;
        var ans = horimax + vertmax;
        var kmax = Math.Max(ka, kb);
        if (kmax == 0)
        {
            return ans;
        }
        if (ka > 0) ans = Math.Min(ans, (h * w + ka - 1) / ka);
        if (kb > 0) ans = Math.Min(ans, (h * w + kb - 1) / kb);
        for (var ai = 0; ai <= h; ++ai)
        {
            if (ai == 0 && kb == 0) continue;
            var ok = h * w;
            var ng = -1L;
            while (ok - ng > 1)
            {
                var mid = (ok + ng) / 2;
                var hs = Math.Min(h, ai * la);
                var ws = Math.Min(w, mid * lb);
                var cnt = hs * ws + ai * ka + mid * kb;
                if (cnt >= h * w) ok = mid;
                else ng = mid;
            }
            ans = Math.Min(ans, ai + ok);
        }
        for (var bi = 0; bi <= w; ++bi)
        {
            if (bi == 0 && ka == 0) continue;
            var ok = h * w;
            var ng = -1L;
            while (ok - ng > 1)
            {
                var mid = (ok + ng) / 2;
                var hs = Math.Min(h, mid * la);
                var ws = Math.Min(w, bi * lb);
                var cnt = hs * ws + bi * kb + mid * ka;
                if (cnt >= h * w) ok = mid;
                else ng = mid;
            }
            ans = Math.Min(ans, bi + ok);
        }
        return ans;
    }
}
0