結果
| 問題 |
No.854 公平なりんご分配
|
| コンテスト | |
| ユーザー |
tarattata1
|
| 提出日時 | 2019-07-26 23:09:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,614 bytes |
| コンパイル時間 | 1,407 ms |
| コンパイル使用メモリ | 86,592 KB |
| 実行使用メモリ | 52,316 KB |
| 最終ジャッジ日時 | 2024-07-02 09:17:20 |
| 合計ジャッジ時間 | 7,681 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 7 WA * 43 TLE * 1 -- * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:78:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
78 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:92:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
92 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
main.cpp:108:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
108 | scanf("%d", &Q);
| ~~~~~^~~~~~~~~~
main.cpp:111:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
111 | 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;
ll gcd(ll a, ll b) {
if(b == 0) return a;
return gcd(b,a%b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a,b);
return a / g * b; // Be careful not to overflow
}
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][400];
int main(int argc, char* argv[])
{
int n;
scanf("%d", &n);
preparePrime(2500);
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;
}
tarattata1