제출 #719877

#제출 시각아이디문제언어결과실행 시간메모리
719877thiago_bastosBrunhilda’s Birthday (BOI13_brunhilda)C++17
56.83 / 100
1087 ms144616 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("mmx,sse,sse2,sse3,sse4,sse4.1,sse4.2,avx") #include "bits/stdc++.h" using namespace std; //#define INF 1000000000 #define INFLL 1000000000000000000ll #define EPS 1e-9 #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define pb push_back #define fi first #define sc second using i64 = long long; using u64 = unsigned long long; using ld = long double; using ii = pair<int, int>; using i128 = __int128; const int N = 1e7 + 10, INF = 0x3f3f3f3f; int steps[N], maxp[N]; void solve() { int m, q; priority_queue<ii, vector<ii>, greater<ii>> pq; cin >> m >> q; memset(steps, 0x3f, sizeof steps); for(int i = 0; i < m; ++i) { int p; cin >> p; for(int j = 0; j < N; j += p) maxp[j] = p; } pq.emplace(1, maxp[0]); for(int i = 1; i < N; ++i) { while(!pq.empty() && pq.top().sc <= i) pq.pop(); if(!pq.empty()) { steps[i] = pq.top().fi; if(maxp[i]) pq.emplace(steps[i] + 1, i + maxp[i]); } } while(q--) { int n; cin >> n; if(steps[n] == INF) { cout << "oo\n"; continue; } cout << steps[n] << '\n'; } } int main() { ios_base :: sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...