結果

問題 No.183 たのしい排他的論理和(EASY)
ユーザー aketijyuuzou
提出日時 2024-10-10 23:28:23
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,359 ms / 5,000 ms
コード長 1,866 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 113,676 KB
実行使用メモリ 32,248 KB
最終ジャッジ日時 2024-10-10 23:28:40
合計ジャッジ時間 16,842 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2");
            WillReturn.Add("1 2");
            //4
            //0=0
            //1=0 XOR 1
            //2=0 XOR 2
            //3=0 XOR 1 XOR 2
            //の4種類の値を作ることができます。
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("6");
            WillReturn.Add("1 1 4 5 1 4");
            //4
            //6つ整数が与えられても4種類しか作れない場合もあります
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        //0 XOR 0 XOR 0 = 0
        //0 XOR 1 XOR 1 = 0
        //1 XOR 0 XOR 0 = 1
        //1 XOR 1 XOR 1 = 1
        //よって、
        //A XOR B XOR B = A なので、
        //重複した値は、Distinctしておく
        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).Distinct().ToArray();

        //作成可否[整数]なDP表
        var PrevDP = new System.Collections.BitArray(16384 * 2 + 1);
        PrevDP[0] = true;

        foreach (int EachA in AArr) {
            var CurrDP = new System.Collections.BitArray(PrevDP);
            for (int I = 0; I <= PrevDP.Count - 1; I++) {
                if (PrevDP[I] == false) continue;
                int wkInd = EachA ^ I;
                CurrDP[wkInd] = true;
            }
            PrevDP = CurrDP;
        }
        Console.WriteLine(PrevDP.Cast<bool>().Count(X => X));
    }
}

0