結果

問題 No.2652 [Cherry 6th Tune N] Δρονε χιρχλινγ
ユーザー tobisatistobisatis
提出日時 2024-02-24 00:18:04
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,096 ms / 2,000 ms
コード長 3,302 bytes
コンパイル時間 11,051 ms
コンパイル使用メモリ 158,536 KB
実行使用メモリ 208,636 KB
最終ジャッジ日時 2024-02-24 00:19:21
合計ジャッジ時間 75,688 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
32,292 KB
testcase_01 AC 669 ms
58,532 KB
testcase_02 AC 661 ms
58,404 KB
testcase_03 AC 702 ms
57,892 KB
testcase_04 AC 855 ms
64,956 KB
testcase_05 AC 885 ms
65,612 KB
testcase_06 AC 895 ms
65,660 KB
testcase_07 AC 965 ms
69,628 KB
testcase_08 AC 964 ms
76,060 KB
testcase_09 AC 1,015 ms
78,052 KB
testcase_10 AC 976 ms
65,404 KB
testcase_11 AC 993 ms
75,812 KB
testcase_12 AC 977 ms
82,656 KB
testcase_13 AC 1,005 ms
75,360 KB
testcase_14 AC 1,019 ms
77,128 KB
testcase_15 AC 1,017 ms
86,036 KB
testcase_16 AC 1,001 ms
72,432 KB
testcase_17 AC 1,016 ms
77,840 KB
testcase_18 AC 1,013 ms
76,664 KB
testcase_19 AC 1,004 ms
76,096 KB
testcase_20 AC 1,067 ms
88,288 KB
testcase_21 AC 1,059 ms
88,288 KB
testcase_22 AC 1,081 ms
88,288 KB
testcase_23 AC 1,067 ms
88,280 KB
testcase_24 AC 1,062 ms
88,160 KB
testcase_25 AC 1,096 ms
88,160 KB
testcase_26 AC 1,087 ms
88,032 KB
testcase_27 AC 1,082 ms
88,160 KB
testcase_28 AC 1,054 ms
88,280 KB
testcase_29 AC 1,087 ms
88,156 KB
testcase_30 AC 1,075 ms
88,160 KB
testcase_31 AC 1,061 ms
88,160 KB
testcase_32 AC 1,077 ms
88,160 KB
testcase_33 AC 1,053 ms
88,160 KB
testcase_34 AC 1,042 ms
88,288 KB
testcase_35 AC 1,043 ms
88,160 KB
testcase_36 AC 1,063 ms
88,152 KB
testcase_37 AC 1,082 ms
88,152 KB
testcase_38 AC 1,068 ms
88,288 KB
testcase_39 AC 1,077 ms
88,152 KB
testcase_40 AC 472 ms
61,988 KB
testcase_41 AC 464 ms
208,636 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (136 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

namespace AtCoder;

#nullable enable

using System.Numerics;

static class Extensions
{
    public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
}

class AtCoder
{
    object? Solve()
    {
        var t = Int();
        var ans = new List<List<(int, int)>>();
        for (var i = 0; i < t; i++)
        {
            ans.Add(Solve2());
        }
        foreach (var l in ans)
        {
            Out(l.Count);
            foreach (var (x, y) in l) Out(x + " " + y);
        }
        return null;
    }

    List<(int, int)> Solve2()
    {
        var res = new List<(int, int)>();
        var n = Int();
        var l = Int();
        var d = 1;
        while (d * d <= n * 2) d++;
        var z = l / d + 1;
        var g = new Dictionary<(int, int), List<(int, int)>>();
        for (var i = 0; i < n; i++)
        {
            var x = Int();
            var y = Int();
            var (xd, yd) = (x / z, y / z);
            if (!g.ContainsKey((xd, yd))) g[(xd, yd)] = new();
            g[(xd, yd)].Add((x, y));
        }
        var kz = new List<(int, int)>(g.Keys);
        kz.Sort();
        var kz2 = new Dictionary<int, List<int>>();
        foreach (var (x, y) in kz)
        {
            if (!kz2.ContainsKey(x)) kz2[x] = new();
            kz2[x].Add(y);
        }
        var rev = false;
        foreach (var (x, yl) in kz2)
        {
            var ro = rev;
            yl.Sort();
            if (ro) yl.Reverse();
            foreach (var y in yl)
            {
                var a = g[(x, y)];
                a.Sort();
                if (ro) a.Reverse();
                foreach (var (xo, yo) in a) res.Add((xo, yo));
            }
            rev = !rev;
        }

        {
            var check = 0L;
            var (xl, yl) = res[^1];
            foreach (var (x, y) in res)
            {
                check += Math.Abs(x - xl) + Math.Abs(y - yl);
                (xl, yl) = (x, y);
            }
            if (check >= 1000L * l) throw new Exception();
        }

        return res;
    }

    public static void Main() => new AtCoder().Run();
    public void Run()
    {
        var res = Solve();
        if (res != null)
        {
            if (res is bool yes) res = yes ? "Yes" : "No";
            sw.WriteLine(res);
        }
        sw.Flush();
    }

    string[] input = Array.Empty<string>();
    int iter = 0;
    readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false };

    #pragma warning disable IDE0051
    string String()
    {
        while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0);
        return input[iter++];
    }
    T Input<T>() where T : IParsable<T> => T.Parse(String(), null);
    int Int() => Input<int>();
    void Out(object? x, string? separator = null)
    {
        separator ??= Environment.NewLine;
        if (x is System.Collections.IEnumerable obj and not string)
        {
            var firstLine = true;
            foreach (var item in obj)
            {
                if (!firstLine) sw.Write(separator);
                firstLine = false;
                sw.Write(item);
            }
        }
        else sw.Write(x);
        sw.WriteLine();
    }
    #pragma warning restore IDE0051
}
0