結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー |
![]() |
提出日時 | 2020-02-14 22:08:50 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,761 bytes |
コンパイル時間 | 2,487 ms |
コンパイル使用メモリ | 79,688 KB |
実行使用メモリ | 64,948 KB |
最終ジャッジ日時 | 2024-11-16 00:46:31 |
合計ジャッジ時間 | 7,413 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 RE * 1 |
other | AC * 10 RE * 9 |
ソースコード
import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.Arrays;import java.util.HashMap;import java.util.Map;public class Main {public static void main(String[] args) throws Exception {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));String[] sa = br.readLine().split(" ");int n = Integer.parseInt(sa[0]);int m = Integer.parseInt(sa[1]);int k = Integer.parseInt(sa[2]);sa = br.readLine().split(" ");String s = sa[0];long[] b = new long[m];for (int i = 0; i < b.length; i++) {b[i] = Long.parseLong(sa[i + 1]);}long[] a = new long[n];for (int i = 0; i < a.length; i++) {a[i] = Long.parseLong(br.readLine());}br.close();if ("+".equals(s)) {for (int i = 0; i < a.length; i++) {a[i] %= k;}double[] d = new double[m];for (int i = 0; i < b.length; i++) {d[i] = b[i] % k;}Arrays.parallelSort(a);Arrays.parallelSort(d);long ans = 0;for (int i = 0; i < a.length; i++) {long v = k - a[i];v %= k;int idx1 = Arrays.binarySearch(d, v - 0.5);idx1 = ~idx1;int idx2 = Arrays.binarySearch(d, v + 0.5);idx2 = ~idx2;ans += idx2 - idx1;}System.out.println(ans);} else {Map<Integer, Integer> soinsu = bunkai(k);throw new Exception();}}static Map<Integer, Integer> bunkai(int n) {Map<Integer, Integer> soinsu = new HashMap<>();int end = (int) Math.sqrt(n);int d = 2;while (n > 1) {if (n % d == 0) {n /= d;if (soinsu.containsKey(d)) {soinsu.put(d, soinsu.get(d) + 1);} else {soinsu.put(d, 1);}end = (int) Math.sqrt(n);} else {if (d > end) {d = n - 1;}d++;}}return soinsu;}}