Submission #313955

#TimeUsernameProblemLanguageResultExecution timeMemory
313955shivensinha4Brunhilda’s Birthday (BOI13_brunhilda)C++17
0 / 100
307 ms262148 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 = 1e7; 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); multiset<int> vals; for (int i: primes) vals.insert(0); for_(i, 1, MXV+1) { for (auto p: facs[i]) vals.erase(vals.find(curVal[p])); if (vals.size()) ans[i] = *vals.begin()+1; else ans[i] = -1; for (auto p: facs[i]) vals.insert(curVal[p] = ans[i]); } for_(x, 0, q) { int k; cin >> k; if (ans[k] == -1) cout << "oo"; else cout << ans[k]; cout << endl; } return 0; }

Compilation message (stderr)

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:29:11: warning: unused variable 'i' [-Wunused-variable]
   29 |  for (int i: primes) vals.insert(0);
      |           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...