結果

問題 No.854 公平なりんご分配
ユーザー 37zigen37zigen
提出日時 2019-07-27 12:56:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,012 ms / 3,153 ms
コード長 1,572 bytes
コンパイル時間 6,899 ms
コンパイル使用メモリ 76,384 KB
実行使用メモリ 275,196 KB
最終ジャッジ日時 2023-09-15 06:20:11
合計ジャッジ時間 79,291 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,928 KB
testcase_01 AC 119 ms
56,240 KB
testcase_02 AC 124 ms
56,020 KB
testcase_03 AC 121 ms
56,200 KB
testcase_04 AC 121 ms
55,932 KB
testcase_05 AC 121 ms
55,820 KB
testcase_06 AC 118 ms
56,324 KB
testcase_07 AC 118 ms
56,108 KB
testcase_08 AC 121 ms
56,108 KB
testcase_09 AC 118 ms
56,180 KB
testcase_10 AC 118 ms
55,780 KB
testcase_11 AC 122 ms
56,512 KB
testcase_12 AC 131 ms
56,084 KB
testcase_13 AC 132 ms
55,832 KB
testcase_14 AC 124 ms
56,520 KB
testcase_15 AC 125 ms
56,268 KB
testcase_16 AC 132 ms
56,084 KB
testcase_17 AC 136 ms
56,080 KB
testcase_18 AC 128 ms
56,352 KB
testcase_19 AC 131 ms
56,004 KB
testcase_20 AC 130 ms
55,976 KB
testcase_21 AC 128 ms
56,136 KB
testcase_22 AC 229 ms
59,176 KB
testcase_23 AC 218 ms
59,780 KB
testcase_24 AC 255 ms
61,212 KB
testcase_25 AC 216 ms
59,240 KB
testcase_26 AC 256 ms
60,448 KB
testcase_27 AC 237 ms
61,400 KB
testcase_28 AC 232 ms
59,248 KB
testcase_29 AC 198 ms
58,428 KB
testcase_30 AC 222 ms
59,584 KB
testcase_31 AC 256 ms
60,904 KB
testcase_32 AC 582 ms
100,016 KB
testcase_33 AC 711 ms
87,468 KB
testcase_34 AC 888 ms
122,016 KB
testcase_35 AC 667 ms
106,488 KB
testcase_36 AC 639 ms
71,632 KB
testcase_37 AC 584 ms
93,072 KB
testcase_38 AC 499 ms
82,704 KB
testcase_39 AC 1,126 ms
121,336 KB
testcase_40 AC 787 ms
87,984 KB
testcase_41 AC 776 ms
103,708 KB
testcase_42 AC 867 ms
119,692 KB
testcase_43 AC 933 ms
106,840 KB
testcase_44 AC 1,062 ms
126,588 KB
testcase_45 AC 1,181 ms
79,980 KB
testcase_46 AC 1,183 ms
120,868 KB
testcase_47 AC 690 ms
93,388 KB
testcase_48 AC 801 ms
123,264 KB
testcase_49 AC 751 ms
114,288 KB
testcase_50 AC 574 ms
88,560 KB
testcase_51 AC 1,209 ms
125,032 KB
testcase_52 AC 993 ms
90,232 KB
testcase_53 AC 792 ms
92,288 KB
testcase_54 AC 1,124 ms
95,048 KB
testcase_55 AC 595 ms
88,808 KB
testcase_56 AC 528 ms
86,860 KB
testcase_57 AC 745 ms
87,020 KB
testcase_58 AC 1,155 ms
77,984 KB
testcase_59 AC 509 ms
77,996 KB
testcase_60 AC 827 ms
88,052 KB
testcase_61 AC 610 ms
71,592 KB
testcase_62 AC 1,057 ms
88,384 KB
testcase_63 AC 847 ms
84,844 KB
testcase_64 AC 476 ms
69,276 KB
testcase_65 AC 740 ms
111,848 KB
testcase_66 AC 734 ms
75,972 KB
testcase_67 AC 935 ms
101,280 KB
testcase_68 AC 1,116 ms
87,664 KB
testcase_69 AC 654 ms
100,040 KB
testcase_70 AC 549 ms
83,100 KB
testcase_71 AC 607 ms
84,416 KB
testcase_72 AC 719 ms
71,124 KB
testcase_73 AC 718 ms
104,496 KB
testcase_74 AC 1,109 ms
120,980 KB
testcase_75 AC 730 ms
87,956 KB
testcase_76 AC 960 ms
107,396 KB
testcase_77 AC 972 ms
118,780 KB
testcase_78 AC 1,144 ms
89,968 KB
testcase_79 AC 1,077 ms
96,856 KB
testcase_80 AC 941 ms
106,508 KB
testcase_81 AC 871 ms
108,220 KB
testcase_82 AC 1,743 ms
266,928 KB
testcase_83 AC 1,815 ms
267,424 KB
testcase_84 AC 1,829 ms
269,056 KB
testcase_85 AC 2,012 ms
267,912 KB
testcase_86 AC 1,509 ms
275,196 KB
testcase_87 AC 1,810 ms
267,116 KB
testcase_88 AC 1,849 ms
267,020 KB
testcase_89 AC 1,852 ms
266,624 KB
testcase_90 AC 1,888 ms
268,780 KB
testcase_91 AC 1,855 ms
268,692 KB
testcase_92 AC 1,980 ms
268,552 KB
testcase_93 AC 1,975 ms
270,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; ++i)
			A[i] = sc.nextInt();
		int Q = sc.nextInt();
		ArrayList<Integer> primes = new ArrayList<>();
		out: for (int i = 2; i <= 2 * 1000; ++i) {
			for (int j = 2; j * j <= i; ++j) {
				if (i % j == 0)
					continue out;
			}
			primes.add(i);
		}
		int[] zero = new int[N];
		int[][] cnt = new int[N][primes.size()];
		for (int i = 0; i < N; ++i) {
			zero[i] = (i > 0 ? zero[i - 1] : 0) + (A[i] == 0 ? 1 : 0);
			for (int j = 0; j < primes.size(); ++j) {
				if (i > 0)
					cnt[i][j] = cnt[i - 1][j];
				while (A[i] > 0 && A[i] % primes.get(j) == 0) {
					cnt[i][j]++;
					A[i] /= primes.get(j);
				}
			}
		}
		PrintWriter pw = new PrintWriter(System.out);
		for (int t = 0; t < Q; ++t) {
			int P = sc.nextInt();
			int L = sc.nextInt();
			int R = sc.nextInt();
			--L;
			--R;
			boolean ok = true;
			int[] cnt2 = new int[primes.size()];
			for (int i = 0; i < primes.size(); ++i) {
				while (P % primes.get(i) == 0) {
					cnt2[i]++;
					P /= primes.get(i);
				}
				ok &= cnt[R][i] - (L > 0 ? cnt[L - 1][i] : 0) >= cnt2[i];
			}
			ok &= P == 1;
			ok |= zero[R] - (L > 0 ? zero[L - 1] : 0) > 0;
			pw.println(ok ? "Yes" : "NO");
		}
		pw.close();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0