제출 #222292

#제출 시각아이디문제언어결과실행 시간메모리
222292lycBrunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
566 ms157688 KiB
#include <bits/stdc++.h> using namespace std; #define SZ(x) (int)(x).size() #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define RFOR(i, a, b) for (int i=a;i>=b;--i) const int MX_M = 1e5+5; const int MX_Q = 1e5+5; const int MX_P = 2e7+10; const int infty = 1e9; int M, Q, P[MX_M]; int pi[MX_P], dp[MX_P]; using ii = pair<int, int>; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> M >> Q; FOR(i,1,M){ cin >> P[i]; for (int j = P[i]; j < MX_P; j += P[i]) pi[j-1] = P[i]-1; } RFOR(i,MX_P-2,0) pi[i] = max(pi[i],pi[i+1]-1); dp[0] = 0; FOR(i,1,MX_P-1) { assert(pi[i] >= 0); if (pi[i] == 0) dp[i] = infty; else dp[i] = min(infty,dp[i-pi[i]]+1); } FOR(i,1,Q){ int N; cin >> N; if (dp[N] == infty) cout << "oo" << '\n'; else cout << dp[N] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...