Submission #1125887

#TimeUsernameProblemLanguageResultExecution timeMemory
1125887AgageldiBrunhilda’s Birthday (BOI13_brunhilda)C++20
43.49 / 100
1100 ms149604 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define N 40000005 #define ff first #define ss second #define pb push_back #define sz(s) (int)s.size() ll n, m, q, vis[N], p = -1, vip[N]; vector <ll> a; int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> m >> q; for(ll i = 1;i<=m;i++) { ll x; cin >> x; if(vip[x]) continue; vip[x] = 1; a.pb(x); } for(auto i : a) { for(ll j = i; j <= 1e7; j += i) { vis[j]++; if(vis[j] == sz(a)) { p = j; break; } } if(p != -1) break; } sort(a.rbegin(),a.rend()); for(int j = 1; j <= q; j++) { ll x, cnt = 0; cin >> x; if(p > 0 && x % p == 0) { cout << "oo\n"; continue; } while(x) { if(a[0] > x) { cnt++; break; } ll mx = INT_MAX; for(auto i : a) { if(mx > (x / i) * i) mx = (x / i) * i; if(i - 1 <= x - mx) break; } x = mx; cnt++; } cout << cnt << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...