Submission #1126540

#TimeUsernameProblemLanguageResultExecution timeMemory
1126540AgageldiBrunhilda’s Birthday (BOI13_brunhilda)C++20
100 / 100
436 ms157976 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second #define pb push_back #define sz(s) (int)s.size() #define N 10000005 ll n, m, q, a[N], ad[N], t, dp[N]; int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> m >> q; for(int i = 1; i <= m; i++){ cin >> a[i]; for(int j = a[i]; j <= 1e7 + 1; j += a[i]) { ad[j - 1] = max(ad[j - 1], a[i] - 1); } ad[10000000] = max(ad[10000000], (10000000 % a[i])); } for(int i = 1e7; i >= 1; i--) { ad[i] = max(ad[i], ad[i + 1] - 1); } for(int i = 1; i <= 1e7; i++) { if(!ad[i] || dp[i - ad[i]] == -1) dp[i] = -1; else dp[i] = dp[i - ad[i]] + 1; } for(int i = 1; i <= q; i++) { int x, cnt = 0; cin >> x; if(dp[x] == -1) { cout << "oo\n"; continue; } cout << dp[x] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...