結果

問題 No.3018 目隠し宝探し
ユーザー 鳩でもわかるC#
提出日時 2025-01-28 19:16:01
言語 C#
(.NET 8.0.404)
結果
WA  
実行時間 -
コード長 1,950 bytes
コンパイル時間 13,756 ms
コンパイル使用メモリ 174,416 KB
実行使用メモリ 55,928 KB
平均クエリ数 2.82
最終ジャッジ日時 2025-01-28 19:16:20
合計ジャッジ時間 19,107 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15 WA * 1 RE * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (95 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string ReadLine()
    {
        return Console.ReadLine().Trim();
    }

    static void Main()
    {
        int H, W;
        {
            int[] vs = ReadLine().Split().Select(_ => int.Parse(_)).ToArray();
            H = vs[0];
            W = vs[1];
        }

        bool[,] grid = new bool[H, W];
        for (int row = 0; row < H; row++)
        {
            for (int col = 0; col < W; col++)
                grid[row, col] = true;
        }

        int y = 0;
        int x = 0;

        Console.WriteLine($"? {y+1} {x + 1}");
        int d = int.Parse(ReadLine());
        if (d == 0)
        {
            Console.WriteLine($"! {y + 1} {x + 1}");
            return;
        }
        if (d == -1)
            return;

        Check(grid, H, W, y, x, d);

        x = W - 1;
        Console.WriteLine($"? {y + 1} {x + 1}");
        d = int.Parse(ReadLine());
        if (d == 0)
        {
            Console.WriteLine($"! {y + 1} {x + 1}");
            return;
        }
        if (d == -1)
            return;

        Check(grid, H, W, y, x, d);
    }

    static void Check(bool[,] grid, int H, int W, int y, int x, int d)
    {
        for (int row = 0; row < H; row++)
        {
            for (int col = 0; col < W; col++)
            {
                if ((row - y) * (row - y) + (col - x) * (col - x) != d)
                    grid[row, col] = false;
            }
        }

        int hit = 0;
        int hitX = 0;
        int hitY = 0;
        for (int row = 0; row < H; row++)
        {
            for (int col = 0; col < W; col++)
            {
                if (grid[row, col])
                {
                    hit++;
                    hitY = row;
                    hitX = col;
                }
            }
        }
        if (hit == 1)
            Console.WriteLine($"! {hitY + 1} {hitX + 1}");
    }
}

0