結果

問題 No.854 公平なりんご分配
ユーザー CuriousFairy315CuriousFairy315
提出日時 2019-02-22 06:28:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,563 bytes
コンパイル時間 1,027 ms
コンパイル使用メモリ 71,476 KB
実行使用メモリ 122,640 KB
最終ジャッジ日時 2023-08-16 20:11:18
合計ジャッジ時間 28,955 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,540 KB
testcase_01 AC 4 ms
6,672 KB
testcase_02 AC 4 ms
6,540 KB
testcase_03 WA -
testcase_04 AC 4 ms
6,644 KB
testcase_05 AC 4 ms
6,516 KB
testcase_06 AC 4 ms
6,540 KB
testcase_07 AC 4 ms
6,508 KB
testcase_08 AC 4 ms
6,648 KB
testcase_09 AC 4 ms
6,540 KB
testcase_10 AC 4 ms
6,508 KB
testcase_11 AC 4 ms
6,560 KB
testcase_12 AC 4 ms
6,732 KB
testcase_13 AC 5 ms
6,644 KB
testcase_14 AC 4 ms
6,668 KB
testcase_15 AC 4 ms
6,572 KB
testcase_16 AC 4 ms
6,600 KB
testcase_17 WA -
testcase_18 AC 4 ms
6,648 KB
testcase_19 AC 4 ms
6,728 KB
testcase_20 AC 5 ms
6,772 KB
testcase_21 AC 4 ms
6,612 KB
testcase_22 WA -
testcase_23 AC 7 ms
7,264 KB
testcase_24 AC 10 ms
7,580 KB
testcase_25 AC 6 ms
7,012 KB
testcase_26 AC 10 ms
7,632 KB
testcase_27 AC 9 ms
7,700 KB
testcase_28 AC 7 ms
6,792 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 112 ms
31,260 KB
testcase_33 WA -
testcase_34 AC 270 ms
40,704 KB
testcase_35 AC 184 ms
33,356 KB
testcase_36 WA -
testcase_37 AC 112 ms
29,840 KB
testcase_38 AC 84 ms
25,352 KB
testcase_39 WA -
testcase_40 AC 155 ms
17,812 KB
testcase_41 AC 187 ms
28,040 KB
testcase_42 AC 238 ms
40,140 KB
testcase_43 AC 316 ms
29,040 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 441 ms
37,168 KB
testcase_47 WA -
testcase_48 AC 210 ms
39,624 KB
testcase_49 AC 190 ms
40,320 KB
testcase_50 AC 98 ms
29,632 KB
testcase_51 AC 436 ms
38,872 KB
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 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 AC 709 ms
122,548 KB
testcase_84 AC 688 ms
122,536 KB
testcase_85 AC 714 ms
122,432 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 AC 1,614 ms
122,604 KB
testcase_93 AC 1,545 ms
122,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<bitset>
using namespace std; // 575

const int MAX = 100001;
const int MAX2 = 2001;
const int PRIME = 303; // 2000までの素数

const string ERROR = "No Judge";
int main() {
	static int N, A[MAX], Q, P, L, R;
	cin >> N;
	if (!(1 <= N && N <= 100000)) {
		cout << ERROR << endl;
		return 0;
	}
	for (int i = 0;i < N;++ i) {
		cin >> A[i];
		if (!(0 <= A[i] && A[i] <= 2000)) {
			cout << ERROR << endl;
			return 0;
		}
	}
	static int prime[PRIME], sum[PRIME][MAX], sumZero[MAX];
	bitset<MAX2> sieve; // エラトステネスの篩
	for (int i = 2, j = 0;i < MAX2;++ i) {
		if (!sieve[i]) {
			prime[j++] = i;
			for (int k = i;k < MAX2;k += i) sieve[k] = true;
		}
	}
	for (int i = 0;i < PRIME;++ i) sum[0][i] = 0;
	sumZero[0] = 0;
	for (int i = 0;i < N;++ i) { // 累積和
		sumZero[i + 1] = sumZero[i] + (A[i] == 0 ? 1 : 0);
		for (int j = 0;j < PRIME;++ j) sum[j][i + 1] = sum[j][i] + (A[i] % prime[j] == 0 ? 1 : 0);
	}
	// ここまでで前準備終わり、次に各クエリの処理
	cin >> Q;
	if (!(1 <= Q && Q <= 100000)) {
		cout << ERROR << endl;
		return 0;
	}
	while (Q-- > 0) {
		cin >> P >> L >> R;
		bool isDiv = sumZero[R] - sumZero[L - 1] == 0; // 割り切れるかフラグ
		for (int i = 0;i < PRIME;++ i) {
			int factor = 0;
			while (P % prime[i] == 0) {
				P /= prime[i];
				++ factor;
			}
			isDiv &= sum[i][R] - sum[i][L - 1] >= factor;
		}
		if (1 <= P && P <= 1000000000 && 1 <= L && L <= R && R <= N) cout << (isDiv && P == 1 ? "Yes" : "NO") << endl;
		else cout << ERROR << endl;
	}
	return 0;
}
0