結果
問題 | No.885 アマリクエリ |
ユーザー | tenten |
提出日時 | 2023-06-20 09:12:49 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,341 ms / 2,000 ms |
コード長 | 2,332 bytes |
コンパイル時間 | 3,690 ms |
コンパイル使用メモリ | 91,408 KB |
実行使用メモリ | 79,120 KB |
最終ジャッジ日時 | 2023-09-10 04:32:13 |
合計ジャッジ時間 | 13,553 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 288 ms
57,364 KB |
testcase_01 | AC | 1,300 ms
77,752 KB |
testcase_02 | AC | 622 ms
64,164 KB |
testcase_03 | AC | 362 ms
61,176 KB |
testcase_04 | AC | 354 ms
60,932 KB |
testcase_05 | AC | 308 ms
60,248 KB |
testcase_06 | AC | 268 ms
56,524 KB |
testcase_07 | AC | 323 ms
62,824 KB |
testcase_08 | AC | 242 ms
56,296 KB |
testcase_09 | AC | 1,341 ms
79,120 KB |
testcase_10 | AC | 45 ms
49,832 KB |
testcase_11 | AC | 45 ms
49,944 KB |
testcase_12 | AC | 44 ms
49,852 KB |
testcase_13 | AC | 122 ms
54,532 KB |
testcase_14 | AC | 117 ms
54,376 KB |
testcase_15 | AC | 114 ms
54,388 KB |
testcase_16 | AC | 71 ms
51,700 KB |
testcase_17 | AC | 75 ms
51,672 KB |
testcase_18 | AC | 91 ms
52,824 KB |
testcase_19 | AC | 69 ms
51,916 KB |
testcase_20 | AC | 60 ms
51,440 KB |
testcase_21 | AC | 96 ms
52,560 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(); TreeMap<Integer, Integer> counts = new TreeMap<>(); long total = 0; for (int i = 0; i < n; i++) { int x = sc.nextInt(); total += x; counts.put(x, counts.getOrDefault(x, 0) + 1); } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (q-- > 0) { int x = sc.nextInt(); while (counts.size() > 0 && counts.lastKey() >= x) { int y = counts.lastKey(); int size = counts.get(y); counts.remove(y); total -= (long)y * size; y %= x; total += (long)y * size; if (y > 0) { counts.put(y, counts.getOrDefault(y, 0) + size); } } sb.append(total).append("\n"); } System.out.print(sb); } } 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(); } }