結果

問題 No.854 公平なりんご分配
ユーザー ahe100ahe100
提出日時 2019-07-26 23:25:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 559 ms / 3,153 ms
コード長 1,912 bytes
コンパイル時間 1,627 ms
コンパイル使用メモリ 170,820 KB
実行使用メモリ 129,396 KB
最終ジャッジ日時 2023-09-15 04:43:08
合計ジャッジ時間 16,740 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
9,824 KB
testcase_01 AC 10 ms
9,988 KB
testcase_02 AC 11 ms
9,844 KB
testcase_03 AC 12 ms
9,840 KB
testcase_04 AC 11 ms
9,816 KB
testcase_05 AC 10 ms
9,896 KB
testcase_06 AC 10 ms
9,828 KB
testcase_07 AC 11 ms
9,896 KB
testcase_08 AC 11 ms
9,928 KB
testcase_09 AC 11 ms
9,820 KB
testcase_10 AC 11 ms
9,876 KB
testcase_11 AC 12 ms
9,812 KB
testcase_12 AC 11 ms
9,992 KB
testcase_13 AC 11 ms
9,980 KB
testcase_14 AC 11 ms
9,812 KB
testcase_15 AC 11 ms
9,956 KB
testcase_16 AC 11 ms
9,956 KB
testcase_17 AC 12 ms
9,936 KB
testcase_18 AC 11 ms
9,944 KB
testcase_19 AC 12 ms
9,940 KB
testcase_20 AC 11 ms
10,080 KB
testcase_21 AC 11 ms
9,936 KB
testcase_22 AC 15 ms
10,144 KB
testcase_23 AC 13 ms
10,704 KB
testcase_24 AC 15 ms
10,976 KB
testcase_25 AC 13 ms
10,412 KB
testcase_26 AC 16 ms
11,152 KB
testcase_27 AC 13 ms
11,052 KB
testcase_28 AC 13 ms
10,188 KB
testcase_29 AC 12 ms
10,092 KB
testcase_30 AC 13 ms
10,364 KB
testcase_31 AC 15 ms
11,012 KB
testcase_32 AC 41 ms
36,368 KB
testcase_33 AC 67 ms
23,948 KB
testcase_34 AC 96 ms
46,512 KB
testcase_35 AC 66 ms
38,460 KB
testcase_36 AC 77 ms
11,488 KB
testcase_37 AC 39 ms
34,140 KB
testcase_38 AC 32 ms
30,064 KB
testcase_39 AC 163 ms
48,556 KB
testcase_40 AC 80 ms
21,904 KB
testcase_41 AC 73 ms
32,128 KB
testcase_42 AC 80 ms
44,464 KB
testcase_43 AC 123 ms
34,180 KB
testcase_44 AC 115 ms
42,432 KB
testcase_45 AC 157 ms
17,636 KB
testcase_46 AC 162 ms
42,656 KB
testcase_47 AC 58 ms
27,968 KB
testcase_48 AC 72 ms
44,492 KB
testcase_49 AC 64 ms
44,764 KB
testcase_50 AC 35 ms
34,144 KB
testcase_51 AC 157 ms
44,512 KB
testcase_52 AC 155 ms
25,884 KB
testcase_53 AC 80 ms
25,932 KB
testcase_54 AC 147 ms
27,956 KB
testcase_55 AC 49 ms
25,936 KB
testcase_56 AC 37 ms
26,188 KB
testcase_57 AC 71 ms
23,928 KB
testcase_58 AC 154 ms
15,704 KB
testcase_59 AC 37 ms
21,840 KB
testcase_60 AC 102 ms
23,820 KB
testcase_61 AC 66 ms
13,520 KB
testcase_62 AC 120 ms
21,816 KB
testcase_63 AC 108 ms
21,760 KB
testcase_64 AC 41 ms
15,608 KB
testcase_65 AC 56 ms
40,380 KB
testcase_66 AC 77 ms
17,696 KB
testcase_67 AC 121 ms
30,020 KB
testcase_68 AC 142 ms
20,000 KB
testcase_69 AC 40 ms
48,564 KB
testcase_70 AC 45 ms
21,768 KB
testcase_71 AC 52 ms
23,828 KB
testcase_72 AC 106 ms
13,524 KB
testcase_73 AC 55 ms
34,452 KB
testcase_74 AC 133 ms
40,396 KB
testcase_75 AC 76 ms
23,836 KB
testcase_76 AC 125 ms
34,148 KB
testcase_77 AC 105 ms
44,580 KB
testcase_78 AC 158 ms
19,716 KB
testcase_79 AC 146 ms
30,008 KB
testcase_80 AC 130 ms
32,092 KB
testcase_81 AC 95 ms
32,072 KB
testcase_82 AC 503 ms
129,224 KB
testcase_83 AC 527 ms
129,188 KB
testcase_84 AC 510 ms
129,188 KB
testcase_85 AC 559 ms
129,248 KB
testcase_86 AC 462 ms
129,256 KB
testcase_87 AC 512 ms
129,220 KB
testcase_88 AC 514 ms
129,196 KB
testcase_89 AC 512 ms
129,232 KB
testcase_90 AC 512 ms
129,228 KB
testcase_91 AC 510 ms
129,276 KB
testcase_92 AC 524 ms
129,252 KB
testcase_93 AC 521 ms
129,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)

