結果

問題 No.854 公平なりんご分配
ユーザー ks2mks2m
提出日時 2019-07-26 23:05:40
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 2,214 bytes
コンパイル時間 4,727 ms
コンパイル使用メモリ 75,216 KB
実行使用メモリ 551,104 KB
最終ジャッジ日時 2023-09-15 04:04:52
合計ジャッジ時間 93,952 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,164 KB
testcase_01 AC 46 ms
49,252 KB
testcase_02 AC 46 ms
47,420 KB
testcase_03 AC 47 ms
49,252 KB
testcase_04 AC 47 ms
49,312 KB
testcase_05 AC 45 ms
49,272 KB
testcase_06 AC 45 ms
49,248 KB
testcase_07 AC 46 ms
49,568 KB
testcase_08 AC 46 ms
49,280 KB
testcase_09 AC 46 ms
49,636 KB
testcase_10 AC 46 ms
49,304 KB
testcase_11 AC 45 ms
49,468 KB
testcase_12 AC 52 ms
50,280 KB
testcase_13 AC 53 ms
50,216 KB
testcase_14 AC 46 ms
49,264 KB
testcase_15 AC 47 ms
49,208 KB
testcase_16 AC 53 ms
49,908 KB
testcase_17 AC 53 ms
50,828 KB
testcase_18 AC 52 ms
50,044 KB
testcase_19 AC 52 ms
51,064 KB
testcase_20 AC 52 ms
50,088 KB
testcase_21 AC 51 ms
50,108 KB
testcase_22 AC 125 ms
52,744 KB
testcase_23 AC 136 ms
55,104 KB
testcase_24 AC 188 ms
57,992 KB
testcase_25 AC 116 ms
54,740 KB
testcase_26 AC 193 ms
58,044 KB
testcase_27 AC 163 ms
57,624 KB
testcase_28 AC 108 ms
52,372 KB
testcase_29 AC 95 ms
52,668 KB
testcase_30 AC 126 ms
54,736 KB
testcase_31 AC 155 ms
57,352 KB
testcase_32 MLE -
testcase_33 AC 1,335 ms
210,052 KB
testcase_34 MLE -
testcase_35 MLE -
testcase_36 AC 333 ms
68,580 KB
testcase_37 MLE -
testcase_38 AC 1,395 ms
283,724 KB
testcase_39 MLE -
testcase_40 AC 1,284 ms
196,540 KB
testcase_41 AC 1,576 ms
293,276 KB
testcase_42 MLE -
testcase_43 AC 1,730 ms
293,704 KB
testcase_44 MLE -
testcase_45 AC 935 ms
117,852 KB
testcase_46 MLE -
testcase_47 AC 1,387 ms
252,056 KB
testcase_48 MLE -
testcase_49 MLE -
testcase_50 MLE -
testcase_51 MLE -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 MLE -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 MLE -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 MLE -
testcase_75 WA -
testcase_76 MLE -
testcase_77 MLE -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 MLE -
testcase_82 TLE -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		int q = Integer.parseInt(sa[0]);
		int[][] p = new int[q][3];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			for (int j = 0; j < 3; j++) {
				p[i][j] = Integer.parseInt(sa[j]);
			}
		}
		br.close();

		List<Map<Integer, Integer>> list = new ArrayList<>(n);
		list.add(new HashMap<>());
		for (int i = 0; i < n; i++) {
			Map<Integer, Integer> soinsu = bunkai(a[i]);
			for (Integer o : list.get(i).keySet()) {
				if (soinsu.containsKey(o)) {
					soinsu.put(o, soinsu.get(o) + list.get(i).get(o));
				} else {
					soinsu.put(o, list.get(i).get(o));
				}
			}
			list.add(soinsu);
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			Map<Integer, Integer> soinsu = bunkai(p[i][0]);
			Map<Integer, Integer> l = list.get(p[i][1] - 1);
			Map<Integer, Integer> r = list.get(p[i][2]);
			boolean flg = true;
			for (Integer o : soinsu.keySet()) {
				int x = soinsu.get(o);
				Integer y = l.get(o);
				if (y == null) y = 0;
				Integer z = r.get(o);
				if (z == null) z = 0;
				if (x > z - y) {
					flg = false;
					break;
				}
			}
			if (flg) {
				pw.println("Yes");
			} else {
				pw.println("NO");
			}
		}
		pw.flush();
	}

	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