Submission #386119

#TimeUsernameProblemLanguageResultExecution timeMemory
386119ak2006Brunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
389 ms116720 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; const ll mod = 1e9 + 7,inf = 1e18; #define pb push_back #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int main() { fast; int n,t; cin>>n>>t; vi p(n),lp(1e7 + 5); vi dp(1e7 + 5); for (int i = 0;i<n;i++){ cin>>p[i]; for (int j = 0;j<=1e7;j+=p[i])lp[j] = p[i]; } int ptr = 0; deque<int>a; a.push_back(0); for (int i = 1;i<=1e7;i++){ while (ptr + lp[ptr] <= i)ptr++; while (!a.empty() && a.front() < ptr)a.pop_front(); if (a.empty())dp[i] = 1e7 + 5; else dp[i] = 1 + dp[a.front()]; while (!a.empty() && dp[a.back()] > dp[i])a.pop_back(); a.push_back(i); } while (t--){ int n; cin>>n; if (dp[n] > 1e7)cout<<"oo"<<'\n'; else cout<<dp[n]<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...