이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
bool isPrime(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return n > 1;
}
int INF = 1e9;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
clock_t startTime = clock();
int n, q, N = 1e7;
cin >> n >> q;
vector<int> primes(n), g(N + 1), dp(N + 1, INF);
iota(g.begin(), g.end(), 0);
for (int &p: primes) {
cin >> p;
}
sort(primes.rbegin(), primes.rend());
for (int i = 0; i < n; i++) {
int p = primes[i];
for (int j = 0; j <= N; j += p) {
for (int k = min(N, j + p - 1); k > j and j < g[k]; k--) {
g[k] = j;
}
}
}
dp[0] = 0;
for (int i = 1; i <= N; i++) {
dp[i] = dp[g[i]] + 1;
}
while (q--) {
int x;
cin >> x;
if (dp[x] >= INF) {
cout << "oo\n";
} else {
cout << dp[x] << '\n';
}
}
#ifdef sunnitov
cerr << "\nTime: " << (int)((double)(clock() - startTime) / CLOCKS_PER_SEC * 1000);
#endif
}
컴파일 시 표준 에러 (stderr) 메시지
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:18:13: warning: unused variable 'startTime' [-Wunused-variable]
18 | clock_t startTime = clock();
| ^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |