結果
問題 | No.545 ママの大事な二人の子供 |
ユーザー | tenten |
提出日時 | 2023-06-14 10:07:55 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 284 ms / 2,000 ms |
コード長 | 2,405 bytes |
コンパイル時間 | 2,681 ms |
コンパイル使用メモリ | 90,756 KB |
実行使用メモリ | 66,076 KB |
最終ジャッジ日時 | 2023-09-04 23:23:49 |
合計ジャッジ時間 | 7,768 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
49,816 KB |
testcase_01 | AC | 42 ms
49,552 KB |
testcase_02 | AC | 42 ms
49,888 KB |
testcase_03 | AC | 44 ms
49,768 KB |
testcase_04 | AC | 43 ms
49,576 KB |
testcase_05 | AC | 43 ms
49,532 KB |
testcase_06 | AC | 43 ms
49,896 KB |
testcase_07 | AC | 44 ms
49,980 KB |
testcase_08 | AC | 44 ms
49,940 KB |
testcase_09 | AC | 43 ms
49,596 KB |
testcase_10 | AC | 44 ms
49,900 KB |
testcase_11 | AC | 44 ms
49,604 KB |
testcase_12 | AC | 45 ms
49,852 KB |
testcase_13 | AC | 46 ms
49,636 KB |
testcase_14 | AC | 48 ms
49,804 KB |
testcase_15 | AC | 44 ms
49,552 KB |
testcase_16 | AC | 48 ms
49,792 KB |
testcase_17 | AC | 56 ms
50,372 KB |
testcase_18 | AC | 91 ms
53,296 KB |
testcase_19 | AC | 90 ms
53,308 KB |
testcase_20 | AC | 118 ms
53,384 KB |
testcase_21 | AC | 42 ms
49,580 KB |
testcase_22 | AC | 166 ms
58,152 KB |
testcase_23 | AC | 273 ms
63,540 KB |
testcase_24 | AC | 171 ms
57,932 KB |
testcase_25 | AC | 278 ms
63,612 KB |
testcase_26 | AC | 284 ms
66,076 KB |
testcase_27 | AC | 251 ms
63,372 KB |
testcase_28 | AC | 267 ms
63,636 KB |
testcase_29 | AC | 260 ms
63,260 KB |
testcase_30 | AC | 252 ms
63,356 KB |
testcase_31 | AC | 263 ms
62,832 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); TreeSet<Long> ev = new TreeSet<>(); TreeSet<Long> od = new TreeSet<>(); ev.add(0L); od.add(0L); long total = 0; for (int i = 0; i < n; i++) { long a = sc.nextLong(); long b = sc.nextLong(); total += a; b += a; TreeSet<Long> current; if (i % 2 == 0) { current = ev; } else { current = od; } Long key = Long.MAX_VALUE; while ((key = current.lower(key)) != null) { current.add(key + b); } } od.add(Long.MIN_VALUE / 2); od.add(Long.MAX_VALUE / 2); long ans = Long.MAX_VALUE; for (Long x : ev) { long target = total - x; ans = Math.min(ans, target - od.floor(target)); ans = Math.min(ans, od.ceiling(target) - target); } System.out.println(ans); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }