結果
問題 | No.1012 荷物収集 |
ユーザー | tenten |
提出日時 | 2023-04-11 08:23:19 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 741 ms / 2,000 ms |
コード長 | 3,131 bytes |
コンパイル時間 | 2,865 ms |
コンパイル使用メモリ | 91,752 KB |
実行使用メモリ | 69,068 KB |
最終ジャッジ日時 | 2024-04-16 08:23:46 |
合計ジャッジ時間 | 24,216 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
50,840 KB |
testcase_01 | AC | 70 ms
50,900 KB |
testcase_02 | AC | 69 ms
51,124 KB |
testcase_03 | AC | 69 ms
51,228 KB |
testcase_04 | AC | 510 ms
67,440 KB |
testcase_05 | AC | 516 ms
67,084 KB |
testcase_06 | AC | 499 ms
67,512 KB |
testcase_07 | AC | 503 ms
67,532 KB |
testcase_08 | AC | 505 ms
67,264 KB |
testcase_09 | AC | 512 ms
67,244 KB |
testcase_10 | AC | 508 ms
67,264 KB |
testcase_11 | AC | 499 ms
66,948 KB |
testcase_12 | AC | 505 ms
67,328 KB |
testcase_13 | AC | 497 ms
67,184 KB |
testcase_14 | AC | 82 ms
51,252 KB |
testcase_15 | AC | 97 ms
51,796 KB |
testcase_16 | AC | 86 ms
51,144 KB |
testcase_17 | AC | 93 ms
52,032 KB |
testcase_18 | AC | 88 ms
51,484 KB |
testcase_19 | AC | 81 ms
51,052 KB |
testcase_20 | AC | 85 ms
51,328 KB |
testcase_21 | AC | 90 ms
51,620 KB |
testcase_22 | AC | 88 ms
50,952 KB |
testcase_23 | AC | 84 ms
51,088 KB |
testcase_24 | AC | 627 ms
67,120 KB |
testcase_25 | AC | 692 ms
67,316 KB |
testcase_26 | AC | 442 ms
61,588 KB |
testcase_27 | AC | 253 ms
58,100 KB |
testcase_28 | AC | 686 ms
68,900 KB |
testcase_29 | AC | 456 ms
61,436 KB |
testcase_30 | AC | 709 ms
68,408 KB |
testcase_31 | AC | 436 ms
65,932 KB |
testcase_32 | AC | 399 ms
61,596 KB |
testcase_33 | AC | 507 ms
65,648 KB |
testcase_34 | AC | 542 ms
67,004 KB |
testcase_35 | AC | 632 ms
66,152 KB |
testcase_36 | AC | 504 ms
67,020 KB |
testcase_37 | AC | 457 ms
61,596 KB |
testcase_38 | AC | 616 ms
65,872 KB |
testcase_39 | AC | 393 ms
58,976 KB |
testcase_40 | AC | 435 ms
63,532 KB |
testcase_41 | AC | 741 ms
69,068 KB |
testcase_42 | AC | 471 ms
65,704 KB |
testcase_43 | AC | 589 ms
65,752 KB |
testcase_44 | AC | 69 ms
51,284 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(); int q = sc.nextInt(); Point[] points = new Point[n + q]; for (int i = 0; i < n; i++) { points[i] = new Point(0, sc.nextInt(), sc.nextInt()); } for (int i = n; i < n + q; i++) { points[i] = new Point(i - n, sc.nextInt(), 0); } Arrays.sort(points); long[] ans = new long[q]; long leftWeight = 0; long leftSum = 0; int leftPrev = 0; for (int i = 0; i < n + q; i++) { leftSum += (points[i].position - leftPrev) * leftWeight; leftWeight += points[i].weight; leftPrev = points[i].position; if (points[i].weight == 0) { ans[points[i].idx] += leftSum; } } long rightWeight = 0; long rightSum = 0; int rightPrev = 0; for (int i = n + q - 1; i >= 0; i--) { rightSum += (rightPrev - points[i].position) * rightWeight; rightWeight += points[i].weight; rightPrev = points[i].position; if (points[i].weight == 0) { ans[points[i].idx] += rightSum; } } System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new))); } static class Point implements Comparable<Point> { int idx; int position; int weight; public Point(int idx, int position, int weight) { this.idx = idx; this.position = position; this.weight = weight; } public int compareTo(Point another) { return position - another.position; } } } 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(); } }