結果

問題 No.513 宝探し2
ユーザー 14番14番
提出日時 2017-05-18 19:39:48
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,770 bytes
コンパイル時間 4,300 ms
コンパイル使用メモリ 107,464 KB
実行使用メモリ 255,632 KB
平均クエリ数 2.42
最終ジャッジ日時 2023-09-23 14:06:40
合計ジャッジ時間 8,666 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using System.Text;
    using System.Net;

     
    public class Program
    {
        public void Proc() {
            Reader.IsDebug = false;
            try {
                int posX = GetX(0, 100000);
                int posY = GetY(0, 100000);
                GetPos(posX, posY);
            } catch(Exception e) {

            }
        }

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

        private int GetY(int min, int max) {
            if(max-min<=1) {
                int num1 = GetPos(0,min);
                int num2 = GetPos(0,max);
                if(num1<=num2) {
                    return min;
                } else {
                    return max;
                }
            }
            int idx1 = min + ((max-min)/3);
            int idx2 = min + ((max-min)*2/3);

            int minPos = GetPos(0,min);
            int idx1Pos = GetPos(0,idx1);
            int idx2Pos = GetPos(0,idx2);
            int maxPos = GetPos(0,max);

            int[] arr = new int[]{minPos, idx1Pos, idx2Pos, maxPos};
            if(arr.Min() == minPos) {
                return GetX(min, idx1);
            } else if(arr.Min() == idx1Pos) {
                return GetX(min, idx2);
            } else if(arr.Min() == idx2Pos) {
                return GetX(idx1, maxPos);
            } else {
                return GetX(idx2, max);
            }
        }
        private int GetX(int min, int max) {
            if(max-min<=1) {
                int num1 = GetPos(min, 0);
                int num2 = GetPos(max, 0);
                if(num1<=num2) {
                    return min;
                } else {
                    return max;
                }
            }
            int idx1 = min + ((max-min)/3);
            int idx2 = min + ((max-min)*2/3);

            int minPos = GetPos(min, 0);
            int idx1Pos = GetPos(idx1, 0);
            int idx2Pos = GetPos(idx2, 0);
            int maxPos = GetPos(max, 0);

            int[] arr = new int[]{minPos, idx1Pos, idx2Pos, maxPos};
            if(arr.Min() == minPos) {
                return GetX(min, idx1);
            } else if(arr.Min() == idx1Pos) {
                return GetX(min, idx2);
            } else if(arr.Min() == idx2Pos) {
                return GetX(idx1, maxPos);
            } else {
                return GetX(idx2, max);
            }
        }

        private int GetPos(int x, int y) {
            if(!dic.ContainsKey(x)) {
                dic.Add(x, new Dictionary<int, int>());
            }
            if(dic[x].ContainsKey(y)) {
                return dic[x][y];
            }
            Console.WriteLine(x + " " + y);
            int ans = int.Parse(Reader.ReadLine());
            if(ans == 0) {
                throw new Exception();
            }
            dic[x][y] = ans;
            return ans;
        }


        public class Reader {
            public static bool IsDebug = true;
            private static System.IO.StringReader SReader;
            private static string InitText = @"







19 57
9
5 16 48 144 432 1296 3888 11664 34992






";
            public static string ReadLine() {
                if(IsDebug) {
                    if(SReader == null) {
                        SReader = new System.IO.StringReader(InitText.Trim());
                    }
                    return SReader.ReadLine();
                } else {
                    return Console.ReadLine();
                }
            }
        }
        public static void Main(string[] args)
        {
            Program prg = new Program();
            prg.Proc();
        }
    }
0