Submission #159756

#TimeUsernameProblemLanguageResultExecution timeMemory
159756Rouge_HugoBrunhilda’s Birthday (BOI13_brunhilda)C++14
0 / 100
1087 ms764 KiB
#include <bits/stdc++.h> using namespace std; int n,q; long long dp[10009]; int a[10009]; long long d(int x) { if (x==0)return 0; if (dp[x]!=-1)return dp[x]; long long mn=1000000000; for(int i=0;i<n;i++) { if (x%a[i]!=0)mn=min(mn,1+d(x-(x%a[i]))); } return mn; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>q; for(int i=0;i<n;i++)cin>>a[i]; sort(a,a+n); int x; memset (dp,-1,sizeof dp); while (q--) { cin>>x; long long u=d(x); if (u>=1000000)cout<<"oo"<<endl; else cout<<u<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...