結果

問題 No.854 公平なりんご分配
ユーザー ks2mks2m
提出日時 2019-07-26 23:18:45
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 2,214 bytes
コンパイル時間 3,702 ms
コンパイル使用メモリ 82,080 KB
実行使用メモリ 756,688 KB
最終ジャッジ日時 2023-09-15 04:39:43
合計ジャッジ時間 95,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
51,496 KB
testcase_01 AC 45 ms
49,392 KB
testcase_02 AC 46 ms
49,384 KB
testcase_03 AC 47 ms
49,336 KB
testcase_04 AC 48 ms
49,520 KB
testcase_05 AC 46 ms
49,432 KB
testcase_06 AC 47 ms
49,380 KB
testcase_07 AC 46 ms
49,504 KB
testcase_08 AC 47 ms
49,364 KB
testcase_09 AC 46 ms
49,324 KB
testcase_10 AC 46 ms
49,636 KB
testcase_11 AC 46 ms
49,680 KB
testcase_12 AC 53 ms
51,236 KB
testcase_13 AC 53 ms
51,060 KB
testcase_14 AC 45 ms
49,272 KB
testcase_15 AC 48 ms
49,524 KB
testcase_16 AC 53 ms
51,076 KB
testcase_17 AC 55 ms
50,204 KB
testcase_18 AC 53 ms
50,168 KB
testcase_19 AC 52 ms
51,132 KB
testcase_20 AC 51 ms
50,180 KB
testcase_21 AC 52 ms
50,420 KB
testcase_22 AC 126 ms
53,044 KB
testcase_23 AC 128 ms
55,000 KB
testcase_24 AC 183 ms
58,160 KB
testcase_25 AC 122 ms
54,696 KB
testcase_26 AC 187 ms
58,716 KB
testcase_27 AC 173 ms
58,176 KB
testcase_28 AC 127 ms
53,156 KB
testcase_29 AC 94 ms
52,768 KB
testcase_30 AC 121 ms
54,896 KB
testcase_31 AC 170 ms
58,124 KB
testcase_32 MLE -
testcase_33 AC 1,334 ms
210,116 KB
testcase_34 MLE -
testcase_35 MLE -
testcase_36 AC 359 ms
69,672 KB
testcase_37 MLE -
testcase_38 AC 1,422 ms
295,068 KB
testcase_39 MLE -
testcase_40 AC 1,024 ms
179,428 KB
testcase_41 AC 1,550 ms
290,788 KB
testcase_42 MLE -
testcase_43 MLE -
testcase_44 MLE -
testcase_45 AC 932 ms
126,612 KB
testcase_46 MLE -
testcase_47 AC 1,371 ms
235,668 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 MLE -
testcase_74 MLE -
testcase_75 WA -
testcase_76 MLE -
testcase_77 MLE -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 MLE -
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]);

		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++) {
			sa = br.readLine().split(" ");
			int p0 = Integer.parseInt(sa[0]);
			int p1 = Integer.parseInt(sa[1]);
			int p2 = Integer.parseInt(sa[2]);
			if (p0 == 1) {
				pw.println("Yes");
				continue;
			}
			Map<Integer, Integer> soinsu = bunkai(p0);
			Map<Integer, Integer> l = list.get(p1 - 1);
			Map<Integer, Integer> r = list.get(p2);
			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