Submission #757438

# Submission time Handle Problem Language Result Execution time Memory
757438 2023-06-13T07:43:29 Z dxz05 Brunhilda’s Birthday (BOI13_brunhilda) C++17
20 / 100
15 ms 1380 KB
#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];
int max_p[N];

void solve(){
    int m, q;
    cin >> m >> q;

    vector<int> primes(m);
    for (int i = 0; i < m; i++) cin >> primes[i];

    for (int p : primes){
        for (int i = 0; i < N; i += p) max_p[i] = p;
    }

    fill(dp + 1, dp + N, 1e9);

    int l = 0, r = 0;
    int val = 0;

    while (r < N){
        if (l > r) break;

        int nxt_r = r;
        for (int i = l; i <= r; i++){
            dp[i] = val;

            int p = max_p[i];
            if (p == 0) continue;
            nxt_r = max(nxt_r, i + p - 1);
        }

        nxt_r = min(nxt_r, N - 1);
        l = r + 1;
        r = nxt_r;
        val++;
    }

    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

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:71:13: warning: unused variable 'startTime' [-Wunused-variable]
   71 |     clock_t startTime = clock();
      |             ^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 13 ms 408 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 12 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 15 ms 416 KB Output is correct
18 Correct 14 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 724 KB Execution killed with signal 11
2 Runtime error 10 ms 1364 KB Execution killed with signal 11
3 Runtime error 7 ms 1108 KB Execution killed with signal 11
4 Runtime error 1 ms 596 KB Execution killed with signal 11
5 Runtime error 5 ms 980 KB Execution killed with signal 11
6 Runtime error 1 ms 596 KB Execution killed with signal 11
7 Runtime error 2 ms 724 KB Execution killed with signal 11
8 Runtime error 1 ms 596 KB Execution killed with signal 11
9 Runtime error 7 ms 1108 KB Execution killed with signal 11
10 Runtime error 8 ms 1108 KB Execution killed with signal 11
11 Runtime error 6 ms 852 KB Execution killed with signal 11
12 Runtime error 1 ms 596 KB Execution killed with signal 11
13 Runtime error 1 ms 596 KB Execution killed with signal 11
14 Runtime error 2 ms 596 KB Execution killed with signal 11
15 Runtime error 6 ms 852 KB Execution killed with signal 11
16 Runtime error 9 ms 1364 KB Execution killed with signal 11
17 Runtime error 2 ms 596 KB Execution killed with signal 11
18 Runtime error 9 ms 1364 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 924 KB Execution killed with signal 11
2 Runtime error 5 ms 980 KB Execution killed with signal 11
3 Runtime error 5 ms 980 KB Execution killed with signal 11
4 Runtime error 1 ms 596 KB Execution killed with signal 11
5 Runtime error 10 ms 1364 KB Execution killed with signal 11
6 Runtime error 2 ms 596 KB Execution killed with signal 11
7 Runtime error 11 ms 1364 KB Execution killed with signal 11
8 Runtime error 5 ms 1056 KB Execution killed with signal 11
9 Runtime error 5 ms 980 KB Execution killed with signal 11
10 Runtime error 1 ms 596 KB Execution killed with signal 11
11 Runtime error 2 ms 596 KB Execution killed with signal 11
12 Runtime error 1 ms 596 KB Execution killed with signal 11
13 Runtime error 3 ms 852 KB Execution killed with signal 11
14 Runtime error 1 ms 596 KB Execution killed with signal 11
15 Runtime error 1 ms 596 KB Execution killed with signal 11
16 Runtime error 2 ms 596 KB Execution killed with signal 11
17 Runtime error 4 ms 980 KB Execution killed with signal 11
18 Runtime error 8 ms 980 KB Execution killed with signal 11
19 Runtime error 2 ms 596 KB Execution killed with signal 11
20 Runtime error 6 ms 924 KB Execution killed with signal 11
21 Runtime error 1 ms 596 KB Execution killed with signal 11
22 Runtime error 9 ms 1364 KB Execution killed with signal 11
23 Runtime error 4 ms 852 KB Execution killed with signal 11
24 Runtime error 1 ms 596 KB Execution killed with signal 11
25 Runtime error 2 ms 596 KB Execution killed with signal 11
26 Runtime error 1 ms 596 KB Execution killed with signal 11
27 Runtime error 10 ms 1380 KB Execution killed with signal 11
28 Runtime error 1 ms 596 KB Execution killed with signal 11
29 Runtime error 9 ms 1380 KB Execution killed with signal 11
30 Runtime error 6 ms 1108 KB Execution killed with signal 11
31 Runtime error 1 ms 596 KB Execution killed with signal 11
32 Runtime error 1 ms 596 KB Execution killed with signal 11
33 Runtime error 1 ms 596 KB Execution killed with signal 11
34 Runtime error 9 ms 1372 KB Execution killed with signal 11
35 Runtime error 1 ms 596 KB Execution killed with signal 11
36 Runtime error 9 ms 1336 KB Execution killed with signal 11
37 Runtime error 9 ms 1368 KB Execution killed with signal 11
38 Runtime error 3 ms 596 KB Execution killed with signal 11
39 Runtime error 1 ms 596 KB Execution killed with signal 11
40 Runtime error 3 ms 596 KB Execution killed with signal 11
41 Runtime error 9 ms 1364 KB Execution killed with signal 11
42 Runtime error 1 ms 596 KB Execution killed with signal 11