답안 #757442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757442 2023-06-13T07:46:03 Z dxz05 Brunhilda’s Birthday (BOI13_brunhilda) C++17
100 / 100
339 ms 79180 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 = 1e7 + 2;

int dp[N];
int max_p[N];

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

    while (m--){
        int p;
        cin >> p;
        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:70:13: warning: unused variable 'startTime' [-Wunused-variable]
   70 |     clock_t startTime = clock();
      |             ^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 78496 KB Output is correct
2 Correct 67 ms 78492 KB Output is correct
3 Correct 43 ms 78500 KB Output is correct
4 Correct 61 ms 78596 KB Output is correct
5 Correct 76 ms 78456 KB Output is correct
6 Correct 41 ms 78488 KB Output is correct
7 Correct 44 ms 78548 KB Output is correct
8 Correct 51 ms 78548 KB Output is correct
9 Correct 105 ms 78620 KB Output is correct
10 Correct 101 ms 78488 KB Output is correct
11 Correct 107 ms 78492 KB Output is correct
12 Correct 47 ms 78528 KB Output is correct
13 Correct 152 ms 78564 KB Output is correct
14 Correct 195 ms 78620 KB Output is correct
15 Correct 83 ms 78488 KB Output is correct
16 Correct 75 ms 78496 KB Output is correct
17 Correct 99 ms 78620 KB Output is correct
18 Correct 76 ms 78668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 78588 KB Output is correct
2 Correct 85 ms 78500 KB Output is correct
3 Correct 185 ms 78584 KB Output is correct
4 Correct 106 ms 78520 KB Output is correct
5 Correct 131 ms 78620 KB Output is correct
6 Correct 63 ms 78492 KB Output is correct
7 Correct 67 ms 78516 KB Output is correct
8 Correct 104 ms 78588 KB Output is correct
9 Correct 149 ms 78496 KB Output is correct
10 Correct 172 ms 78504 KB Output is correct
11 Correct 173 ms 78552 KB Output is correct
12 Correct 110 ms 78492 KB Output is correct
13 Correct 62 ms 78584 KB Output is correct
14 Correct 101 ms 78492 KB Output is correct
15 Correct 147 ms 78492 KB Output is correct
16 Correct 85 ms 78508 KB Output is correct
17 Correct 159 ms 78492 KB Output is correct
18 Correct 163 ms 78500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 228 ms 78612 KB Output is correct
2 Correct 241 ms 78620 KB Output is correct
3 Correct 260 ms 78752 KB Output is correct
4 Correct 255 ms 78828 KB Output is correct
5 Correct 269 ms 78680 KB Output is correct
6 Correct 297 ms 78876 KB Output is correct
7 Correct 227 ms 78648 KB Output is correct
8 Correct 204 ms 78620 KB Output is correct
9 Correct 208 ms 78616 KB Output is correct
10 Correct 169 ms 78612 KB Output is correct
11 Correct 164 ms 78592 KB Output is correct
12 Correct 194 ms 78680 KB Output is correct
13 Correct 339 ms 78744 KB Output is correct
14 Correct 232 ms 79144 KB Output is correct
15 Correct 191 ms 78636 KB Output is correct
16 Correct 186 ms 78644 KB Output is correct
17 Correct 171 ms 78540 KB Output is correct
18 Correct 287 ms 78584 KB Output is correct
19 Correct 86 ms 78544 KB Output is correct
20 Correct 260 ms 78744 KB Output is correct
21 Correct 245 ms 79180 KB Output is correct
22 Correct 320 ms 78756 KB Output is correct
23 Correct 234 ms 78892 KB Output is correct
24 Correct 196 ms 78844 KB Output is correct
25 Correct 277 ms 78956 KB Output is correct
26 Correct 228 ms 78832 KB Output is correct
27 Correct 288 ms 78620 KB Output is correct
28 Correct 202 ms 78916 KB Output is correct
29 Correct 315 ms 78864 KB Output is correct
30 Correct 287 ms 78708 KB Output is correct
31 Correct 224 ms 78784 KB Output is correct
32 Correct 233 ms 78864 KB Output is correct
33 Correct 185 ms 78832 KB Output is correct
34 Correct 216 ms 78616 KB Output is correct
35 Correct 238 ms 78808 KB Output is correct
36 Correct 304 ms 78708 KB Output is correct
37 Correct 238 ms 78712 KB Output is correct
38 Correct 265 ms 78848 KB Output is correct
39 Correct 228 ms 78764 KB Output is correct
40 Correct 242 ms 78808 KB Output is correct
41 Correct 234 ms 78620 KB Output is correct
42 Correct 313 ms 78880 KB Output is correct