結果

問題 No.594 壊れた宝物発見機
ユーザー バカらっくバカらっく
提出日時 2017-11-10 23:51:36
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,772 bytes
コンパイル時間 3,339 ms
コンパイル使用メモリ 105,168 KB
実行使用メモリ 39,948 KB
平均クエリ数 1.00
最終ジャッジ日時 2023-09-23 14:58:19
合計ジャッジ時間 7,772 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] ans = new int[3];
        for (int i = 0; i < ans.Length; i++) {
            ans[i] = GetNum(-100, 100, i + 1);
        }
        Console.WriteLine("! " + string.Join(" ", ans));
    }


    private Dictionary<int, Dictionary<int, long>> dic = new Dictionary<int, Dictionary<int, long>>();

    private int GetNum(int min, int max, int idx) {
        int idx1 = min + (max - min) / 3;
        int idx2 = min + 2 * (max - min) / 3;

        long[] nums = new long[4];
        nums[0] = GetQuery(min, idx);
        nums[1] = GetQuery(idx1, idx);
        nums[2] = GetQuery(idx2, idx);
        nums[3] = GetQuery(max, idx);

        long minVal = nums.Min();

        if(nums[0] == minVal) {
            if(idx1-min<=1) {
                return min;
            }
            return GetNum(min, idx1, idx);
        }
        if(nums[1] == minVal) {
            if(idx1-min<=1&&idx2-idx1<=1) {
                return idx1;
            }
            return GetNum(min, idx2, idx);
        }
        if(nums[2] == minVal) {
            if(idx2-idx1<=1&&max-idx2<=1) {
                return idx2;
            }
            return GetNum(idx1, max, idx);
        }
        if(max-idx2<=1) {
            return max;
        }
        return GetNum(idx2, max, idx);

    }

    private long GetQuery(int num , int idx) {
        if(!dic.ContainsKey(num)) {
            dic.Add(num, new Dictionary<int, long>());
        }
        if(dic[num].ContainsKey(idx)) {
            return dic[num][idx];
        }
        String[] command = new string[3].Select(a => "0").ToArray();
        command[0] = "?";
        command[idx] = num.ToString();
        Console.WriteLine(string.Join(" ", command));
        long ans = long.Parse(Reader.ReadLine());
        if(ans < 0) {
            throw new Exception("valid inpt :" + string.Join(" ", command));
        }
        dic[num][idx] = ans;
        return ans;
    }
    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}
0