結果

問題 No.355 数当てゲーム(2)
ユーザー 14番14番
提出日時 2016-05-27 07:51:57
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 6,976 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 118,092 KB
実行使用メモリ 44,052 KB
平均クエリ数 2.00
最終ジャッジ日時 2024-07-16 10:11:31
合計ジャッジ時間 14,402 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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()
    {
        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;
    }
    
    /// 入力候補4つが確定している
    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();
    }
}
0