Submission #26494

#TimeUsernameProblemLanguageResultExecution timeMemory
26494samir_droubiBrunhilda’s Birthday (BOI13_brunhilda)C++14
23.65 / 100
1000 ms262144 KiB
#include <bits/stdc++.h> using namespace std; int n,q; const int MX=(1e7); const int mxn=(1e5)+5; int dp[MX]; int a[mxn]; int mx=0; int get(int up,int pr) { if(up%pr==0)return -1; int dif=up-pr; int ans=pr+pr*(dif/pr); return ans; } int calc(int x) { if(x<mx)return 1; if(dp[x]!=-1)return dp[x]; int ans=(1e9); for(int i=0;i<n;++i) { int num=get(x,a[i]); if(num==-1)continue; ans=min(ans,1+calc(num)); } return dp[x]=ans; } int main() { memset(dp,-1,sizeof dp); scanf("%d%d",&n,&q); for(int i=0;i<n;++i) { scanf("%d",&a[i]); mx=max(mx,a[i]); } for(int i=0;i<q;++i) { int x; scanf("%d",&x); int ans=calc(x); if(ans==(1e9))printf("oo\n"); else printf("%d\n",ans); } return 0; }

Compilation message (stderr)

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:33:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&q);
                     ^
brunhilda.cpp:36:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
                    ^
brunhilda.cpp:42:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...