/*
何故かエラー出る
	解決。配列範囲には気をつけよう
倍数かどうかだけ見れば良い。
*/

int n,m,a[100010],q,p[100010];
int l[100010],r[100010],fact[2010][305],dp[100010][305],zero[100010];
vector<ll> prime,pri2;

void prime_list(ll n,vector<ll>& prime_){
	ll visited[300010]={};
	reg(i,2,n){
		if(visited[i]==0){
			prime_.push_back(i);
			reg(j,2,n){
				if(j*i>n)break;
				visited[i*j]=1;
			}
		}
	}
}
void factoring(ll n,vector<pair<ll,ll>>& v,vector<ll>& p){
	rep(i,p.size()){
		int t=0;
		while(n%p[i]==0){
			n/=p[i];
			t++;
		}
		if(t>0)v.push_back({i,t});
	}
	if(n>1)v.push_back({10000,1});
}
ll modpow(__int128_t a, ll n,ll mo) {
	__int128_t r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void init(){
	cin>>n;
	reg(i,1,n)cin>>a[i];
	cin>>q;
	rep(i,q)cin>>p[i]>>l[i]>>r[i];
	prime_list(2000,prime);
	m = prime.size();
	rep(j,m)fact[0][j]=0;
	reg(i,1,2000){
		ll t = i;
		rep(j,m){
			fact[i][j]=0;
			while(t%prime[j]==0){
				// if(prime[j]>=45)
				t/=prime[j];
				fact[i][j]++;
			}
		}
	}
	// 12ms
	zero[0]=0;
	rep(j,m)dp[0][j]=0;
	for(int i=1;i<=n;++i){
		zero[i]=zero[i-1];
		if(a[i]==0)zero[i]++;
		for(int j=0;j<m;++j)dp[i][j] = dp[i-1][j] + fact[a[i]][j];
	}
}

int main(void){
	init();
	for(int i=0;i<q;++i){
		bool ok=true;
		vector<pair<ll,ll>> v;
		factoring(p[i],v,prime);
		if(zero[r[i]]-zero[l[i]-1]==0){
			irep(j,v.size()){
				if(v[j].first>m){
					ok=false;
					break;
				}
				if(v[j].second > dp[r[i]][v[j].first] - dp[l[i]-1][v[j].first]){
					ok=false;
					break;
				}
			}
		}
		cout<<(ok?"Yes":"NO")<<"\n";
	}
	return 0;
}
0