結果

問題 No.180 美しいWhitespace (2)
ユーザー GrenacheGrenache
提出日時 2016-07-04 19:27:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 101 ms / 5,000 ms
コード長 2,014 bytes
コンパイル時間 3,791 ms
コンパイル使用メモリ 79,108 KB
実行使用メモリ 39,108 KB
最終ジャッジ日時 2024-04-20 21:55:30
合計ジャッジ時間 7,586 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
37,008 KB
testcase_01 AC 54 ms
36,828 KB
testcase_02 AC 55 ms
37,172 KB
testcase_03 AC 54 ms
36,836 KB
testcase_04 AC 57 ms
37,100 KB
testcase_05 AC 62 ms
37,084 KB
testcase_06 AC 66 ms
37,192 KB
testcase_07 AC 69 ms
37,492 KB
testcase_08 AC 86 ms
38,076 KB
testcase_09 AC 101 ms
39,108 KB
testcase_10 AC 93 ms
38,216 KB
testcase_11 AC 93 ms
38,508 KB
testcase_12 AC 94 ms
38,364 KB
testcase_13 AC 95 ms
38,724 KB
testcase_14 AC 94 ms
38,552 KB
testcase_15 AC 94 ms
38,596 KB
testcase_16 AC 92 ms
38,580 KB
testcase_17 AC 97 ms
38,780 KB
testcase_18 AC 95 ms
38,652 KB
testcase_19 AC 96 ms
38,468 KB
testcase_20 AC 55 ms
36,992 KB
testcase_21 AC 54 ms
36,956 KB
testcase_22 AC 54 ms
37,072 KB
testcase_23 AC 56 ms
36,844 KB
testcase_24 AC 55 ms
37,228 KB
testcase_25 AC 55 ms
37,004 KB
testcase_26 AC 56 ms
37,200 KB
testcase_27 AC 55 ms
37,100 KB
testcase_28 AC 55 ms
37,228 KB
testcase_29 AC 54 ms
37,128 KB
testcase_30 AC 93 ms
38,320 KB
testcase_31 AC 93 ms
38,656 KB
testcase_32 AC 93 ms
38,372 KB
testcase_33 AC 92 ms
38,400 KB
testcase_34 AC 92 ms
38,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder180 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Printer pr = new Printer(System.out);

        int n = sc.nextInt();

        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
        	a[i] = sc.nextInt();
        	b[i] = sc.nextInt();
        }

        // 整数の三分探索
        long l = 0;
        long r = 1_000_000_000;
		while (r - l > 1) {
			long mid = l + (r - l) / 2;
			if (f(mid + 1, a, b) - f(mid, a, b) >= 0) {
				r = mid;
			} else {
				l = mid;
			}
		}

        pr.println(r);

        pr.close();
        sc.close();
    }

	private static long f(long x, int[] a, int[] b) {
		long min = Long.MAX_VALUE;
		long max = Long.MIN_VALUE;
		for (int i = 0; i < a.length; i++) {
			min = Math.min(min, (long)a[i] + b[i] * x);
			max = Math.max(max, (long)a[i] + b[i] * x);
		}

		return max - min;
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0