結果
問題 | No.2207 pCr検査 |
ユーザー |
![]() |
提出日時 | 2023-02-04 19:12:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,706 ms / 3,000 ms |
コード長 | 4,665 bytes |
コンパイル時間 | 1,288 ms |
コンパイル使用メモリ | 134,700 KB |
最終ジャッジ日時 | 2025-02-10 11:09:22 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:173:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 173 | scanf("%d", &K); | ~~~~~^~~~~~~~~~ main.cpp:177:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 177 | scanf("%d%d", &p, &e); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:174:9: warning: ‘n’ may be used uninitialized [-Wmaybe-uninitialized] 174 | int n; | ^
ソースコード
// #include <bits/stdc++.h>#include <string.h>#include <algorithm>#include <array>#include <bitset>#include <cassert>#include <chrono>#include <ciso646>#include <climits>#include <cmath>#include <complex>#include <cstdio>#include <functional>#include <iomanip>#include <iostream>#include <map>#include <numeric>#include <queue>#include <random>#include <set>#include <stack>#include <string>#include <unordered_map>#include <unordered_set>#include <utility>#include <vector>#define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i))#define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i))#define rep(i, n) For(i, 0, n)#define rrep(i, n) rFor(i, n, 0)#define fi first#define se second#include <algorithm>#include <bitset>#include <vector>namespace rklib {struct SimpleSieve {std::vector<bool> is_prime;std::vector<int> prime;SimpleSieve(int n) {is_prime.resize(n + 1, true);is_prime[0] = is_prime[1] = false;for (int i = 2; i <= n; ++i) {if (!is_prime[i]) continue;prime.push_back(i);for (int j = 2; i * j <= n; ++j) {is_prime[i * j] = false;}}}};struct Sieve {std::vector<int> min_factor, prime;Sieve(int n) {min_factor.resize(n + 1, 0);for (int i = 2; i <= n; ++i) {if (min_factor[i] == 0) {min_factor[i] = i;prime.push_back(i);}for (int x : prime) {if (x * i > n || x > i) break;min_factor[x * i] = x;}}}std::vector<std::pair<int, int>> prime_factor(int n) {std::vector<std::pair<int, int>> res;while (n > 1) {if (res.empty() || res.rbegin()->first != min_factor[n]) {res.emplace_back(min_factor[n], 1);} else++res.rbegin()->second;n /= min_factor[n];}return res;}void divisor_dfs(std::vector<std::pair<int, int>> &p, int t, int cur,std::vector<int> &res) {if (cur == (int)p.size()) {res.push_back(t);return;}divisor_dfs(p, t, cur + 1, res);for (int _ = 0; _ < p[cur].second; ++_) {t *= p[cur].first;divisor_dfs(p, t, cur + 1, res);}}std::vector<int> get_divisor(int n, bool sorted = false) {std::vector<int> res;auto p = prime_factor(n);divisor_dfs(p, 1, 0, res);if (sorted) sort(res.begin(), res.end());return res;}};} // namespace rklib#include <algorithm>#include <cassert>#include <vector>namespace rklib {template <class T>bool chmax(T &a, const T &b) {if (a < b) {a = b;return true;}return false;}template <class T>bool chmin(T &a, const T &b) {if (a > b) {a = b;return true;}return false;}template <class T>bool chmin_non_negative(T &a, const T &b) {if (a < 0 || a > b) {a = b;return true;}return false;}template <class T>T div_floor(T a, T b) {if (b < 0) a *= -1, b *= -1;return a >= 0 ? a / b : (a + 1) / b - 1;}template <class T>T div_ceil(T a, T b) {if (b < 0) a *= -1, b *= -1;return a > 0 ? (a - 1) / b + 1 : a / b;}} // namespace rklibusing namespace std;using namespace rklib;using lint = long long;using pii = pair<int, int>;using pll = pair<lint, lint>;int prime_factors[10'000'010];int main() {int K;scanf("%d", &K);int n;rep(i, K) {int p, e;scanf("%d%d", &p, &e);prime_factors[p] += e;if (i == K - 1) n = p;}Sieve sv(n);int cnt_nonzero = K;rep(r, n) {{int tmp = n - r;while (tmp != 1) {int mf = sv.min_factor[tmp];if (prime_factors[mf] == 0) ++cnt_nonzero;--prime_factors[mf];if (prime_factors[mf] == 0) --cnt_nonzero;tmp /= mf;}}{int tmp = r + 1;while (tmp != 1) {int mf = sv.min_factor[tmp];if (prime_factors[mf] == 0) ++cnt_nonzero;++prime_factors[mf];if (prime_factors[mf] == 0) --cnt_nonzero;tmp /= mf;}}if (cnt_nonzero == 0) {printf("%d %d\n", n, r + 1);return 0;}}printf("%d %d\n", -1, -1);}