Submission #74689

#TimeUsernameProblemLanguageResultExecution timeMemory
74689kjain_1810Brunhilda’s Birthday (BOI13_brunhilda)C++17
97.78 / 100
349 ms78528 KiB
#include<bits/stdc++.h> #define f first #define s second #define pb push_back #define ind(n) scanf("%d", &n) #define ind2(n, m) scanf("%d%d", &n, &m) #define ind3(n, m, k) scanf("%d%d%d", &n, &m, &k) #define inlld(n) scanf("%lld", &n) #define inlld2(n, m) scanf("%lld%lld", &n, &m) #define inlld3(n, m, k) scanf("%lld%lld%lld", &n, &m, &k) using namespace std; const int N=1e7+5; const int MOD=1e9+7; typedef long long ll; typedef long double ld; int n, q; int arr[N], dp[N]; int solve(int i) { if(i==0) return 0; if(dp[i]!=-1) return dp[i]; int ans=-1e8, best=0; if(q==1) { for(int a=n; a>=1; a--) { if(i%arr[a]==0) continue; if(i%arr[a]>ans) { ans=i%arr[a]; best=a; } } } else { for(int a=n; a>=max(1, n-500); a--) { if(i%arr[a]==0) continue; if(i%arr[a]>ans) { ans=i%arr[a]; best=a; } } } if(best) return dp[i]=solve(i-ans)+1; else return 1e8; } signed main() { ind2(n, q); for(int a=1; a<=n; a++) ind(arr[a]); memset(dp, -1, sizeof(dp)); while(q--) { int x; ind(x); int ans=solve(x); if(ans<1e8) printf("%d\n", ans); else printf("oo\n"); } return 0; }

Compilation message (stderr)

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:6:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ind2(n, m) scanf("%d%d", &n, &m)
                    ~~~~~^~~~~~~~~~~~~~~~
brunhilda.cpp:64:5: note: in expansion of macro 'ind2'
     ind2(n, q);
     ^~~~
brunhilda.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ind(n) scanf("%d", &n)
                ~~~~~^~~~~~~~~~
brunhilda.cpp:66:9: note: in expansion of macro 'ind'
         ind(arr[a]);
         ^~~
brunhilda.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ind(n) scanf("%d", &n)
                ~~~~~^~~~~~~~~~
brunhilda.cpp:71:9: note: in expansion of macro 'ind'
         ind(x);
         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...