結果

問題 No.2165 Let's Play Nim!
ユーザー 👑 kakel-sankakel-san
提出日時 2023-09-18 23:42:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 351 ms / 2,000 ms
コード長 1,521 bytes
コンパイル時間 3,741 ms
コンパイル使用メモリ 65,824 KB
実行使用メモリ 40,328 KB
平均クエリ数 863.56
最終ジャッジ日時 2023-09-18 23:43:31
合計ジャッジ時間 29,610 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
37,596 KB
testcase_01 AC 236 ms
39,892 KB
testcase_02 AC 253 ms
37,792 KB
testcase_03 AC 188 ms
38,196 KB
testcase_04 AC 89 ms
37,844 KB
testcase_05 AC 96 ms
40,176 KB
testcase_06 AC 97 ms
35,840 KB
testcase_07 AC 94 ms
39,944 KB
testcase_08 AC 196 ms
38,012 KB
testcase_09 AC 89 ms
37,892 KB
testcase_10 AC 96 ms
37,732 KB
testcase_11 AC 271 ms
37,908 KB
testcase_12 AC 220 ms
39,932 KB
testcase_13 AC 87 ms
38,004 KB
testcase_14 AC 93 ms
40,328 KB
testcase_15 AC 89 ms
38,016 KB
testcase_16 AC 211 ms
38,188 KB
testcase_17 AC 164 ms
38,096 KB
testcase_18 AC 351 ms
40,276 KB
testcase_19 AC 88 ms
39,596 KB
testcase_20 AC 92 ms
39,768 KB
testcase_21 AC 126 ms
40,320 KB
testcase_22 AC 114 ms
37,832 KB
testcase_23 AC 112 ms
39,848 KB
testcase_24 AC 118 ms
37,680 KB
testcase_25 AC 163 ms
37,744 KB
testcase_26 AC 280 ms
38,600 KB
testcase_27 AC 120 ms
40,000 KB
testcase_28 AC 152 ms
38,156 KB
testcase_29 AC 87 ms
38,012 KB
testcase_30 AC 93 ms
37,576 KB
testcase_31 AC 85 ms
37,984 KB
testcase_32 AC 157 ms
37,580 KB
evil_2_big_1.txt TLE -
evil_2_big_2.txt TLE -
evil_2_big_3.txt TLE -
evil_big_1.txt TLE -
evil_big_2.txt TLE -
evil_big_3.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

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