結果

問題 No.854 公平なりんご分配
ユーザー ks2mks2m
提出日時 2019-07-27 00:11:20
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 2,435 bytes
コンパイル時間 3,207 ms
コンパイル使用メモリ 77,764 KB
実行使用メモリ 515,756 KB
最終ジャッジ日時 2023-09-15 05:18:28
合計ジャッジ時間 92,568 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,672 KB
testcase_01 AC 43 ms
49,712 KB
testcase_02 AC 45 ms
49,556 KB
testcase_03 AC 44 ms
49,732 KB
testcase_04 AC 43 ms
49,544 KB
testcase_05 AC 43 ms
49,788 KB
testcase_06 AC 45 ms
49,780 KB
testcase_07 AC 44 ms
49,520 KB
testcase_08 AC 45 ms
49,716 KB
testcase_09 AC 44 ms
49,608 KB
testcase_10 AC 43 ms
49,632 KB
testcase_11 AC 43 ms
47,508 KB
testcase_12 AC 51 ms
51,392 KB
testcase_13 AC 50 ms
51,096 KB
testcase_14 AC 43 ms
49,592 KB
testcase_15 AC 46 ms
48,068 KB
testcase_16 AC 50 ms
51,316 KB
testcase_17 AC 51 ms
50,800 KB
testcase_18 AC 50 ms
50,392 KB
testcase_19 AC 51 ms
50,436 KB
testcase_20 AC 49 ms
50,376 KB
testcase_21 AC 49 ms
50,468 KB
testcase_22 AC 112 ms
52,936 KB
testcase_23 AC 137 ms
55,492 KB
testcase_24 AC 182 ms
58,816 KB
testcase_25 AC 121 ms
55,176 KB
testcase_26 AC 184 ms
58,792 KB
testcase_27 AC 171 ms
59,184 KB
testcase_28 AC 123 ms
52,872 KB
testcase_29 AC 99 ms
52,688 KB
testcase_30 AC 120 ms
55,424 KB
testcase_31 AC 168 ms
58,576 KB
testcase_32 MLE -
testcase_33 AC 1,284 ms
207,484 KB
testcase_34 MLE -
testcase_35 MLE -
testcase_36 AC 362 ms
70,732 KB
testcase_37 MLE -
testcase_38 AC 1,425 ms
295,264 KB
testcase_39 MLE -
testcase_40 AC 1,009 ms
178,544 KB
testcase_41 AC 1,543 ms
290,344 KB
testcase_42 MLE -
testcase_43 MLE -
testcase_44 MLE -
testcase_45 AC 901 ms
126,056 KB
testcase_46 MLE -
testcase_47 AC 1,361 ms
235,352 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 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;
import java.util.TreeSet;

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];
		TreeSet<Integer> zero = new TreeSet<>();
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
			if (a[i] == 0) {
				zero.add(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;
			}
			if (zero.ceiling(p1 - 1) != null && zero.floor(p2 - 1) != null) {
				pw.println("NO");
				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