結果

問題 No.594 壊れた宝物発見機
ユーザー バカらっくバカらっく
提出日時 2017-11-10 23:52:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 2,772 bytes
コンパイル時間 2,957 ms
コンパイル使用メモリ 109,056 KB
実行使用メモリ 40,312 KB
平均クエリ数 50.70
最終ジャッジ日時 2023-09-23 14:58:43
合計ジャッジ時間 8,142 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 176 ms
40,120 KB
testcase_01 AC 170 ms
38,016 KB
testcase_02 AC 173 ms
38,060 KB
testcase_03 AC 174 ms
39,868 KB
testcase_04 AC 176 ms
40,312 KB
testcase_05 AC 177 ms
37,828 KB
testcase_06 AC 177 ms
37,864 KB
testcase_07 AC 171 ms
39,960 KB
testcase_08 AC 174 ms
37,908 KB
testcase_09 AC 174 ms
37,652 KB
testcase_10 AC 169 ms
37,608 KB
testcase_11 AC 173 ms
39,756 KB
testcase_12 AC 177 ms
38,060 KB
testcase_13 AC 175 ms
37,724 KB
testcase_14 AC 174 ms
36,028 KB
testcase_15 AC 172 ms
38,224 KB
testcase_16 AC 171 ms
36,048 KB
testcase_17 AC 173 ms
39,760 KB
testcase_18 AC 175 ms
37,780 KB
testcase_19 AC 174 ms
38,268 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.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[4].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