結果

問題 No.2375 watasou and hibit's baseball
ユーザー 👑 kakel-sankakel-san
提出日時 2023-07-07 22:39:12
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,168 ms / 2,000 ms
コード長 2,319 bytes
コンパイル時間 2,612 ms
コンパイル使用メモリ 66,280 KB
実行使用メモリ 40,796 KB
最終ジャッジ日時 2023-09-29 00:12:05
合計ジャッジ時間 24,464 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
24,000 KB
testcase_01 AC 65 ms
24,036 KB
testcase_02 AC 64 ms
21,908 KB
testcase_03 AC 421 ms
30,556 KB
testcase_04 AC 65 ms
22,008 KB
testcase_05 AC 64 ms
21,812 KB
testcase_06 AC 715 ms
38,664 KB
testcase_07 AC 64 ms
21,772 KB
testcase_08 AC 235 ms
23,924 KB
testcase_09 AC 65 ms
21,892 KB
testcase_10 AC 66 ms
22,076 KB
testcase_11 AC 88 ms
21,968 KB
testcase_12 AC 1,168 ms
40,796 KB
testcase_13 AC 499 ms
32,556 KB
testcase_14 AC 65 ms
24,020 KB
testcase_15 AC 125 ms
23,912 KB
testcase_16 AC 79 ms
21,924 KB
testcase_17 AC 1,096 ms
38,616 KB
testcase_18 AC 65 ms
21,872 KB
testcase_19 AC 65 ms
24,024 KB
testcase_20 AC 90 ms
21,804 KB
testcase_21 AC 1,019 ms
38,628 KB
testcase_22 AC 68 ms
21,968 KB
testcase_23 AC 1,040 ms
38,800 KB
testcase_24 AC 1,104 ms
40,644 KB
testcase_25 AC 65 ms
19,964 KB
testcase_26 AC 922 ms
38,588 KB
testcase_27 AC 946 ms
38,572 KB
testcase_28 AC 851 ms
36,576 KB
testcase_29 AC 783 ms
38,604 KB
testcase_30 AC 1,039 ms
40,704 KB
testcase_31 AC 970 ms
38,644 KB
testcase_32 AC 976 ms
40,672 KB
testcase_33 AC 969 ms
38,640 KB
testcase_34 AC 874 ms
38,612 KB
testcase_35 AC 796 ms
40,752 KB
testcase_36 AC 773 ms
36,552 KB
testcase_37 AC 1,164 ms
40,728 KB
testcase_38 AC 736 ms
38,716 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, a, b) = (c[0], c[1], c[2]);
        var map = NArr(n);
        var bitmax = 1 << n;
        var infarr = Enumerable.Repeat(int.MinValue, n * n).ToArray();
        var dp = new int[bitmax][];
        for (var i = 0; i < dp.Length; ++i) dp[i] = (int[]) infarr.Clone();
        dp[0][0] = 0;
        for (var bit = 0; bit < bitmax; ++bit)
        {
            var pc = PopCount(bit);
            for (var i = 0; i < dp[bit].Length; ++i)
            {
                var p1 = i % n;
                var p2 = i / n;
                if ((pc == 1 && (bit & (1 << p1)) == 0)
                    || (pc == 2 && ((bit & (1 << p1)) == 0 || (bit & (1 << p2)) == 0))) continue;
                for (var next = 0; next < n; ++next)
                {
                    if ((bit & (1 << next)) != 0) continue;
                    if (pc == 0
                        || (pc == 1 && a <= Dist(map, p1, next))
                        || (pc >= 1 && b <= Speed(map, p1, next))
                        || (pc >= 2 && a <= Dist(map, p1, next) + Dist(map, p2, next)))
                    {
                        dp[bit | (1 << next)][p1 * n + next] = Math.Max(dp[bit | (1 << next)][p1 * n + next], dp[bit][i] + 1);
                    }
                }
            }
        }
        var ans = 0;
        foreach (var di in dp) ans = Math.Max(ans, di.Max());
        WriteLine(ans);
    }
    static int Dist(int[][] map, int i, int j)
    {
        return Math.Abs(map[i][0] - map[j][0]) + Math.Abs(map[i][1] - map[j][1]);
    }
    static int Speed(int[][] map, int i, int j)
    {
        return Math.Abs(map[i][2] - map[j][2]);
    }
    static int PopCount(int n)
    {
        var ans = 0;
        while (n > 0)
        {
            ans += n % 2;
            n >>= 1;
        }
        return ans;
    }
}
0