結果

問題 No.2641 draw X
ユーザー tobisatistobisatis
提出日時 2024-02-19 23:23:38
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 4,824 bytes
コンパイル時間 9,486 ms
コンパイル使用メモリ 159,020 KB
実行使用メモリ 224,076 KB
最終ジャッジ日時 2024-02-19 23:23:55
合計ジャッジ時間 12,942 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
31,268 KB
testcase_01 AC 51 ms
31,268 KB
testcase_02 AC 51 ms
31,268 KB
testcase_03 AC 54 ms
31,268 KB
testcase_04 AC 51 ms
31,268 KB
testcase_05 AC 50 ms
31,268 KB
testcase_06 AC 52 ms
31,268 KB
testcase_07 AC 50 ms
31,268 KB
testcase_08 AC 52 ms
31,268 KB
testcase_09 AC 51 ms
31,268 KB
testcase_10 AC 53 ms
31,268 KB
testcase_11 AC 51 ms
31,268 KB
testcase_12 AC 51 ms
31,268 KB
testcase_13 AC 51 ms
31,268 KB
testcase_14 AC 52 ms
31,268 KB
testcase_15 AC 223 ms
80,084 KB
testcase_16 AC 285 ms
80,032 KB
testcase_17 AC 53 ms
31,268 KB
testcase_18 AC 52 ms
31,268 KB
testcase_19 AC 51 ms
31,268 KB
testcase_20 AC 68 ms
36,388 KB
testcase_21 AC 80 ms
38,180 KB
testcase_22 AC 68 ms
36,260 KB
testcase_23 AC 85 ms
41,528 KB
testcase_24 AC 66 ms
37,028 KB
testcase_25 AC 63 ms
36,004 KB
testcase_26 AC 88 ms
43,940 KB
testcase_27 AC 65 ms
36,004 KB
testcase_28 AC 115 ms
52,644 KB
testcase_29 AC 214 ms
71,100 KB
testcase_30 AC 189 ms
91,444 KB
testcase_31 AC 135 ms
53,412 KB
testcase_32 AC 200 ms
71,164 KB
testcase_33 AC 197 ms
72,184 KB
testcase_34 AC 142 ms
53,924 KB
testcase_35 AC 137 ms
55,204 KB
testcase_36 AC 246 ms
74,932 KB
testcase_37 AC 226 ms
77,672 KB
testcase_38 AC 202 ms
72,612 KB
testcase_39 AC 248 ms
79,248 KB
testcase_40 AC 245 ms
76,884 KB
testcase_41 AC 231 ms
72,772 KB
testcase_42 AC 214 ms
74,640 KB
testcase_43 AC 223 ms
224,076 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (102 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();

    public static T[,] Rotated<T>(this T[,] g)
    {
        var (h, w) = (g.GetLength(0), g.GetLength(1));
        var res = new T[w, h];
        for (var i = 0; i < h; i++) for (var j = 0; j < w; j++) res[w - 1 - j, i] = g[i, j];
        return res;
    }

    public static bool Is<T>(this T[,] g, T[,] a)
    {
        var (h, w) = (g.GetLength(0), g.GetLength(1));
        var (ha, wa) = (a.GetLength(0), a.GetLength(1));
        if (h != ha || w != wa) return false;
        for (var i = 0; i < h; i++) for (var j = 0; j < w; j++)
        {
            var (vg, va) = (g[i, j], a[i, j]);
            if (vg == null) { if (va != null) return false; }
            else if (!vg.Equals(va)) return false;
        }
        return true;
    }
}

class AtCoder
{
    object? Solve()
    {
        var h = Int();
        var w = Int();
        var s = new bool[h, w];
        for (var i = 0; i < h; i++)
        {
            var row = String();
            for (var j = 0; j < w; j++) s[i, j] = row[j] == '#';
        }
        var t = new bool[h, w];
        var g = new int[4][,];
        for (var k = 0; k < 4; k++)
        {
            var gg = new int[h, w];
            for (var i = 0; i < h; i++)
            {
                var (x, y) = (i, 0);
                var l = 0;
                while (x < h && y < w)
                {
                    if (s[x, y]) gg[x, y] = ++l;
                    else l = 0;
                    x++;
                    y++;
                }
            }
            for (var j = 1; j < w; j++)
            {
                var (x, y) = (0, j);
                var l = 0;
                while (x < h && y < w)
                {
                    if (s[x, y]) gg[x, y] = ++l;
                    else l = 0;
                    x++;
                    y++;
                }
            }
            s = s.Rotated();
            (h, w) = (w, h);
            for (var i = 4; i > k; i--) gg = gg.Rotated();
            g[k] = gg;
        }
        var b = new int[h, w];
        for (var i = 0; i < h; i++) for (var j = 0; j < w; j++) b[i, j] = int.MaxValue / 2;
        for (var k = 0; k < 4; k++) for (var i = 0; i < h; i++) for (var j = 0; j < w; j++) b[i, j] = Math.Min(b[i, j], g[k][i, j]);
        for (var i = 0; i < h; i++) for (var j = 0; j < w; j++) if (b[i, j] == 1) b[i, j] = 0;
        for (var k = 0; k < 4; k++)
        {
            for (var i = 0; i < h; i++)
            {
                var (x, y) = (i, 0);
                var l = 0;
                while (x < h && y < w)
                {
                    l = Math.Max(l, b[x, y]);
                    if (l > 0)
                    {
                        t[x, y] = true;
                        l--;
                    }
                    x++;
                    y++;
                }
            }
            for (var j = 1; j < w; j++)
            {
                var (x, y) = (0, j);
                var l = 0;
                while (x < h && y < w)
                {
                    l = Math.Max(l, b[x, y]);
                    if (l > 0)
                    {
                        t[x, y] = true;
                        l--;
                    }
                    x++;
                    y++;
                }
            }
            t = t.Rotated();
            b = b.Rotated();
            (h, w) = (w, h);
        }
        return s.Is(t);
    }

    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