// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const int INF = 1'000'000'007;
int n, q, ans[10'000'001], rem;
priority_queue<ii> pq;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
ans[0] = 0;
cin >> n >> q;
rep(i, 0, n) {
int p;
cin >> p;
pq.emplace(0, p);
}
rep(i, 1, 10'001) {
while (1) {
int val, prime;
tie(val, prime) = pq.top();
val = -val;
if (i / prime == val / prime) {
rem = i - val;
if (!rem)
ans[i] = INF;
else
ans[i] = ans[i - rem]+1;
break;
} else {
pq.pop();
pq.emplace(-(i / prime) * prime, prime);
}
}
}
int val;
while (q--) {
cin >> val;
if(ans[val]==INF)cout<<"oo"<<endl;
else cout << ans[val] << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
12 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
12 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
14 ms |
384 KB |
Output is correct |
18 |
Correct |
15 ms |
432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
2 |
Incorrect |
11 ms |
2124 KB |
Output isn't correct |
3 |
Incorrect |
9 ms |
1868 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
5 |
Incorrect |
6 ms |
1232 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
9 |
Incorrect |
12 ms |
1968 KB |
Output isn't correct |
10 |
Incorrect |
9 ms |
1948 KB |
Output isn't correct |
11 |
Incorrect |
5 ms |
1232 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
1232 KB |
Output isn't correct |
16 |
Incorrect |
14 ms |
2192 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
18 |
Incorrect |
13 ms |
2124 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
62 ms |
1580 KB |
Output isn't correct |
2 |
Incorrect |
45 ms |
1540 KB |
Output isn't correct |
3 |
Incorrect |
78 ms |
1732 KB |
Output isn't correct |
4 |
Incorrect |
116 ms |
1280 KB |
Output isn't correct |
5 |
Incorrect |
155 ms |
2980 KB |
Output isn't correct |
6 |
Incorrect |
126 ms |
1476 KB |
Output isn't correct |
7 |
Incorrect |
80 ms |
2496 KB |
Output isn't correct |
8 |
Incorrect |
58 ms |
1616 KB |
Output isn't correct |
9 |
Incorrect |
59 ms |
1584 KB |
Output isn't correct |
10 |
Incorrect |
19 ms |
680 KB |
Output isn't correct |
11 |
Incorrect |
43 ms |
856 KB |
Output isn't correct |
12 |
Incorrect |
34 ms |
820 KB |
Output isn't correct |
13 |
Incorrect |
127 ms |
1804 KB |
Output isn't correct |
14 |
Incorrect |
118 ms |
1276 KB |
Output isn't correct |
15 |
Incorrect |
36 ms |
796 KB |
Output isn't correct |
16 |
Incorrect |
34 ms |
772 KB |
Output isn't correct |
17 |
Incorrect |
25 ms |
1340 KB |
Output isn't correct |
18 |
Incorrect |
45 ms |
1476 KB |
Output isn't correct |
19 |
Incorrect |
35 ms |
772 KB |
Output isn't correct |
20 |
Incorrect |
77 ms |
1688 KB |
Output isn't correct |
21 |
Incorrect |
163 ms |
1248 KB |
Output isn't correct |
22 |
Incorrect |
147 ms |
2876 KB |
Output isn't correct |
23 |
Incorrect |
131 ms |
1908 KB |
Output isn't correct |
24 |
Incorrect |
130 ms |
1272 KB |
Output isn't correct |
25 |
Incorrect |
122 ms |
1384 KB |
Output isn't correct |
26 |
Incorrect |
114 ms |
1224 KB |
Output isn't correct |
27 |
Incorrect |
79 ms |
2440 KB |
Output isn't correct |
28 |
Incorrect |
132 ms |
1412 KB |
Output isn't correct |
29 |
Incorrect |
139 ms |
2968 KB |
Output isn't correct |
30 |
Incorrect |
134 ms |
2492 KB |
Output isn't correct |
31 |
Incorrect |
115 ms |
1348 KB |
Output isn't correct |
32 |
Incorrect |
119 ms |
1272 KB |
Output isn't correct |
33 |
Incorrect |
128 ms |
1320 KB |
Output isn't correct |
34 |
Incorrect |
81 ms |
2512 KB |
Output isn't correct |
35 |
Incorrect |
128 ms |
1344 KB |
Output isn't correct |
36 |
Incorrect |
141 ms |
2848 KB |
Output isn't correct |
37 |
Incorrect |
144 ms |
2976 KB |
Output isn't correct |
38 |
Incorrect |
125 ms |
1448 KB |
Output isn't correct |
39 |
Incorrect |
134 ms |
1376 KB |
Output isn't correct |
40 |
Incorrect |
121 ms |
1536 KB |
Output isn't correct |
41 |
Incorrect |
79 ms |
2624 KB |
Output isn't correct |
42 |
Incorrect |
127 ms |
1384 KB |
Output isn't correct |