結果

問題 No.2658 L-R Nim
ユーザー tobisatistobisatis
提出日時 2024-03-01 23:41:07
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 3,337 bytes
コンパイル時間 7,119 ms
コンパイル使用メモリ 157,616 KB
実行使用メモリ 189,092 KB
最終ジャッジ日時 2024-03-01 23:41:34
合計ジャッジ時間 26,871 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
37,192 KB
testcase_01 AC 85 ms
36,936 KB
testcase_02 AC 6,543 ms
37,448 KB
testcase_03 AC 6,542 ms
37,444 KB
testcase_04 AC 86 ms
36,936 KB
testcase_05 WA -
testcase_06 AC 87 ms
37,796 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 88 ms
37,796 KB
testcase_10 AC 89 ms
37,796 KB
testcase_11 WA -
testcase_12 AC 87 ms
37,796 KB
testcase_13 AC 89 ms
37,796 KB
testcase_14 AC 88 ms
37,796 KB
testcase_15 WA -
testcase_16 AC 87 ms
37,796 KB
testcase_17 AC 87 ms
37,796 KB
testcase_18 AC 87 ms
37,796 KB
testcase_19 AC 89 ms
37,796 KB
testcase_20 WA -
testcase_21 AC 89 ms
37,796 KB
testcase_22 AC 89 ms
37,796 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 93 ms
39,720 KB
testcase_34 AC 98 ms
41,488 KB
testcase_35 AC 94 ms
39,404 KB
testcase_36 AC 99 ms
41,488 KB
testcase_37 WA -
testcase_38 AC 99 ms
41,488 KB
testcase_39 AC 97 ms
41,488 KB
testcase_40 AC 98 ms
41,488 KB
testcase_41 AC 98 ms
41,488 KB
testcase_42 AC 98 ms
41,480 KB
testcase_43 AC 98 ms
41,480 KB
testcase_44 AC 100 ms
41,480 KB
testcase_45 AC 97 ms
41,480 KB
testcase_46 AC 98 ms
41,480 KB
testcase_47 AC 98 ms
41,468 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 98 ms
41,488 KB
testcase_52 AC 97 ms
189,092 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (97 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 TimeLimit
{
    long Limit { get; set; }
    System.Diagnostics.Stopwatch Stopwatch { get; set; }

    public TimeLimit(long milliseconds)
    {
        Limit = milliseconds;
        Stopwatch = new System.Diagnostics.Stopwatch();
        Stopwatch.Start();
    }
    
    public static implicit operator bool(TimeLimit tl) => tl.Stopwatch.ElapsedMilliseconds < tl.Limit;
}

class AtCoder
{
    object? Solve()
    {
        var tl = new TimeLimit(6500);
        var n = Int();
        var k = Int();
        var az = n.Repeat(Int);
        var (lo, ro) = (0, n - 1);
        var df = false;
        var m = 1000000;
        var srz = (m + 1).Repeat(() => -2);
        srz[0] = -1;
        for (var i = 0; i < n; i++)
        {
            var a = az[i];
            if (srz[a] >= -1)
            {
                df = true;
                var (l, r) = (srz[a] + 1, i);
                lo = Math.Max(lo, l);
                ro = Math.Min(ro, r);
            }
            srz[a] = i;
        }
        if (!df)
        {
            return true;
        }
        if (lo > ro)
        {
            return false;
        }
        var d = new int[m + 1];
        d[0] = 1;
        var dup = 0;
        var random = new Random(1);
        while (tl)
        {
            var ri = random.Next(lo, ro + 1);
            var ao = az[ri];
            az[ri] = random.Next(Math.Max(1, ao - k), ao + k + 1);
            var sxor = 0;
            for (var i = 0; i < n; i++)
            {
                sxor ^= az[i];
                d[sxor]++;
                if (d[sxor] == 2) dup++;
            }
            if (dup == 0)
            {
                return true;
            }
            for (var i = n - 1; i >= 0; i--)
            {
                if (d[sxor] == 2) dup--;
                d[sxor]--;
                sxor ^= az[i];
            }
            az[ri] = ao;
        }
        return false;
    }

    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