Submission #66180

#TimeUsernameProblemLanguageResultExecution timeMemory
66180MatheusLealVBrunhilda’s Birthday (BOI13_brunhilda)C++17
100 / 100
302 ms41132 KiB
#include <bits/stdc++.h> #define N 100050 using namespace std; int n, q, p[N], dp[10000005], prox[10000005]; int solve(int x) { if(!x) return 0; if(dp[x] != -1) return dp[x]; int ans = -2000000000, opt = 0; for(int i = n; i >= (q == 1 ? 1 : max(1, n - 500)); i--) { if(x % p[i] == 0) continue; if(x % p[i] > ans) { ans = x % p[i]; opt = i; } } return dp[x] = opt ? solve(x - ans) + 1: 2000000000; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>q; for(int i = 1; i <= n; i++) cin>>p[i]; sort(p + 1, p + n + 1); memset(dp, -1, sizeof dp); for(int i = 1, x; i <= q; i++) { cin>>x; int s = solve(x); if(s >= 2000000000) cout<<"oo\n"; else cout<<s<<"\n"; //print(x); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...