結果

問題 No.355 数当てゲーム(2)
ユーザー 14番
提出日時 2016-05-27 07:52:44
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 7,008 bytes
コンパイル時間 2,345 ms
コンパイル使用メモリ 116,420 KB
実行使用メモリ 36,448 KB
平均クエリ数 25.06
最終ジャッジ日時 2024-07-16 23:47:03
合計ジャッジ時間 8,027 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 52
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text;
using System.Linq;
class Program
{
public void Proc()
{
Reader.IsDebug = false;
this.FirstStep();
}
private bool FirstStep(){
Console.WriteLine("1 2 3 4");
int[] ret1 = GetInput();
if(ret1[0] == 4) {
return true;
} else if(ret1.Sum() == 4) {
this.InList.AddRange(new int[]{1,2,3,4});
return ProcLast4();
} else if(ret1.Sum() == 0) {
this.OutList.AddRange(new int[]{1,2,3,4});
return this.ProcOut3();
} else if(ret1.Sum() == 1) {
return this.ProcIn1_Out3(new int[]{1,2,3,4});
} else if(ret1.Sum() == 3)
{
return this.ProcIn3_Out1(new int[]{1,2,3,4});
}
Console.WriteLine("5 6 7 8");
int[] ret2 = GetInput();
if(ret2[0] == 4) {
return true;
} else if(ret2.Sum() == 4) {
this.InList.AddRange(new int[]{5,6,7,8});
return ProcLast4();
} else if(ret2.Sum() == 0) {
this.OutList.AddRange(new int[]{5,6,7,8});
return this.ProcOut3();
} else if(ret2.Sum() == 1) {
return this.ProcIn1_Out3(new int[]{5,6,7,8});
} else if(ret2.Sum() == 3) {
return this.ProcIn3_Out1(new int[]{5,6,7,8});
}
Console.WriteLine("9 0 1 2");
int[] ret3 = GetInput();
if(ret3[0] == 4) {
return true;
} else if(ret3.Sum() == 4) {
this.InList.AddRange(new int[]{9,0,1,2});
return ProcLast4();
} else if(ret3.Sum() == 0) {
this.OutList.AddRange(new int[]{9,0,1,2});
return this.ProcOut3();
} else if(ret3.Sum() == 1) {
return this.ProcIn1_Out3(new int[]{9,0,1,2});
} else if(ret3.Sum() == 3) {
return this.ProcIn3_Out1(new int[]{9,0,1,2});
}
List<int> ng = new List<int>(new int[]{9,0, 3, 4});
this.OutList.AddRange(ng);
return this.ProcOut3();
}
private bool ProcIn3_Out1(int[] target) {
List<int> otherList = new List<int>(BaseNumList.Where(a=>!target.Contains(a)).Take(2));
foreach (int item in target)
{
int min = int.MaxValue;
foreach (int hikaku in otherList)
{
List<int> subList = new List<int>(target);
subList.Remove(item);
subList.Add(hikaku);
Console.WriteLine(string.Join(" ", subList));
int[] ret = GetInput();
if(ret[0] == 4) {
return true;
}
if(ret.Sum() == 4) {
this.InList.Clear();
this.InList.AddRange(subList);
return this.ProcLast4();
}
min = Math.Min(min, ret.Sum());
}
if(min == 3) {
this.InList.Clear();
this.InList.AddRange(target);
this.InList.Remove(item);
return this.ProcIn3();
}
}
return true;
}
private bool ProcIn3() {
List<int> target = new List<int>(BaseNumList.Where(a=>!InList.Contains(a)));
foreach (int item in target)
{
List<int> temp = new List<int>(InList.Take(3));
temp.Add(item);
Console.WriteLine(string.Join(" ", temp));
int[] ret = GetInput();
if(ret[0] == 4) {
return true;
}
if(ret.Sum() == 4) {
InList.Add(item);
return this.ProcLast4();
}
}
return true;
}
private bool ProcIn1_Out3(int[] target) {
List<int> hikaku = new List<int>(BaseNumList.Where(a=>!target.ToList().Contains(a)).Take(4));
for(int i=0; i<target.Length; i++) {
int maxVal = int.MaxValue;
for(int j=0; j<hikaku.Count; j++) {
List<int> tmp = new List<int>(target);
tmp.RemoveAt(i);
tmp.Add(hikaku[j]);
Console.WriteLine(string.Join(" ", tmp));
int[] ret = GetInput();
maxVal = Math.Min(maxVal, ret.Sum());
}
if(maxVal == 0) {
this.OutList.Clear();
this.OutList.AddRange(target);
this.OutList.RemoveAt(i);
return this.ProcOut3();
}
}
return true;
}
private bool ProcOut3() {
List<int> target = new List<int>(BaseNumList.Where(a=>!OutList.Contains(a)));
foreach (int num in target)
{
List<int> tmp = new List<int>(this.OutList.Take(3));
tmp.Add(num);
Console.WriteLine(string.Join(" ", tmp));
int[] ret = GetInput();
if(ret.Sum() > 0) {
if(!InList.Contains(num)) {
InList.Add(num);
if(InList.Count == 4) {
return ProcLast4();
}
}
}
}
return true;
}
///
private bool ProcLast4() {
OutList.Clear();
OutList.AddRange(BaseNumList);
InList.ForEach(a=>OutList.Remove(a));
int[] ans = new int[4];
for(int i=0; i<InList.Count; i++) {
for(int j=0; j<4; j++) {
List<int> tmp = new List<int>();
tmp.AddRange(OutList.Take(3));
tmp.Insert(j, InList[i]);
Console.WriteLine(string.Join(" ", tmp));
int[] ret = this.GetInput();
if(ret[0] == 1) {
ans[j] = InList[i];
break;
}
}
}
Console.WriteLine(string.Join(" ", ans));
return true;
}
private int[] GetInput() {
return Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
}
private List<int> OutList = new List<int>();
private List<int> InList = new List<int>();
private int[] BaseNumList = new int[]{0,1,2,3,4,5,6,7,8,9};
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
2 3
";
private static System.IO.StringReader Sr = null;
public static string ReadLine()
{
if (IsDebug)
{
if (Sr == null)
{
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
}
static void Main()
{
Program prg = new Program();
prg.Proc();
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0