結果

問題 No.854 公平なりんご分配
ユーザー leaf_1415leaf_1415
提出日時 2019-07-26 22:33:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,741 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 80,584 KB
実行使用メモリ 246,948 KB
最終ジャッジ日時 2023-09-15 02:28:52
合計ジャッジ時間 15,828 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
7,332 KB
testcase_01 AC 11 ms
5,116 KB
testcase_02 AC 11 ms
7,276 KB
testcase_03 AC 11 ms
7,232 KB
testcase_04 AC 12 ms
7,344 KB
testcase_05 AC 12 ms
7,164 KB
testcase_06 AC 12 ms
7,168 KB
testcase_07 AC 12 ms
7,252 KB
testcase_08 AC 12 ms
7,132 KB
testcase_09 AC 11 ms
7,164 KB
testcase_10 AC 12 ms
7,232 KB
testcase_11 AC 12 ms
7,168 KB
testcase_12 AC 14 ms
17,456 KB
testcase_13 AC 14 ms
17,688 KB
testcase_14 AC 12 ms
7,196 KB
testcase_15 AC 13 ms
13,376 KB
testcase_16 AC 14 ms
17,652 KB
testcase_17 AC 14 ms
17,460 KB
testcase_18 AC 14 ms
17,444 KB
testcase_19 AC 14 ms
17,476 KB
testcase_20 AC 14 ms
15,496 KB
testcase_21 AC 14 ms
15,408 KB
testcase_22 AC 36 ms
97,608 KB
testcase_23 AC 35 ms
110,224 KB
testcase_24 AC 41 ms
124,948 KB
testcase_25 AC 34 ms
108,008 KB
testcase_26 AC 39 ms
119,096 KB
testcase_27 AC 37 ms
116,896 KB
testcase_28 AC 30 ms
79,152 KB
testcase_29 AC 29 ms
89,332 KB
testcase_30 AC 34 ms
109,988 KB
testcase_31 AC 39 ms
122,896 KB
testcase_32 AC 90 ms
169,672 KB
testcase_33 AC 101 ms
149,960 KB
testcase_34 AC 146 ms
182,684 KB
testcase_35 AC 114 ms
172,804 KB
testcase_36 AC 95 ms
125,460 KB
testcase_37 AC 88 ms
168,480 KB
testcase_38 AC 77 ms
161,776 KB
testcase_39 AC 207 ms
187,104 KB
testcase_40 AC 111 ms
148,208 KB
testcase_41 AC 116 ms
165,780 KB
testcase_42 AC 132 ms
182,364 KB
testcase_43 AC 162 ms
168,148 KB
testcase_44 AC 161 ms
177,444 KB
testcase_45 AC 175 ms
135,816 KB
testcase_46 AC 202 ms
177,208 KB
testcase_47 AC 99 ms
156,832 KB
testcase_48 AC 124 ms
181,948 KB
testcase_49 AC 118 ms
182,508 KB
testcase_50 AC 84 ms
168,368 KB
testcase_51 AC 199 ms
179,800 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 429 ms
244,536 KB
testcase_84 AC 687 ms
244,560 KB
testcase_85 AC 430 ms
128,048 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 AC 530 ms
244,656 KB
testcase_93 AC 531 ms
244,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#define llint long long

using namespace std;

llint n, Q;
llint a[100005];
int d[325][100005];
int sum[325][100005];
unordered_map<int, int> mp, fmp[2005];

bool prime[2005];
vector<llint> pvec;

int main(void)
{
	for(int i = 2; i < 55; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 2005; j+=i) prime[j] = true;
	}
	for(int i = 2; i < 2005; i++){
		if(!prime[i]) pvec.push_back(i);
	}
	int m = pvec.size();
	
	for(int i = 1; i < 2005; i++){
		for(int j = 0; j < m; j++){
			int t = i;
			while(t % pvec[j] == 0){
				fmp[i][j]++;
				t /= pvec[j];
			}
		}
	}
	
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++){
		for(auto it = fmp[a[i]].begin(); it != fmp[a[i]].end(); it++) d[it->first][i] = it->second;
	}
	for(int i = 0; i < m; i++){
		for(int j = 1; j <= n; j++) sum[i][j] = sum[i][j-1] + d[i][j];
	}
	
	for(int i = 1; i <= n; i++){
		if(a[i] == 0) d[320][i] = 1;
	}
	for(int i = 1; i <= n; i++){
		sum[320][i] = sum[320][i-1] + d[320][i];
	}
	
	cin >> Q;
	int p, l, r;
	for(int q = 0; q < Q; q++){
		cin >> p >> l >> r;
		
		if(sum[320][r]-sum[320][l-1] > 0){
			printf("NO\n");
			continue;
		}
		
		int t = p;
		mp.clear();
		for(int i = 0; i < m; i++){
			if(pvec[i] > t) break;
			while(t % pvec[i] == 0){
				mp[i]++;
				t /= pvec[i];
			}
		}
		if(t > 1){
			printf("NO\n");
			continue;
		}
		
		bool flag = true;
		for(auto it = mp.begin(); it != mp.end(); it++){
			if(it->second > sum[it->first][r]-sum[it->first][l-1]){
				flag = false;
				break;
			}
		}
		if(flag) printf("Yes\n");
		else printf("NO\n");
	}
	
	return 0;
}
0