#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e6+50;
const int mod=1e9+7;
using namespace std;
int n,q,f[nmax],pr[nmax],x,i,j;
bitset<nmax>viz;
set<pair<int,int> >s;
set<pair<int,int> >::iterator it;
vector<int>d[nmax];
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>q;
for(i=1;i<=n;i++)
{
cin>>x;
for(j=x;j<=1e6;j+=x)d[j].pb(x);
s.in(mkp(pr[x],x));
}
for(i=1;i<=1e6;i++)
{
f[i]=inf;
for(j=0;j<(int)d[i].size();j++)viz[d[i][j]]=1;
for(it=s.begin();it!=s.end();it++)
{
if(viz[it->sc])continue;
f[i]=it->fr+1;
break;
}
for(j=0;j<(int)d[i].size();j++)
{
viz[d[i][j]]=0;
s.er(s.fd(mkp(pr[d[i][j]],d[i][j])));
pr[d[i][j]]=f[i];
s.in(mkp(pr[d[i][j]],d[i][j]));
}
}
while(q--)
{
cin>>x;
if(f[x]==inf)cout<<"oo\n";
else cout<<f[x]<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
60 ms |
33016 KB |
Output isn't correct |
2 |
Correct |
262 ms |
50452 KB |
Output is correct |
3 |
Correct |
163 ms |
47308 KB |
Output is correct |
4 |
Correct |
64 ms |
30072 KB |
Output is correct |
5 |
Correct |
107 ms |
36040 KB |
Output is correct |
6 |
Incorrect |
61 ms |
33016 KB |
Output isn't correct |
7 |
Correct |
152 ms |
47352 KB |
Output is correct |
8 |
Correct |
227 ms |
51320 KB |
Output is correct |
9 |
Correct |
328 ms |
53496 KB |
Output is correct |
10 |
Correct |
415 ms |
54520 KB |
Output is correct |
11 |
Correct |
306 ms |
49656 KB |
Output is correct |
12 |
Correct |
54 ms |
29432 KB |
Output is correct |
13 |
Correct |
869 ms |
57468 KB |
Output is correct |
14 |
Correct |
868 ms |
57592 KB |
Output is correct |
15 |
Correct |
276 ms |
50044 KB |
Output is correct |
16 |
Correct |
268 ms |
50440 KB |
Output is correct |
17 |
Correct |
143 ms |
35836 KB |
Output is correct |
18 |
Correct |
65 ms |
30072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
161 ms |
75216 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
93 ms |
63608 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
485 ms |
119352 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
279 ms |
83704 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
775 ms |
122372 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
266 ms |
94968 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
166 ms |
75128 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
255 ms |
79864 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
952 ms |
128996 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
454 ms |
119416 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Execution timed out |
1099 ms |
61980 KB |
Time limit exceeded |
12 |
Incorrect |
484 ms |
52296 KB |
Output isn't correct |
13 |
Runtime error |
124 ms |
76024 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Incorrect |
258 ms |
41464 KB |
Output isn't correct |
15 |
Execution timed out |
1076 ms |
126852 KB |
Time limit exceeded |
16 |
Runtime error |
90 ms |
63608 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Incorrect |
933 ms |
57336 KB |
Output isn't correct |
18 |
Incorrect |
939 ms |
65784 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1010 ms |
64760 KB |
Time limit exceeded |
2 |
Execution timed out |
1087 ms |
64000 KB |
Time limit exceeded |
3 |
Execution timed out |
1101 ms |
63608 KB |
Time limit exceeded |
4 |
Runtime error |
557 ms |
107796 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
103 ms |
65912 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
889 ms |
114936 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
243 ms |
103416 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Execution timed out |
1044 ms |
65180 KB |
Time limit exceeded |
9 |
Execution timed out |
1037 ms |
65144 KB |
Time limit exceeded |
10 |
Runtime error |
634 ms |
103672 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Runtime error |
455 ms |
96504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Runtime error |
828 ms |
113852 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Execution timed out |
1060 ms |
60920 KB |
Time limit exceeded |
14 |
Incorrect |
496 ms |
56056 KB |
Output isn't correct |
15 |
Runtime error |
935 ms |
116728 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Execution timed out |
1085 ms |
117672 KB |
Time limit exceeded |
17 |
Runtime error |
892 ms |
123000 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
18 |
Execution timed out |
1091 ms |
63780 KB |
Time limit exceeded |
19 |
Runtime error |
202 ms |
88952 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Execution timed out |
1099 ms |
63608 KB |
Time limit exceeded |
21 |
Incorrect |
615 ms |
57464 KB |
Output isn't correct |
22 |
Execution timed out |
1097 ms |
67708 KB |
Time limit exceeded |
23 |
Runtime error |
261 ms |
84476 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
24 |
Runtime error |
139 ms |
68600 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
25 |
Runtime error |
624 ms |
106092 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
26 |
Runtime error |
555 ms |
108024 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
27 |
Execution timed out |
1099 ms |
67576 KB |
Time limit exceeded |
28 |
Incorrect |
174 ms |
40312 KB |
Output isn't correct |
29 |
Execution timed out |
1050 ms |
134352 KB |
Time limit exceeded |
30 |
Runtime error |
940 ms |
129520 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
31 |
Runtime error |
246 ms |
83576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
32 |
Runtime error |
317 ms |
88056 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
33 |
Runtime error |
105 ms |
64632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
34 |
Runtime error |
247 ms |
103408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
35 |
Incorrect |
218 ms |
41216 KB |
Output isn't correct |
36 |
Execution timed out |
1057 ms |
66424 KB |
Time limit exceeded |
37 |
Runtime error |
106 ms |
65784 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
38 |
Runtime error |
890 ms |
114936 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
39 |
Runtime error |
177 ms |
72440 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
40 |
Runtime error |
735 ms |
113028 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
41 |
Runtime error |
244 ms |
105324 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
42 |
Incorrect |
998 ms |
58840 KB |
Output isn't correct |