結果

問題 No.771 しおり
ユーザー bluemeganebluemegane
提出日時 2021-05-14 11:30:11
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,004 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 112,764 KB
実行使用メモリ 161,256 KB
最終ジャッジ日時 2024-04-09 03:21:10
合計ジャッジ時間 27,304 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 166 ms
42,808 KB
testcase_02 AC 32 ms
22,968 KB
testcase_03 AC 31 ms
25,056 KB
testcase_04 AC 32 ms
26,924 KB
testcase_05 AC 30 ms
23,100 KB
testcase_06 AC 32 ms
26,804 KB
testcase_07 AC 29 ms
24,672 KB
testcase_08 AC 32 ms
25,264 KB
testcase_09 AC 32 ms
27,048 KB
testcase_10 AC 31 ms
24,928 KB
testcase_11 AC 32 ms
25,136 KB
testcase_12 AC 31 ms
25,136 KB
testcase_13 AC 32 ms
25,140 KB
testcase_14 AC 34 ms
26,836 KB
testcase_15 AC 31 ms
22,836 KB
testcase_16 AC 31 ms
26,924 KB
testcase_17 AC 31 ms
24,932 KB
testcase_18 AC 32 ms
27,180 KB
testcase_19 AC 32 ms
24,676 KB
testcase_20 AC 31 ms
24,800 KB
testcase_21 AC 32 ms
26,836 KB
testcase_22 AC 31 ms
27,052 KB
testcase_23 AC 31 ms
25,056 KB
testcase_24 AC 30 ms
24,804 KB
testcase_25 AC 700 ms
73,524 KB
testcase_26 AC 37 ms
22,936 KB
testcase_27 AC 177 ms
37,224 KB
testcase_28 AC 366 ms
53,100 KB
testcase_29 AC 167 ms
39,396 KB
testcase_30 AC 1,861 ms
129,160 KB
testcase_31 AC 1,874 ms
129,772 KB
testcase_32 AC 50 ms
27,492 KB
testcase_33 AC 1,871 ms
127,648 KB
testcase_34 AC 1,991 ms
131,208 KB
testcase_35 AC 56 ms
27,364 KB
testcase_36 AC 33 ms
24,984 KB
testcase_37 AC 33 ms
24,980 KB
testcase_38 AC 52 ms
29,416 KB
testcase_39 AC 34 ms
27,028 KB
testcase_40 AC 677 ms
74,928 KB
testcase_41 AC 1,894 ms
127,604 KB
testcase_42 AC 1,739 ms
123,500 KB
testcase_43 AC 169 ms
40,916 KB
testcase_44 TLE -
testcase_45 AC 1,935 ms
126,968 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public int ended { get; set; }
    public int pre { get; set; }
}

public class Hello
{
    public static int n;
    static void Main()
    {
        n = int.Parse(Console.ReadLine().Trim());
        var input = new int[n, 2];
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            input[i, 0] = int.Parse(line[0]);
            input[i, 1] = int.Parse(line[1]);
        }
        getAns(input);
    }
    static int[,] makeArray(int[,] input)
    {
        var res = new int[n, n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (i != j) res[i, j] = input[i, 1] - input[i, 0] + input[j, 0];
        return res;
    }
    static void getAns(int[,] input)
    {
        var aa = makeArray(input);
        var imax = 1 << n;
        var dp = new int[imax, n];
        for (int i = 0; i < imax; i++)
            for (int j = 0; j < n; j++) dp[i, j] = int.MaxValue;
        var q = new Queue<P>();
        for (int i = 0; i < n; i++)
        {
            var t = 1 << i;
            dp[t, i] = 0;
            q.Enqueue(new P { ended = t, pre = i });
        }
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            for (int i = 0; i < n; i++)
            {
                if (((w.ended >> i) & 1) == 0)
                {

                    var ndp = Max(dp[w.ended, w.pre], aa[w.pre, i]);
                    var nended = (w.ended | (1 << i));
                    if (ndp < dp[nended, i])
                    {
                        dp[nended, i] = ndp;
                        q.Enqueue(new P { ended = nended, pre = i });
                    }
                }
            }
        }
        var ans = int.MaxValue;
        for (int i = 0; i < n; i++)
            ans = Min(ans, dp[imax - 1, i]);
        Console.WriteLine(ans);
    }
}
0