#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
//#define int long long int
using namespace std;
int dp[10000001];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m, q;
cin >> m >> q;
vector<int> P(m);
for(int i = 0; i < m; i++) cin >> P[i];
for(int i = 1; i <= 1e7; i++){
dp[i] = 1e9;
for(int j = m - 1; j >= 0 && j >= m - 10; j--){
dp[i] = min(dp[i], dp[i - i % P[j]] + 1);
}
}
while(q--){
int n;
cin >> n;
if(dp[n] >= 1e9) cout << "oo\n";
else cout << dp[n] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
276 ms |
39416 KB |
Output is correct |
2 |
Correct |
815 ms |
39404 KB |
Output is correct |
3 |
Correct |
449 ms |
39416 KB |
Output is correct |
4 |
Incorrect |
742 ms |
39516 KB |
Output isn't correct |
5 |
Correct |
878 ms |
39428 KB |
Output is correct |
6 |
Correct |
281 ms |
39544 KB |
Output is correct |
7 |
Correct |
472 ms |
39492 KB |
Output is correct |
8 |
Correct |
539 ms |
39468 KB |
Output is correct |
9 |
Correct |
917 ms |
39520 KB |
Output is correct |
10 |
Correct |
866 ms |
39544 KB |
Output is correct |
11 |
Correct |
896 ms |
39512 KB |
Output is correct |
12 |
Correct |
836 ms |
39404 KB |
Output is correct |
13 |
Correct |
691 ms |
39520 KB |
Output is correct |
14 |
Correct |
696 ms |
39536 KB |
Output is correct |
15 |
Correct |
800 ms |
39552 KB |
Output is correct |
16 |
Correct |
821 ms |
39840 KB |
Output is correct |
17 |
Incorrect |
811 ms |
39576 KB |
Output isn't correct |
18 |
Incorrect |
736 ms |
39544 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
596 ms |
39568 KB |
Output is correct |
2 |
Correct |
564 ms |
39800 KB |
Output is correct |
3 |
Correct |
589 ms |
39800 KB |
Output is correct |
4 |
Incorrect |
643 ms |
39416 KB |
Output isn't correct |
5 |
Correct |
710 ms |
39672 KB |
Output is correct |
6 |
Incorrect |
642 ms |
39544 KB |
Output isn't correct |
7 |
Correct |
583 ms |
39548 KB |
Output is correct |
8 |
Incorrect |
681 ms |
39416 KB |
Output isn't correct |
9 |
Correct |
608 ms |
39800 KB |
Output is correct |
10 |
Correct |
619 ms |
39800 KB |
Output is correct |
11 |
Incorrect |
628 ms |
39752 KB |
Output isn't correct |
12 |
Incorrect |
658 ms |
39468 KB |
Output isn't correct |
13 |
Incorrect |
604 ms |
39472 KB |
Output isn't correct |
14 |
Incorrect |
659 ms |
39544 KB |
Output isn't correct |
15 |
Correct |
618 ms |
39672 KB |
Output is correct |
16 |
Correct |
560 ms |
39928 KB |
Output is correct |
17 |
Correct |
677 ms |
39416 KB |
Output is correct |
18 |
Incorrect |
576 ms |
39888 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
635 ms |
39800 KB |
Output is correct |
2 |
Incorrect |
594 ms |
39708 KB |
Output isn't correct |
3 |
Correct |
594 ms |
39800 KB |
Output is correct |
4 |
Incorrect |
670 ms |
39784 KB |
Output isn't correct |
5 |
Correct |
630 ms |
40096 KB |
Output is correct |
6 |
Incorrect |
671 ms |
39928 KB |
Output isn't correct |
7 |
Correct |
580 ms |
39928 KB |
Output is correct |
8 |
Correct |
667 ms |
39768 KB |
Output is correct |
9 |
Correct |
605 ms |
39928 KB |
Output is correct |
10 |
Incorrect |
649 ms |
39636 KB |
Output isn't correct |
11 |
Incorrect |
648 ms |
39544 KB |
Output isn't correct |
12 |
Incorrect |
657 ms |
39544 KB |
Output isn't correct |
13 |
Incorrect |
626 ms |
39944 KB |
Output isn't correct |
14 |
Incorrect |
840 ms |
40824 KB |
Output isn't correct |
15 |
Incorrect |
654 ms |
39672 KB |
Output isn't correct |
16 |
Incorrect |
654 ms |
39672 KB |
Output isn't correct |
17 |
Incorrect |
598 ms |
39672 KB |
Output isn't correct |
18 |
Incorrect |
600 ms |
39800 KB |
Output isn't correct |
19 |
Incorrect |
594 ms |
39664 KB |
Output isn't correct |
20 |
Correct |
597 ms |
39928 KB |
Output is correct |
21 |
Incorrect |
787 ms |
40824 KB |
Output isn't correct |
22 |
Correct |
612 ms |
40056 KB |
Output is correct |
23 |
Incorrect |
615 ms |
39928 KB |
Output isn't correct |
24 |
Incorrect |
670 ms |
39820 KB |
Output isn't correct |
25 |
Incorrect |
688 ms |
40024 KB |
Output isn't correct |
26 |
Incorrect |
674 ms |
39800 KB |
Output isn't correct |
27 |
Correct |
586 ms |
40052 KB |
Output is correct |
28 |
Incorrect |
658 ms |
39932 KB |
Output isn't correct |
29 |
Correct |
607 ms |
40184 KB |
Output is correct |
30 |
Correct |
623 ms |
40276 KB |
Output is correct |
31 |
Incorrect |
632 ms |
39672 KB |
Output isn't correct |
32 |
Incorrect |
679 ms |
39976 KB |
Output isn't correct |
33 |
Incorrect |
654 ms |
39932 KB |
Output isn't correct |
34 |
Correct |
572 ms |
39928 KB |
Output is correct |
35 |
Incorrect |
663 ms |
40056 KB |
Output isn't correct |
36 |
Correct |
608 ms |
40056 KB |
Output is correct |
37 |
Correct |
579 ms |
40056 KB |
Output is correct |
38 |
Incorrect |
669 ms |
39836 KB |
Output isn't correct |
39 |
Incorrect |
676 ms |
39800 KB |
Output isn't correct |
40 |
Incorrect |
649 ms |
39704 KB |
Output isn't correct |
41 |
Correct |
572 ms |
39928 KB |
Output is correct |
42 |
Incorrect |
695 ms |
40056 KB |
Output isn't correct |