結果

問題 No.1715 Dinner 2
ユーザー 👑 kakel-sankakel-san
提出日時 2021-10-22 22:16:06
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,197 bytes
コンパイル時間 2,010 ms
コンパイル使用メモリ 113,584 KB
実行使用メモリ 49,852 KB
最終ジャッジ日時 2023-10-24 13:30:25
合計ジャッジ時間 24,992 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 564 ms
49,836 KB
testcase_01 AC 562 ms
49,836 KB
testcase_02 AC 561 ms
49,836 KB
testcase_03 AC 564 ms
49,836 KB
testcase_04 AC 560 ms
49,836 KB
testcase_05 AC 562 ms
49,836 KB
testcase_06 AC 570 ms
49,836 KB
testcase_07 AC 567 ms
49,836 KB
testcase_08 AC 571 ms
49,844 KB
testcase_09 AC 562 ms
49,836 KB
testcase_10 AC 566 ms
49,836 KB
testcase_11 AC 585 ms
49,844 KB
testcase_12 AC 595 ms
49,844 KB
testcase_13 AC 582 ms
49,844 KB
testcase_14 AC 580 ms
49,844 KB
testcase_15 AC 581 ms
49,844 KB
testcase_16 AC 584 ms
49,844 KB
testcase_17 AC 615 ms
49,844 KB
testcase_18 AC 376 ms
44,064 KB
testcase_19 AC 417 ms
46,616 KB
testcase_20 AC 465 ms
45,700 KB
testcase_21 AC 345 ms
44,516 KB
testcase_22 AC 435 ms
45,868 KB
testcase_23 AC 539 ms
49,432 KB
testcase_24 AC 495 ms
49,396 KB
testcase_25 AC 567 ms
49,576 KB
testcase_26 AC 566 ms
49,576 KB
testcase_27 AC 567 ms
49,576 KB
testcase_28 AC 563 ms
49,324 KB
testcase_29 AC 566 ms
49,576 KB
testcase_30 AC 550 ms
49,576 KB
testcase_31 AC 558 ms
49,576 KB
testcase_32 AC 596 ms
49,852 KB
testcase_33 AC 574 ms
49,844 KB
testcase_34 AC 585 ms
49,852 KB
testcase_35 AC 568 ms
49,844 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 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 System.Collections.Generic;
using static System.Console;
using System.Linq;

class yuki319
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(int n) => Enumerable.Repeat(0, n).Select(_ => NList).ToArray();
    static void Main()
    {
        var c = NList;
        var (n, d) = (c[0], c[1]);
        var menu = NArr(n);

        var pmlist = new List<Pair>[100001];
        for (var i = 0; i < pmlist.Length; ++i) pmlist[i] = new List<Pair>();
        for (var i = 0; i < menu.Length; ++i) pmlist[menu[i][0]].Add(new Pair(i, menu[i][1] - menu[i][0]));

        for (var i = 1; i < pmlist.Length; ++i)
        {
            pmlist[i].AddRange(pmlist[i - 1]);
            pmlist[i].Sort();
            pmlist[i] = pmlist[i].Take(2).ToList();
        }

        var ok = -100000000;
        var ng = 0;
        while (ng - ok > 1)
        {
            var center = (ok + ng) / 2;
            var tmp = 0;
            var flg = true;
            var prev = -1;
            for (var i = 0; i < d; ++i)
            {
                var pow = Math.Min(100000, tmp - center);
                if (pow < 0 || pmlist[pow].Count == 0 || pmlist[pow].Count == 1 && pmlist[pow][0].Pos == prev)
                {
                    flg = false;
                    break;
                }
                if (pmlist[pow][0].Pos != prev)
                {
                    prev = pmlist[pow][0].Pos;
                    tmp += pmlist[pow][0].Val;
                }
                else
                {
                    prev = pmlist[pow][1].Pos;
                    tmp += pmlist[pow][1].Val;
                }
            }
            if (flg) ok = center;
            else ng = center;
        }
        WriteLine(ok);
    }
    class Pair : IComparable<Pair>
    {
        public int Pos;
        public int Val;
        public Pair(int pos, int val)
        {
            Pos = pos; Val = val;
        }
        public int CompareTo(Pair b)
        {
            return b.Val.CompareTo(Val);
        }
    }
}
0