結果

問題 No.2696 Sign Creation
ユーザー tobisatistobisatis
提出日時 2024-03-22 22:55:49
言語 C#
(.NET 8.0.203)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 4,865 bytes
コンパイル時間 7,714 ms
コンパイル使用メモリ 165,216 KB
実行使用メモリ 190,832 KB
最終ジャッジ日時 2024-05-17 18:17:41
合計ジャッジ時間 14,219 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
29,696 KB
testcase_01 AC 55 ms
29,824 KB
testcase_02 AC 56 ms
29,696 KB
testcase_03 AC 56 ms
29,440 KB
testcase_04 AC 55 ms
29,696 KB
testcase_05 AC 56 ms
29,792 KB
testcase_06 AC 55 ms
29,824 KB
testcase_07 AC 56 ms
29,824 KB
testcase_08 AC 77 ms
33,792 KB
testcase_09 AC 70 ms
32,000 KB
testcase_10 AC 73 ms
33,376 KB
testcase_11 AC 74 ms
35,968 KB
testcase_12 AC 75 ms
35,968 KB
testcase_13 AC 284 ms
54,400 KB
testcase_14 AC 147 ms
54,400 KB
testcase_15 AC 138 ms
54,272 KB
testcase_16 AC 268 ms
54,520 KB
testcase_17 AC 154 ms
54,400 KB
testcase_18 AC 119 ms
54,144 KB
testcase_19 AC 162 ms
54,520 KB
testcase_20 AC 84 ms
42,880 KB
testcase_21 AC 122 ms
54,528 KB
testcase_22 AC 168 ms
54,380 KB
testcase_23 AC 139 ms
54,656 KB
testcase_24 AC 140 ms
54,528 KB
testcase_25 AC 192 ms
54,272 KB
testcase_26 AC 162 ms
54,272 KB
testcase_27 AC 173 ms
54,644 KB
testcase_28 AC 149 ms
54,392 KB
testcase_29 AC 161 ms
54,400 KB
testcase_30 AC 163 ms
54,272 KB
testcase_31 AC 570 ms
55,156 KB
testcase_32 AC 55 ms
29,440 KB
testcase_33 AC 59 ms
31,616 KB
testcase_34 AC 54 ms
29,696 KB
testcase_35 AC 54 ms
29,824 KB
testcase_36 AC 54 ms
29,952 KB
testcase_37 AC 54 ms
29,696 KB
testcase_38 AC 53 ms
29,816 KB
testcase_39 WA -
testcase_40 AC 55 ms
190,832 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (92 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.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 UnionFind
{
    (int parent, int size)[] Verticals { get; set; }

    public UnionFind(int verticals)
    {
        Verticals = new (int, int)[verticals];
        for (int i = 0; i < verticals; i++) Verticals[i] = (i, 1);
    }

    public int Union(int x, int y)
    {
        (x, y) = (Find(x), Find(y));
        if (Size(x) < Size(y)) (x, y) = (y, x);
        if (x == y) return x;
        Verticals[x].size += Verticals[y].size;
        Verticals[y].parent = x;
        return x;
    }

    public int Find(int x) => Parent(x).parent;
    public int Size(int x) => Parent(x).size;

    (int parent, int size) Parent(int x)
    {
        var parentId = Verticals[x].parent;
        if (parentId == x) return Verticals[x];
        var parent = Parent(parentId);
        Verticals[x].parent = parent.parent;
        return parent;
    }
}

class AtCoder
{
    object? Solve()
    {
        var h = Int();
        var w = Int();
        var n = Int();
        var d = Int();
        var g = new int[h, w];
        for (var i = 0; i < h; i++) for (var j = 0; j < w; j++) g[i, j] = -1;
        for (var i = 0; i < n; i++)
        {
            var x = Int() - 1;
            var y = Int() - 1;
            g[x, y] = i;
        }
        bool Inside(int x, int y) => 0 <= x && x < h && 0 <= y && y < w;
        var uf = new UnionFind(n);
        for (var x = 0; x < h; x++) for (var y = 0; y < w; y++) if (g[x, y] >= 0)
        {
            var v = g[x, y];
            for (var ds = 1; ds <= d; ds++) for (var dx = 0; dx <= ds; dx++)
            {
                var dy = ds - dx;
                var dc = new[]{ (x + dx, y + dy), (x + dx, y - dy), (x - dx, y + dy), (x - dx, y - dy) };
                foreach (var (nx, ny) in dc)
                {
                    if (!Inside(nx, ny)) continue;
                    var nv = g[nx, ny];
                    if (nv < 0) continue;
                    var u = uf.Union(v, nv);
                    g[x, y] = g[nx, ny] = u;
                }
            }
        }
        int o;
        {
            var s = new HashSet<int>();
            for (var x = 0; x < h; x++) for (var y = 0; y < w; y++) if (g[x, y] >= 0)
            {
                var v = g[x, y];
                var par = uf.Find(v);
                if (uf.Size(par) == 1) continue;
                s.Add(par);
            }
            o = s.Count;
        }
        var min = int.MaxValue / 2;
        var max = int.MinValue / 2;
        for (var x = 0; x < h; x++) for (var y = 0; y < w; y++) if (g[x, y] < 0)
        {
            var s = new HashSet<int>();
            var os = new HashSet<int>();
            for (var ds = 1; ds <= d; ds++) for (var dx = 0; dx <= ds; dx++)
            {
                var dy = ds - dx;
                var dc = new[]{ (x + dx, y + dy), (x + dx, y - dy), (x - dx, y + dy), (x - dx, y - dy) };
                foreach (var (nx, ny) in dc)
                {
                    if (!Inside(nx, ny)) continue;
                    var nv = g[nx, ny];
                    if (nv < 0) continue;
                    var par = uf.Find(nv);
                    if (uf.Size(par) == 1) os.Add(par);
                    else s.Add(par);
                }
            }
            var c = s.Count - 1;
            if (c < 0) c = 0;
            if (os.Count > 0) c--;
            min = Math.Min(min, o - c);
            max = Math.Max(max, o - c);
        }
        return min + " " + max;
    }

    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