結果

問題 No.3018 目隠し宝探し
ユーザー tobisatis
提出日時 2025-01-25 14:57:44
言語 C#
(.NET 8.0.404)
結果
RE  
実行時間 -
コード長 2,868 bytes
コンパイル時間 19,825 ms
コンパイル使用メモリ 171,492 KB
実行使用メモリ 58,896 KB
平均クエリ数 1.09
最終ジャッジ日時 2025-01-25 23:37:16
合計ジャッジ時間 22,188 ms
ジャッジサーバーID
(参考情報)
judge13 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other AC * 2 RE * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (108 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

#nullable enable

using System.Numerics;

var _backend_ = new StandardIOBackend();

object? Solve()
{
    var h = Int();
    var w = Int();
    int Query(int x, int y)
    {
        Out("? " + x + " " + y);
        _backend_.Flush();
        return Int();
    }
    void Answer(int x, int y)
    {
        Out("! " + x + " " + y);
    }
    static int D(int x0, int y0, int x1, int y1)
    {
        var dx = x0 - x1;
        var dy = y0 - y1;
        return dx * dx + dy * dy;
    }
    var d0 = Query(1, 1);
    if (d0 == 0)
    {
        Answer(1, 1);
        return null;
    }
    var c0 = new List<(int, int)>();
    for (var i = 1; i <= h; i++) for (var j = 1; j <= w; j++)
    {
        if (D(i, j, 1, 1) == d0) c0.Add((i, j));
    }
    var g1 = new int[h, w];
    var mc = int.MaxValue;
    for (var i = 1; i <= h; i++) for (var j = 1; j <= w; j++)
    {
        foreach (var (ci, cj) in c0)
        {
            if (D(i, j, ci, cj) == d0) g1[i, j]++;
        }
        if (g1[i, j] > 0) mc = Math.Min(mc, g1[i, j]);
    }
    var f = true;
    for (var i = 1; i <= h; i++) for (var j = 1; j <= w; j++)
    {
        if (g1[i, j] == mc)
        {
            var d1 = -1;
            if (f)
            {
                 d1 = Query(i, j);
                 f = false;
            }
            else d1 = 0;
            if (d1 == 0)
            {
                Answer(i, j);
                break;
            }
        }
    }
    return null;
}

#region
AtCoderIO _io_;
_io_ = new(){ Backend = _backend_ };
Out(Solve());
_backend_.Flush();

string String() => _io_.Next();
int Int() => int.Parse(String());
void Out(object? x, string? sep = null) => _io_.Out(x, sep ?? Environment.NewLine);

class AtCoderIO
{
    public required StandardIOBackend Backend { get; init; }

    Memory<string> _input = Array.Empty<string>();
    int _iter = 0;
    public string Next()
    {
        while (_iter >= _input.Length) (_input, _iter) = (Backend.ReadLine().Trim().Split(' '), 0);
        return _input.Span[_iter++];
    }

    public void Out(object? x, string separator)
    {
        if (x == null) return;
        if (x is System.Collections.IEnumerable a and not string)
        {
            var objects = a.Cast<object>();
            if (!objects.Any()) return;
            x = string.Join(separator, objects);
        }
        Backend.WriteLine(x);
    }
}

class StandardIOBackend
{
    readonly StreamReader _sr = new(Console.OpenStandardInput());
    readonly StreamWriter _sw = new(Console.OpenStandardOutput()) { AutoFlush = false };
    public string ReadLine() => _sr.ReadLine()!;
    public void WriteLine(object? value) => _sw.WriteLine(value);
    public void Flush() => _sw.Flush();
}
#endregion

static class Extensions
{
    public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
}
0