結果

問題 No.2658 L-R Nim
ユーザー tobisatistobisatis
提出日時 2024-03-01 23:47:19
言語 C#
(.NET 8.0.203)
結果
RE  
実行時間 -
コード長 3,391 bytes
コンパイル時間 7,130 ms
コンパイル使用メモリ 158,496 KB
実行使用メモリ 193,808 KB
最終ジャッジ日時 2024-03-01 23:47:58
合計ジャッジ時間 39,411 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
37,196 KB
testcase_01 AC 82 ms
36,940 KB
testcase_02 AC 6,559 ms
37,452 KB
testcase_03 AC 85 ms
36,936 KB
testcase_04 AC 89 ms
36,936 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 6,544 ms
39,792 KB
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (96 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;
        var txor = 0;
        for (var i = 0; i < n; i++)
        {
            var a = az[i];
            txor ^= a;
            if (srz[txor] >= -1)
            {
                df = true;
                var (l, r) = (srz[txor] + 1, i);
                lo = Math.Max(lo, l);
                ro = Math.Min(ro, r);
            }
            srz[txor] = 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