답안 #58978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58978 2018-07-20T00:10:33 Z Benq Brunhilda’s Birthday (BOI13_brunhilda) C++14
100 / 100
556 ms 83992 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 10000001;

int m,Q, mx = MOD, ans[MX], mxP[MX];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> m >> Q;
    F0R(i,m) {
        int p; cin >> p;
        for (int j = 0; j < MX; j += p) mxP[j] = max(mxP[j],p);
    }
    array<int,3> cur = {0,0,0};
    while (1) {
        int nex = cur[2];
        FOR(i,cur[1],cur[2]+1) nex = max(nex,i+mxP[i]-1);
        nex = min(nex,MX-1);
        if (nex == cur[2]) {
            mx = cur[2];
            break;
        }
        cur[0] ++;
        cur[1] = cur[2]+1; cur[2] = nex;
        FOR(i,cur[1],cur[2]+1) ans[i] = cur[0];
    }
    F0R(i,Q) {
        int x; cin >> x;
        if (x > mx) cout << "oo";
        else cout << ans[x];
        cout << "\n";
    }
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 39544 KB Output is correct
2 Correct 157 ms 78792 KB Output is correct
3 Correct 87 ms 78792 KB Output is correct
4 Correct 124 ms 78792 KB Output is correct
5 Correct 155 ms 78792 KB Output is correct
6 Correct 65 ms 78792 KB Output is correct
7 Correct 91 ms 78792 KB Output is correct
8 Correct 105 ms 78792 KB Output is correct
9 Correct 178 ms 78792 KB Output is correct
10 Correct 213 ms 78864 KB Output is correct
11 Correct 205 ms 78864 KB Output is correct
12 Correct 115 ms 78932 KB Output is correct
13 Correct 379 ms 78932 KB Output is correct
14 Correct 406 ms 78956 KB Output is correct
15 Correct 180 ms 78956 KB Output is correct
16 Correct 175 ms 78956 KB Output is correct
17 Correct 160 ms 78956 KB Output is correct
18 Correct 135 ms 78956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 78956 KB Output is correct
2 Correct 195 ms 79004 KB Output is correct
3 Correct 456 ms 79004 KB Output is correct
4 Correct 192 ms 79024 KB Output is correct
5 Correct 356 ms 79024 KB Output is correct
6 Correct 189 ms 79024 KB Output is correct
7 Correct 148 ms 79032 KB Output is correct
8 Correct 189 ms 79032 KB Output is correct
9 Correct 406 ms 79032 KB Output is correct
10 Correct 492 ms 79032 KB Output is correct
11 Correct 463 ms 79032 KB Output is correct
12 Correct 241 ms 79032 KB Output is correct
13 Correct 130 ms 79032 KB Output is correct
14 Correct 189 ms 79032 KB Output is correct
15 Correct 388 ms 79032 KB Output is correct
16 Correct 177 ms 79032 KB Output is correct
17 Correct 465 ms 79032 KB Output is correct
18 Correct 414 ms 79032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 79288 KB Output is correct
2 Correct 520 ms 79564 KB Output is correct
3 Correct 473 ms 80016 KB Output is correct
4 Correct 293 ms 80864 KB Output is correct
5 Correct 227 ms 80864 KB Output is correct
6 Correct 413 ms 81536 KB Output is correct
7 Correct 342 ms 81732 KB Output is correct
8 Correct 427 ms 82056 KB Output is correct
9 Correct 390 ms 82360 KB Output is correct
10 Correct 347 ms 82516 KB Output is correct
11 Correct 265 ms 82612 KB Output is correct
12 Correct 346 ms 82752 KB Output is correct
13 Correct 495 ms 83148 KB Output is correct
14 Correct 256 ms 83248 KB Output is correct
15 Correct 373 ms 83248 KB Output is correct
16 Correct 422 ms 83248 KB Output is correct
17 Correct 387 ms 83248 KB Output is correct
18 Correct 483 ms 83248 KB Output is correct
19 Correct 175 ms 83248 KB Output is correct
20 Correct 506 ms 83560 KB Output is correct
21 Correct 313 ms 83992 KB Output is correct
22 Correct 491 ms 83992 KB Output is correct
23 Correct 221 ms 83992 KB Output is correct
24 Correct 192 ms 83992 KB Output is correct
25 Correct 328 ms 83992 KB Output is correct
26 Correct 315 ms 83992 KB Output is correct
27 Correct 556 ms 83992 KB Output is correct
28 Correct 187 ms 83992 KB Output is correct
29 Correct 518 ms 83992 KB Output is correct
30 Correct 431 ms 83992 KB Output is correct
31 Correct 218 ms 83992 KB Output is correct
32 Correct 271 ms 83992 KB Output is correct
33 Correct 157 ms 83992 KB Output is correct
34 Correct 355 ms 83992 KB Output is correct
35 Correct 188 ms 83992 KB Output is correct
36 Correct 549 ms 83992 KB Output is correct
37 Correct 239 ms 83992 KB Output is correct
38 Correct 396 ms 83992 KB Output is correct
39 Correct 231 ms 83992 KB Output is correct
40 Correct 350 ms 83992 KB Output is correct
41 Correct 309 ms 83992 KB Output is correct
42 Correct 449 ms 83992 KB Output is correct