結果
| 問題 |
No.594 壊れた宝物発見機
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2017-11-10 23:52:48 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 140 ms / 2,000 ms |
| コード長 | 2,772 bytes |
| コンパイル時間 | 917 ms |
| コンパイル使用メモリ | 115,860 KB |
| 実行使用メモリ | 44,024 KB |
| 平均クエリ数 | 50.70 |
| 最終ジャッジ日時 | 2024-07-16 14:38:15 |
| 合計ジャッジ時間 | 4,930 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
バカらっく