Submission #757435

#TimeUsernameProblemLanguageResultExecution timeMemory
757435dxz05Brunhilda’s Birthday (BOI13_brunhilda)C++17
20 / 100
1095 ms736 KiB
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define MP make_pair
//#define endl '\n'
 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
 
typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 1e4 + 2;
 
int dp[N];
 
void solve(){
    int m, q;
    cin >> m >> q;
 
    vector<int> primes(m);
    for (int i = 0; i < m; i++) cin >> primes[i];
 
    fill(dp + 1, dp + N, 1e9);
 
    dp[0] = 0;
    for (int i = 1; i < N; i++){
        for (int p : primes){
            dp[i] = min(dp[i], dp[i / p * p] + 1);
        }
    }
 
    for (int i = 1; i < N; i++){
        assert(dp[i] >= dp[i - 1] && dp[i] <= dp[i - 1] + 1 || dp[i] == 1e9);
    }
 
    while (q--){
        int i;
        cin >> i;
        if (dp[i] != 1e9){
            cout << dp[i] << "\n";
        } else {
            cout << "oo\n";
        }
    }
 
}
 
int main(){
    clock_t startTime = clock();
    ios_base::sync_with_stdio(false);
 
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
    int test_cases = 1;
//    cin >> test_cases;
 
    for (int test = 1; test <= test_cases; test++){
        // cout << (solve() ? "YES" : "NO") << endl;
        solve();
    }
 
#ifdef LOCAL
    cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl;
#endif
 
    return 0;
}

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from brunhilda.cpp:4:
brunhilda.cpp: In function 'void solve()':
brunhilda.cpp:40:35: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   40 |         assert(dp[i] >= dp[i - 1] && dp[i] <= dp[i - 1] + 1 || dp[i] == 1e9);
      |                ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:56:13: warning: unused variable 'startTime' [-Wunused-variable]
   56 |     clock_t startTime = clock();
      |             ^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...