結果
問題 | No.703 ゴミ拾い Easy |
ユーザー | 37zigen |
提出日時 | 2018-06-16 08:10:59 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 326 ms / 1,500 ms |
コード長 | 3,293 bytes |
コンパイル時間 | 2,444 ms |
コンパイル使用メモリ | 78,664 KB |
実行使用メモリ | 69,192 KB |
最終ジャッジ日時 | 2024-06-10 18:31:42 |
合計ジャッジ時間 | 12,618 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
50,016 KB |
testcase_01 | AC | 52 ms
49,820 KB |
testcase_02 | AC | 52 ms
49,964 KB |
testcase_03 | AC | 53 ms
50,060 KB |
testcase_04 | AC | 53 ms
49,696 KB |
testcase_05 | AC | 53 ms
49,956 KB |
testcase_06 | AC | 53 ms
49,880 KB |
testcase_07 | AC | 53 ms
49,716 KB |
testcase_08 | AC | 53 ms
49,880 KB |
testcase_09 | AC | 54 ms
49,768 KB |
testcase_10 | AC | 53 ms
49,812 KB |
testcase_11 | AC | 53 ms
50,020 KB |
testcase_12 | AC | 53 ms
50,012 KB |
testcase_13 | AC | 54 ms
50,056 KB |
testcase_14 | AC | 58 ms
50,016 KB |
testcase_15 | AC | 58 ms
49,568 KB |
testcase_16 | AC | 57 ms
49,824 KB |
testcase_17 | AC | 60 ms
49,904 KB |
testcase_18 | AC | 59 ms
50,020 KB |
testcase_19 | AC | 60 ms
49,768 KB |
testcase_20 | AC | 58 ms
49,828 KB |
testcase_21 | AC | 58 ms
49,580 KB |
testcase_22 | AC | 61 ms
50,108 KB |
testcase_23 | AC | 59 ms
49,948 KB |
testcase_24 | AC | 279 ms
69,180 KB |
testcase_25 | AC | 278 ms
69,068 KB |
testcase_26 | AC | 291 ms
69,192 KB |
testcase_27 | AC | 304 ms
69,000 KB |
testcase_28 | AC | 241 ms
67,704 KB |
testcase_29 | AC | 257 ms
68,744 KB |
testcase_30 | AC | 278 ms
67,728 KB |
testcase_31 | AC | 283 ms
68,852 KB |
testcase_32 | AC | 258 ms
67,700 KB |
testcase_33 | AC | 259 ms
67,668 KB |
testcase_34 | AC | 305 ms
69,016 KB |
testcase_35 | AC | 326 ms
68,864 KB |
testcase_36 | AC | 295 ms
68,892 KB |
testcase_37 | AC | 279 ms
69,012 KB |
testcase_38 | AC | 233 ms
67,956 KB |
testcase_39 | AC | 288 ms
69,064 KB |
testcase_40 | AC | 281 ms
68,108 KB |
testcase_41 | AC | 247 ms
68,672 KB |
testcase_42 | AC | 270 ms
68,800 KB |
testcase_43 | AC | 292 ms
68,964 KB |
testcase_44 | AC | 54 ms
49,716 KB |
testcase_45 | AC | 54 ms
49,716 KB |
testcase_46 | AC | 278 ms
68,228 KB |
testcase_47 | AC | 319 ms
68,468 KB |
testcase_48 | AC | 59 ms
49,964 KB |
testcase_49 | AC | 60 ms
49,804 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.util.ArrayDeque; import java.util.Arrays; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { new Main().run(); } public void run() { Scanner sc = new Scanner(); int n = sc.nextInt(); long[] a = new long[n]; long[] x = new long[n]; long[] y = new long[n]; for (int i = 0; i < n; ++i) { a[i] = sc.nextLong(); } for (int i = 0; i < n; ++i) { x[i] = sc.nextLong(); } for (int i = 0; i < n; ++i) { y[i] = sc.nextLong(); } long[] d = new long[n]; Arrays.fill(d, Long.MAX_VALUE / 3); ArrayDeque<long[]> dq = new ArrayDeque<>(); for (int i = 0; i < n; ++i) { dq.addLast(new long[] { -2 * x[i], (i == 0 ? 0 : d[i - 1]) + x[i] * x[i] + y[i] * y[i] }); while (dq.size() >= 3) { long[] l1 = dq.pollLast(); long[] l2 = dq.pollLast(); long[] l3 = dq.pollLast(); if (-(l3[1] - l2[1]) * (l3[0] - l1[0]) >= -(l3[0] - l2[0]) * (l3[1] - l1[1])) { dq.addLast(l3); dq.addLast(l1); continue; } else { dq.addLast(l3); dq.addLast(l2); dq.addLast(l1); break; } } while (dq.size() >= 2) { long[] l1 = dq.pollFirst(); long[] l2 = dq.pollFirst(); if (-(l1[1] - l2[1]) <= a[i] * (l1[0] - l2[0])) { dq.addFirst(l2); } else { dq.addFirst(l2); dq.addFirst(l1); break; } } d[i] = Math.min(d[i], a[i] * a[i] + dq.peekFirst()[0] * a[i] + dq.peekFirst()[1]); } System.out.println(d[n - 1]); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } class Scanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } private void skipUnprintable() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; } public boolean hasNext() { skipUnprintable(); return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } int nextInt() { return (int) nextLong(); } } }