結果

問題 No.854 公平なりんご分配
ユーザー CuriousFairy315CuriousFairy315
提出日時 2019-02-22 06:20:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,563 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 72,136 KB
実行使用メモリ 67,948 KB
最終ジャッジ日時 2024-05-04 03:30:21
合計ジャッジ時間 29,924 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 3 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
6,940 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
6,944 KB
testcase_15 WA -
testcase_16 AC 8 ms
34,280 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 7 ms
26,088 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 WA -
testcase_29 WA -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 RE -
testcase_75 RE -
testcase_76 RE -
testcase_77 RE -
testcase_78 RE -
testcase_79 RE -
testcase_80 RE -
testcase_81 RE -
testcase_82 RE -
testcase_83 RE -
testcase_84 RE -
testcase_85 RE -
testcase_86 RE -
testcase_87 RE -
testcase_88 RE -
testcase_89 RE -
testcase_90 RE -
testcase_91 RE -
testcase_92 RE -
testcase_93 RE -
権限があれば一括ダウンロードができます

ソースコード

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[i] = 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[i + 1][j] = sum[i][j] + (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[R][i] - sum[L - 1][i] >= 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