Submission #313958

#TimeUsernameProblemLanguageResultExecution timeMemory
313958shivensinha4Brunhilda’s Birthday (BOI13_brunhilda)C++17
0 / 100
46 ms10748 KiB
#include <bits/stdc++.h> using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; #define endl '\n' const int MXV = 10; vi facs[MXV+2]; int ans[MXV+2], curVal[MXV+2]; int main() { #ifdef shiven freopen("test.in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vi primes(n); for_(i, 0, n) cin >> primes[i]; for (int i: primes) for (int j = i; j <= MXV; j += i) facs[j].push_back(i); set<ii> vals; for (int i: primes) vals.insert({0, i}); for_(i, 1, MXV+1) { //cout << i << ":: "; for (auto p: facs[i]) if (vals.count({curVal[p], p})) vals.erase({curVal[p], p}); //for (ii c: vals) cout << c.first << " " << c.second << endl; //cout << endl; if (vals.size()) ans[i] = (*vals.begin()).first+1; else ans[i] = -1; if (ans[i] != -1) for (auto p: facs[i]) vals.insert({curVal[p] = ans[i], p}); //cout << i << ": " << ans[i] << endl; } for_(x, 0, q) { int k; cin >> k; if (ans[k] == -1) cout << "oo"; else cout << ans[k]; cout << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...