結果

問題 No.183 たのしい排他的論理和(EASY)
ユーザー 紙ぺーぱー紙ぺーぱー
提出日時 2015-04-07 03:34:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 74 ms / 5,000 ms
コード長 1,913 bytes
コンパイル時間 3,034 ms
コンパイル使用メモリ 106,488 KB
実行使用メモリ 24,136 KB
最終ジャッジ日時 2023-09-11 10:58:23
合計ジャッジ時間 5,709 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
21,436 KB
testcase_01 AC 62 ms
21,564 KB
testcase_02 AC 62 ms
21,448 KB
testcase_03 AC 61 ms
21,500 KB
testcase_04 AC 62 ms
21,640 KB
testcase_05 AC 62 ms
23,544 KB
testcase_06 AC 62 ms
21,580 KB
testcase_07 AC 72 ms
21,904 KB
testcase_08 AC 71 ms
21,876 KB
testcase_09 AC 71 ms
21,960 KB
testcase_10 AC 71 ms
22,024 KB
testcase_11 AC 73 ms
24,120 KB
testcase_12 AC 62 ms
21,680 KB
testcase_13 AC 61 ms
21,520 KB
testcase_14 AC 71 ms
21,980 KB
testcase_15 AC 74 ms
21,980 KB
testcase_16 AC 63 ms
21,708 KB
testcase_17 AC 71 ms
21,884 KB
testcase_18 AC 73 ms
24,136 KB
testcase_19 AC 70 ms
21,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

static public class Program
{
    static public void Main()
    {
        var n = readInteger().Validate(x => 1 <= x && x <= 100000);
        var a = readLong(n).ValidateArray(x => 1 <= x && x <= 1L << 60);
        readEOF();
        var b = new List<long>[65];
        for (int i = 0; i < 65; i++)
            b[i] = new List<long>();
        foreach (var x in a)
        {
            var v = x;
            for (int i = 0; i < 64 && 0 < v; i++)
            {
                if (((v >> i) & 1) == 0)
                    continue;
                if (b[i].Count > 0)
                    v ^= b[i][0];
                else
                {
                    b[i].Add(v);
                    break;
                }
            }
        }
        Console.WriteLine(1L << b.Count(x => x.Count > 0));

    }

    static int readInteger()
    {
        var s = Console.ReadLine();
        return int.Parse(s);
    }
    static long[] readLong(int n, params char[] sep)
    {
        var s = Console.ReadLine().Split(sep);
        if (s.Length != n)
            throw new Exception(string.Format("invalid input, expected{0} actual{1}", n, s.Length));
        var ret = new long[n];
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(s[i]);
        return ret;
    }
    static void readEOF()
    {
        if (Console.In.Peek() >= 0)
            throw new Exception("invalid input too long input file");
    }

}
static public class Ex
{
    static public T Validate<T>(this T input, Func<T, bool> f)
    {
        if (!f(input))
            throw new Exception("invalid input");
        return input;
    }
    static public T[] ValidateArray<T>(this T[] input, Func<T, bool> f)
    {
        foreach (var x in input)
            if (!f(x))
                throw new Exception("invalid input");
        return input;
    }
}

0