結果

問題 No.2376 障害物競プロ
ユーザー 👑 kakel-sankakel-san
提出日時 2023-07-13 20:39:25
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,386 ms / 4,000 ms
コード長 3,279 bytes
コンパイル時間 14,182 ms
コンパイル使用メモリ 144,188 KB
実行使用メモリ 220,316 KB
最終ジャッジ日時 2023-10-13 09:39:13
合計ジャッジ時間 79,137 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
31,388 KB
testcase_01 AC 65 ms
29,540 KB
testcase_02 AC 64 ms
31,332 KB
testcase_03 AC 65 ms
29,448 KB
testcase_04 AC 329 ms
81,388 KB
testcase_05 AC 387 ms
84,252 KB
testcase_06 AC 238 ms
67,204 KB
testcase_07 AC 628 ms
85,932 KB
testcase_08 AC 626 ms
85,980 KB
testcase_09 AC 613 ms
87,900 KB
testcase_10 AC 633 ms
85,944 KB
testcase_11 AC 603 ms
82,432 KB
testcase_12 AC 578 ms
81,400 KB
testcase_13 AC 579 ms
85,916 KB
testcase_14 AC 629 ms
86,168 KB
testcase_15 AC 606 ms
85,864 KB
testcase_16 AC 619 ms
86,032 KB
testcase_17 AC 578 ms
81,356 KB
testcase_18 AC 580 ms
81,784 KB
testcase_19 AC 1,386 ms
82,056 KB
testcase_20 AC 1,364 ms
84,760 KB
testcase_21 AC 1,359 ms
82,916 KB
testcase_22 AC 476 ms
81,992 KB
testcase_23 AC 391 ms
67,880 KB
testcase_24 AC 325 ms
82,912 KB
testcase_25 AC 194 ms
66,728 KB
testcase_26 AC 343 ms
81,788 KB
testcase_27 AC 319 ms
83,352 KB
testcase_28 AC 269 ms
66,620 KB
testcase_29 AC 198 ms
64,544 KB
testcase_30 AC 299 ms
53,164 KB
testcase_31 AC 245 ms
67,184 KB
testcase_32 AC 93 ms
36,196 KB
testcase_33 AC 163 ms
41,092 KB
testcase_34 AC 173 ms
51,136 KB
testcase_35 AC 106 ms
43,884 KB
testcase_36 AC 419 ms
69,988 KB
testcase_37 AC 401 ms
83,772 KB
testcase_38 AC 192 ms
68,260 KB
testcase_39 AC 533 ms
81,144 KB
testcase_40 AC 282 ms
41,732 KB
testcase_41 AC 173 ms
66,244 KB
testcase_42 AC 1,051 ms
86,228 KB
testcase_43 AC 1,291 ms
220,316 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  Determining projects to restore...
  Restored /home/judge/data/code/main.csproj (in 136 ms).
.NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f
Copyright (C) Microsoft Corporation.All rights reserved.

  プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください
  main -> /home/judge/data/code/bin/Release/net6.0/main.dll
  main -> /home/judge/data/code/bin/Release/net6.0/publish/

ソースコード

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 map = NArr(n);
        var query = NArr(m);

        var points = new int[n * 2][];
        for (var i = 0; i < n; ++i)
        {
            points[i * 2] = new int[] { map[i][0], map[i][1] };
            points[i * 2 + 1] = new int[] { map[i][2], map[i][3] };
        }
        var INF = double.MaxValue / 2;
        var dp = new double[n * 2][];
        for (var i = 0; i < dp.Length; ++i) dp[i] = Enumerable.Repeat(INF, n * 2).ToArray();
        for (var i = 0; i < n; ++i) for (var j = 0; j < n; ++j)
        {
            void calc(int a, int b)
            {
                var flg = true;
                for (var k = 0; k < n; ++k)
                {
                    if (a / 2 == k || b / 2 == k) continue;
                    if (Cross(points[a], points[b], points[k * 2], points[k * 2 + 1]))
                    {
                        flg = false;
                        break;
                    }
                }
                if (flg)
                {
                    dp[a][b] = Length(points[a], points[b]);
                    dp[b][a] = dp[a][b];
                }
            }
            calc(i * 2, j * 2);
            calc(i * 2, j * 2 + 1);
            calc(i * 2 + 1, j * 2);
            calc(i * 2 + 1, j * 2 + 1);
        }
        for (var k = 0; k < dp.Length; ++k) for (var i = 0; i < dp.Length; ++i) for (var j = 0; j < dp.Length; ++j)
        {
            dp[i][j] = Math.Min(dp[i][j], dp[i][k] + dp[k][j]);
        }
        var ans = new double[m];
        for (var i = 0; i < m; ++i)
        {
            ans[i] = dp[query[i][0] * 2 + query[i][1] - 3][query[i][2] * 2 + query[i][3] - 3];
        }
        WriteLine(string.Join("\n", ans));
    }
    static bool Cross(int[] a, int[] b, int[] c, int[] d)
    {
        var sa = AreaSign(c, d, a);
        var sb = AreaSign(c, d, b);
        var sc = AreaSign(a, b, c);
        var sd = AreaSign(a, b, d);
        if (sa == 0 && sb == 0 && sc == 0 && sd == 0)
        {
            return false;
        }
        return sa != sb && sc != sd;
    }
    static int AreaSign(int[] a, int[] b, int[] c)
    {
        if (a[0] == b[0])
        {
            if (c[0] == a[0]) return 0;
            else if (c[0] > a[0]) return 1;
            else return -1;
        }
        if (a[0] > b[0]) (a, b) = (b, a);
        var res = Area2(a, c) + Area2(c, b) - Area2(a, b);
        if (res == 0) return 0;
        if (res > 0) return 1;
        return -1;
    }
    static long Area2(int[] a, int[] b)
    {
        return (long)(a[1] + b[1]) * (b[0] - a[0]);
    }
    static double Length(int[] a, int[] b)
    {
        return Math.Sqrt(Math.Pow(a[0] - b[0], 2) + Math.Pow(a[1] - b[1], 2));
    }
}
0