結果
問題 |
No.854 公平なりんご分配
|
ユーザー |
![]() |
提出日時 | 2019-07-27 07:58:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,438 bytes |
コンパイル時間 | 938 ms |
コンパイル使用メモリ | 87,128 KB |
実行使用メモリ | 39,552 KB |
最終ジャッジ日時 | 2024-07-02 10:43:20 |
合計ジャッジ時間 | 8,328 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 50 TLE * 1 -- * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’: main.cpp:68:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 68 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:82:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 82 | scanf("%d", &a); | ~~~~~^~~~~~~~~~ main.cpp:98:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 98 | scanf("%d", &Q); | ~~~~~^~~~~~~~~~ main.cpp:101:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 101 | scanf("%d %d %d", &p, &l, &r); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <list> #include <iterator> #include <assert.h> #pragma warning(disable:4996) typedef long long ll; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; using namespace std; vector<int> pp; void preparePrime( int maxp ) { int i; vector<int> a(maxp+1); for(i=2; i<=maxp; i++) { int k=i+i; while(k<=maxp) { a[k]=1; k+=i; } } for(i=2; i<=maxp; i++) { if(a[i]==0) pp.push_back( i ); } return; } void decompositPrime( ll a, vector<pair<ll,ll> >& vv ) { //preparePrime( (int)sqrt((double)a)+1 ); int i; for(i=0; i<(int)pp.size(); i++) { int count = 0; while(a % pp[i] == 0 ) { a /= pp[i]; count ++; } if(count>0) vv.push_back( make_pair( pp[i], count ) ); if (a==1) break; } if(a>1) { vv.push_back( make_pair( a, 1 ) ); } return; } int s[100005][303]; int main(int argc, char* argv[]) { int n; scanf("%d", &n); preparePrime(2001); map<int,int> mp; int i; for(i=0; i<(int)pp.size(); i++) { mp[pp[i]]=i; } vector<pair<ll,ll> > vv; for(i=0; i<n; i++) { int a; scanf("%d", &a); vv.clear(); decompositPrime(a, vv); int k; for(k=0; k<(int)pp.size(); k++) { s[i+1][k]=s[i][k]; } for(k=0; k<(int)vv.size(); k++) { int id=mp[vv[k].first]; s[i+1][id]=s[i+1][id]+vv[k].second; } } int Q; scanf("%d", &Q); for(i=0; i<Q; i++) { int p, l, r; scanf("%d %d %d", &p, &l, &r); vv.clear(); decompositPrime(p, vv); int k; int ng=0; for(k=0; k<(int)vv.size(); k++) { if( mp.find(vv[k].first) == mp.end() ) { ng=1; break; } int id=mp[vv[k].first]; if(s[r][id]-s[l-1][id]<vv[k].second) { ng=1; break; } } if(ng) { printf("NO\n"); } else { printf("Yes\n"); } } return 0; }