답안 #491794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
491794 2021-12-04T13:06:05 Z Victor Brunhilda’s Birthday (BOI13_brunhilda) C++17
97.7778 / 100
421 ms 40624 KB
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const int INF = 1'000'000'007;

int n, q, ans[10'000'001], rem;
priority_queue<ii> pq;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    ans[0] = 0;
    cin >> n >> q;
    rep(i, 0, n) {
        int p;
        cin >> p;
        pq.emplace(0, p);
    }

    rep(i, 1, 10'000'001) {
        while (1) {
            int val, prime;
            tie(val, prime) = pq.top();
            val = -val;

            if (i / prime == val / prime) {
                rem = i - val;
                if (!rem)
                    ans[i] = INF;
                else
                    ans[i] = ans[i - rem] + 1;
                break;
            } else {
                pq.pop();
                pq.emplace(-(i / prime) * prime, prime);
            }
        }
    }

    int val;
    while (q--) {
        cin >> val;
        if (ans[val] == INF)
            cout << "oo" << endl;
        else
            cout << ans[val] << endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 240 ms 39392 KB Output isn't correct
2 Correct 208 ms 39424 KB Output is correct
3 Correct 227 ms 39388 KB Output is correct
4 Correct 171 ms 39380 KB Output is correct
5 Correct 237 ms 39316 KB Output is correct
6 Incorrect 249 ms 39312 KB Output isn't correct
7 Correct 227 ms 39408 KB Output is correct
8 Correct 232 ms 39312 KB Output is correct
9 Correct 273 ms 39364 KB Output is correct
10 Correct 235 ms 39400 KB Output is correct
11 Correct 257 ms 39332 KB Output is correct
12 Correct 179 ms 39364 KB Output is correct
13 Correct 249 ms 39436 KB Output is correct
14 Correct 265 ms 39488 KB Output is correct
15 Correct 191 ms 39440 KB Output is correct
16 Correct 210 ms 39360 KB Output is correct
17 Correct 228 ms 39448 KB Output is correct
18 Correct 164 ms 39340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 39564 KB Output is correct
2 Correct 126 ms 40300 KB Output is correct
3 Correct 172 ms 40196 KB Output is correct
4 Correct 157 ms 39492 KB Output is correct
5 Correct 171 ms 39884 KB Output is correct
6 Correct 138 ms 39376 KB Output is correct
7 Correct 133 ms 39620 KB Output is correct
8 Correct 173 ms 39412 KB Output is correct
9 Correct 213 ms 40068 KB Output is correct
10 Correct 169 ms 40124 KB Output is correct
11 Correct 209 ms 39924 KB Output is correct
12 Correct 167 ms 39408 KB Output is correct
13 Correct 121 ms 39392 KB Output is correct
14 Correct 156 ms 39464 KB Output is correct
15 Correct 197 ms 39852 KB Output is correct
16 Correct 123 ms 40280 KB Output is correct
17 Correct 192 ms 39444 KB Output is correct
18 Correct 148 ms 40308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 40100 KB Output is correct
2 Correct 267 ms 40040 KB Output is correct
3 Correct 326 ms 40132 KB Output is correct
4 Correct 291 ms 39752 KB Output is correct
5 Correct 278 ms 40480 KB Output is correct
6 Correct 316 ms 39788 KB Output is correct
7 Correct 239 ms 40348 KB Output is correct
8 Correct 248 ms 40128 KB Output is correct
9 Correct 251 ms 40016 KB Output is correct
10 Correct 216 ms 39588 KB Output is correct
11 Correct 206 ms 39572 KB Output is correct
12 Correct 219 ms 39588 KB Output is correct
13 Correct 312 ms 40076 KB Output is correct
14 Correct 421 ms 39900 KB Output is correct
15 Correct 244 ms 39508 KB Output is correct
16 Correct 260 ms 39592 KB Output is correct
17 Correct 215 ms 39936 KB Output is correct
18 Correct 266 ms 40032 KB Output is correct
19 Correct 152 ms 39636 KB Output is correct
20 Correct 284 ms 40012 KB Output is correct
21 Correct 338 ms 39928 KB Output is correct
22 Correct 365 ms 40624 KB Output is correct
23 Correct 295 ms 40000 KB Output is correct
24 Correct 272 ms 39740 KB Output is correct
25 Correct 305 ms 39708 KB Output is correct
26 Correct 311 ms 39632 KB Output is correct
27 Correct 289 ms 40432 KB Output is correct
28 Correct 257 ms 39720 KB Output is correct
29 Correct 359 ms 40548 KB Output is correct
30 Correct 358 ms 40332 KB Output is correct
31 Correct 252 ms 39764 KB Output is correct
32 Correct 277 ms 39716 KB Output is correct
33 Correct 247 ms 39592 KB Output is correct
34 Correct 258 ms 40388 KB Output is correct
35 Correct 264 ms 39640 KB Output is correct
36 Correct 339 ms 40404 KB Output is correct
37 Correct 269 ms 40600 KB Output is correct
38 Correct 307 ms 39748 KB Output is correct
39 Correct 284 ms 39832 KB Output is correct
40 Correct 296 ms 39804 KB Output is correct
41 Correct 220 ms 40348 KB Output is correct
42 Correct 338 ms 39952 KB Output is correct