結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ks2mks2m
提出日時 2020-02-14 22:08:50
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,761 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 79,536 KB
実行使用メモリ 63,560 KB
最終ジャッジ日時 2024-04-27 19:42:19
合計ジャッジ時間 6,101 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,920 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 48 ms
50,416 KB
testcase_04 RE -
testcase_05 AC 54 ms
49,948 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 48 ms
50,268 KB
testcase_09 AC 47 ms
50,496 KB
testcase_10 AC 263 ms
59,328 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 333 ms
49,668 KB
testcase_15 AC 236 ms
47,096 KB
testcase_16 AC 297 ms
48,392 KB
testcase_17 AC 221 ms
47,152 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 385 ms
54,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
	}
}
0