結果

問題 No.130 XOR Minimax
ユーザー NetSeedNetSeed
提出日時 2016-02-10 19:43:47
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,312 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 109,312 KB
実行使用メモリ 48,964 KB
最終ジャッジ日時 2024-09-21 23:57:53
合計ジャッジ時間 8,393 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.IO;
using System.Linq;

//全て1だったら?ってことで、1でフラグ立てきって、順序よくに倒していくパタンも診てみたら?

namespace ConsoleApplication2
{
	class Program
	{
		static void Main(string[] args)
		{
#if LOCAL
			foreach (var fileName in Enumerable.Range(1, 20).Select(x => "test" + x.ToString("00") + ".txt"))
			{
				Console.SetIn(new StreamReader(fileName));
				CandidateA();

			}

//			Console.SetIn(new StreamReader("test15.txt"));
#else
			CandidateA();
#endif
		}

		private static void CandidateB()
		{
			var mask = Enumerable.Range(0, 31).Select(x => 1 << x).Reverse().ToArray();
			Console.ReadLine();

			var original = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

			int[] candidate = null;


			for (int i = 0; i < 10; i++)
			{
				foreach (var m in mask)
				{
					var currentMax = original.Max();

					candidate = original.Select(x => x ^ m).ToArray();
					var candidateMax = candidate.Max();

					if (currentMax > candidateMax)
					{
						original = candidate;
					}
				}
				candidate = original;
				foreach (var m in mask.Reverse())
				{
					var currentMax = original.Max();

					candidate = original.Select(x => x ^ m).ToArray();
					var candidateMax = candidate.Max();

					if (currentMax > candidateMax)
					{
						original = candidate;
					}

				}

				candidate = original;
			}




			Console.WriteLine(candidate.Max());
		}


		private static void CandidateA()
		{
			var mask = Enumerable.Range(0, 31).Select(x => 1 << x).Reverse().ToArray();
			Console.ReadLine();

			var original = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
			var currentA = original.ToArray();
			var currentB = original.ToArray();
			var currentC = original.ToArray();
			var currentD = original.ToArray();

			int[] candidate;



			foreach (var m in mask)
			{
				var currentMax = currentA.Max();

				candidate = currentA.Select(x => x ^ m).ToArray();
				var candidateMax = candidate.Max();

				if (currentMax > candidateMax)
				{
					currentA = candidate;
				}
			}

			foreach (var m in mask.Reverse())
			{
				var currentMax = currentB.Max();

				candidate = currentB.Select(x => x ^ m).ToArray();
				var candidateMax = candidate.Max();

				if (currentMax > candidateMax)
				{
					currentB = candidate;
				}

			}

			foreach (var m in mask.Select(x=>x^int.MaxValue))
			{
				var currentMax = currentC.Max();

				candidate = currentC.Select(x => x ^ m).ToArray();
				var candidateMax = candidate.Max();

				if (currentMax > candidateMax)
				{
					currentC = candidate;
				}
			}

			foreach (var m in mask.Select(x=>x^int.MaxValue).Reverse())
			{
				var currentMax = currentD.Max();

				candidate = currentD.Select(x => x ^ m).ToArray();
				var candidateMax = candidate.Max();

				if (currentMax > candidateMax)
				{
					currentB = candidate;
				}

			}

			Console.WriteLine(currentA.Max());
			Console.WriteLine(currentB.Max());
			Console.WriteLine(currentC.Max());
			Console.WriteLine(currentD.Max());



			var hoge = Math.Min(Math.Min(currentA.Max(), currentB.Max()), Math.Min(currentC.Max(), currentD.Max()));


			Console.WriteLine(hoge);
			Console.WriteLine();
		}
	}
}
0