結果
| 問題 |
No.183 たのしい排他的論理和(EASY)
|
| コンテスト | |
| ユーザー |
紙ぺーぱー
|
| 提出日時 | 2015-04-13 06:07:14 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 611 ms / 5,000 ms |
| コード長 | 1,675 bytes |
| コンパイル時間 | 887 ms |
| コンパイル使用メモリ | 115,808 KB |
| 実行使用メモリ | 47,988 KB |
| 最終ジャッジ日時 | 2024-06-29 01:41:38 |
| 合計ジャッジ時間 | 6,686 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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.
ソースコード
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 <= 5000);
var a = readInteger(n).ValidateArray(x => 1 <= x && x <= 16384);
readEOF();
var dp = new bool[32768];
dp[0] = true;
foreach (var x in a)
{
var next = new bool[32768];
for (int i = 0; i < dp.Length; i++)
if (dp[i])
next[i] = next[i ^ x] = true;
dp = next;
}
var cnt = dp.Count(x => x);
Console.WriteLine(cnt);
}
static int readInteger()
{
var s = Console.ReadLine();
return int.Parse(s);
}
static int[] readInteger(int n)
{
var s = Console.ReadLine().Split(' ');
if (s.Length != n)
throw new Exception(string.Format("invalid input, expected{0} actual{1}", n, s.Length));
var ret = new int[n];
for (int i = 0; i < n; i++)
ret[i] = int.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;
}
}
紙ぺーぱー