結果

問題 No.355 数当てゲーム(2)
ユーザー 14番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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
35,800 KB
testcase_01 AC 55 ms
35,544 KB
testcase_02 AC 55 ms
36,440 KB
testcase_03 AC 55 ms
35,928 KB
testcase_04 AC 55 ms
36,440 KB
testcase_05 AC 55 ms
35,840 KB
testcase_06 AC 57 ms
36,056 KB
testcase_07 AC 56 ms
35,928 KB
testcase_08 AC 53 ms
36,048 KB
testcase_09 AC 58 ms
36,312 KB
testcase_10 AC 54 ms
36,440 KB
testcase_11 AC 54 ms
36,184 KB
testcase_12 AC 56 ms
36,184 KB
testcase_13 AC 56 ms
36,440 KB
testcase_14 AC 54 ms
36,184 KB
testcase_15 AC 53 ms
36,184 KB
testcase_16 AC 54 ms
36,440 KB
testcase_17 AC 56 ms
35,928 KB
testcase_18 AC 55 ms
36,056 KB
testcase_19 AC 57 ms
36,312 KB
testcase_20 AC 57 ms
35,800 KB
testcase_21 AC 56 ms
35,928 KB
testcase_22 AC 55 ms
35,928 KB
testcase_23 AC 56 ms
35,800 KB
testcase_24 AC 56 ms
35,800 KB
testcase_25 AC 55 ms
36,184 KB
testcase_26 AC 56 ms
35,800 KB
testcase_27 AC 54 ms
36,184 KB
testcase_28 AC 54 ms
36,440 KB
testcase_29 AC 53 ms
35,928 KB
testcase_30 AC 55 ms
35,672 KB
testcase_31 AC 54 ms
35,672 KB
testcase_32 AC 55 ms
36,184 KB
testcase_33 AC 54 ms
36,056 KB
testcase_34 AC 54 ms
36,312 KB
testcase_35 AC 57 ms
36,320 KB
testcase_36 AC 55 ms
36,192 KB
testcase_37 AC 56 ms
36,192 KB
testcase_38 AC 56 ms
35,936 KB
testcase_39 AC 58 ms
36,192 KB
testcase_40 AC 57 ms
35,936 KB
testcase_41 AC 56 ms
36,064 KB
testcase_42 AC 54 ms
35,808 KB
testcase_43 AC 56 ms
35,680 KB
testcase_44 AC 55 ms
36,448 KB
testcase_45 AC 56 ms
35,664 KB
testcase_46 AC 55 ms
36,176 KB
testcase_47 AC 55 ms
36,048 KB
testcase_48 AC 58 ms
36,048 KB
testcase_49 AC 56 ms
35,664 KB
testcase_50 AC 54 ms
36,176 KB
testcase_51 AC 56 ms
36,304 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
    }
    
    /// 入力候補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