結果

問題 No.2165 Let's Play Nim!
ユーザー kakel-san
提出日時 2023-09-18 23:42:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 1,521 bytes
コンパイル時間 3,706 ms
コンパイル使用メモリ 107,136 KB
実行使用メモリ 38,480 KB
平均クエリ数 863.56
最終ジャッジ日時 2024-07-05 12:43:50
合計ジャッジ時間 27,701 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 32 TLE * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var a = NList;
        var xor = a.Aggregate((x, y) => x ^ y);
        WriteLine(xor == 0 ? 0 : 1);
        while (true)
        {
            if (xor == 0)
            {
                var c = NList;
                var preva = a[c[0] - 1];
                a[c[0] - 1] -= c[1];
                xor ^= preva ^ a[c[0] - 1];
                if (NN != 0) return;
            }
            else
            {
                for (var i = 0; i < n; ++i)
                {
                    var xb = Bits(xor);
                    if (xb <= Bits(a[i]))
                    {
                        var k = a[i] - (xor ^ a[i]);
                        if (k < 0) continue;
                        WriteLine($"{i + 1} {k}");
                        xor ^= a[i] ^ (a[i] - k);
                        a[i] -= k;
                        if (NN != 0) return;
                        break;
                    }
                }
            }
        }
    }
    static int Bits(int a)
    {
        var ans = 0;
        while (a > 0)
        {
            ++ans;
            a >>= 1;
        }
        return ans;
    }
}
0