제출 #631373

#제출 시각아이디문제언어결과실행 시간메모리
631373CDuongBrunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
699 ms157376 KiB
#include <bits/stdc++.h> #define int long long #define pb push_back #define mp make_pair #define ff first #define ss second #define endl '\n' #define pii pair<int, int> using namespace std; const int mxN = 2e7; const int mod = 1e9 + 7; int m, Q, dp[mxN]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen("Bai3.inp", "r", stdin); //freopen("Bai3.out", "w", stdout); cin >> m >> Q; for(int i = 1; i <= m; ++i){ int p; cin >> p; for(int j = p - 1; j < mxN; j += p){ dp[j] = max(dp[j], p - 1); } } for(int i = mxN - 2; i >= 0; --i){ dp[i] = max(dp[i], dp[i + 1] - 1); } dp[0] = 0; for(int i = 1; i < mxN; ++i){ if(dp[i] > 0){ dp[i] = 1 + dp[i - dp[i]]; } else{ dp[i] = mod; } } while(Q--){ int x; cin >> x; if(dp[x] >= mxN) cout << "oo" << endl; else cout << dp[x] << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...