Submission #156534

#TimeUsernameProblemLanguageResultExecution timeMemory
156534combi1k1Brunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
384 ms79612 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e7 + 1; int f[N]; int g[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int m; cin >> m; int q; cin >> q; for(int i = 1 ; i < N ; ++i) f[i] = i; for(int i = 0 ; i < m ; ++i) { int x; cin >> x; for(int j = x ; j < N ; j += x) f[j - 1] = min(f[j - 1],j - x); f[N - 1] = min(f[N - 1],(N - 1) / x * x); } for(int i = N - 2 ; i ; --i) f[i] = min(f[i],f[i + 1]); for(int i = 1 ; i < N ; ++i) { if (f[i] == i) g[i] = 1e9; else g[i] = g[f[i]] + 1; } //for(int i = 1 ; i < 10 ; ++i) // cout << f[i] << " "; //cout << "\n"; for(int i = 0 ; i < q ; ++i) { int x; cin >> x; if (g[x] >= 1e9) cout << "oo\n"; else cout << g[x] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...