結果
| 問題 |
No.854 公平なりんご分配
|
| コンテスト | |
| ユーザー |
mencotton
|
| 提出日時 | 2019-07-26 22:22:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,457 bytes |
| コンパイル時間 | 790 ms |
| コンパイル使用メモリ | 76,276 KB |
| 実行使用メモリ | 41,216 KB |
| 最終ジャッジ日時 | 2024-07-02 07:43:30 |
| 合計ジャッジ時間 | 8,692 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 50 TLE * 1 -- * 41 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> prime;
for (int i = 2; i <= 2000; i++) {
bool flag = true;
for (auto x:prime) {
if (x * x > i)break;
if (i % x == 0)flag = false;
}
if (flag)prime.push_back(i);
}
int n;
cin >> n;
vector<vector<int>> cumulative_sum(n + 1, vector<int>(prime.size()));
for (int i = 1; i <= n; i++) {
cumulative_sum[i] = cumulative_sum[i - 1];
int now;
cin >> now;
for (int j = 0; j < prime.size(); j++) {
while (now % prime[j] == 0) {
now /= prime[j];
cumulative_sum[i][j]++;
}
}
}
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int p, l, r;
cin >> p >> l >> r;
vector<int> available(prime.size());
for (int j = 0; j < prime.size(); j++) {
available[j] = cumulative_sum[r][j] - cumulative_sum[l - 1][j];
}
vector<int> needed(prime.size());
for (int j = 0; j < prime.size(); j++) {
while (p % prime[j] == 0) {
p /= prime[j];
needed[j]++;
}
}
bool ret = true;
for (int j = 0; j < prime.size(); j++) {
if (available[j] < needed[j])ret = false;
}
cout << (ret && p == 1 ? "Yes" : "NO") << endl;
}
return 0;
}
mencotton