結果

問題 No.2962 Sum Bomb Bomber
ユーザー tenten
提出日時 2024-11-18 16:08:43
言語 Java
(openjdk 23)
結果
AC  
実行時間 260 ms / 2,000 ms
コード長 2,351 bytes
コンパイル時間 3,092 ms
コンパイル使用メモリ 78,976 KB
実行使用メモリ 57,664 KB
平均クエリ数 189.09
最終ジャッジ日時 2024-11-18 16:09:09
合計ジャッジ時間 22,271 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 64
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int x = getValue(true, sc);
        int y = getValue(false, sc);
        System.out.println("2 " + x + " " + y);
        System.out.flush();
    }
    
    static int getValue(boolean isX, Scanner sc) {
        int left = -100000000;
        int right = 100000000;
        while (right - left > 2) {
            int m1 = (left * 2 + right) / 3;
            int m2 = (left + right * 2) / 3;
            System.out.println(getQuery(m1, isX));
            System.out.flush();
            long r1 = sc.nextLong();
            System.out.println(getQuery(m2, isX));
            System.out.flush();
            long r2 = sc.nextLong();
            if (r1 < r2) {
                right = m2;
            } else {
                left = m1;
            }
        }
        int ans = 0;
        long min = Long.MAX_VALUE;
        for (int i = left; i <= right; i++) {
            System.out.println(getQuery(i, isX));
            System.out.flush();
            long r = sc.nextLong();
            if (min > r) {
                min = r;
                ans = i;
            }
        }
        return ans;
    }
    
    static String getQuery(int value, boolean isX) {
        if (isX) {
            return "1 " + value + " 0";
        } else {
            return "1 0 " + value;
        }
    }
}

class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}


0