Submission #473007

#TimeUsernameProblemLanguageResultExecution timeMemory
473007hidden1Brunhilda’s Birthday (BOI13_brunhilda)C++14
80.32 / 100
328 ms79936 KiB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define debug(...) cout << "Line: " << __LINE__ << endl; \
    printDebug(", "#__VA_ARGS__, __VA_ARGS__)
template <typename T>
void printDebug(const char* name, T&& arg1) { cout << (name + 2) << " = " << arg1 << endl; }
template <typename T, typename... T2>
void printDebug(const char* names, T&& arg1, T2&&... args) {
    const char* end = strchr(names + 1, ',');
    cout.write(names + 2, end - names - 2) << " = " << arg1 << endl;
    printDebug(end, args...);
}

const int MAX_N = 1e5 + 10;
const int MAX_Q = 1e7 + 10;
int arr[MAX_N];
int dp[MAX_Q], best[MAX_Q];
int n, m;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> m;
    for(int i = 0; i < n; i ++) {
        cin >> arr[i];
        for(int j = arr[i] - 1; j < MAX_Q; j += arr[i]) {
            chkmax(best[j], arr[i] - 1);
        }
    }
    for(int i = MAX_Q - 2; i >= 0; i --) {
        chkmax(best[i], best[i + 1] - 1);
    }
    fill_n(dp, MAX_Q - 1, mod);
    dp[0] = 0;
    for(int i = 1; i < MAX_Q; i ++) {
        dp[i] = dp[i - best[i]] + 1;
    }

    while(m --) {
        int x;
        cin >> x;
        if(dp[x] > mod) {
            cout << "oo" << endl;
        } else {
            cout << dp[x] << endl;
        }
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...