답안 #861194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861194 2023-10-15T15:46:33 Z Dec0Dedd Gap (APIO16_gap) C++14
100 / 100
45 ms 3876 KB
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;

typedef long long ll;

const ll INF = 1e18;

ll solve1(int n) {
    ll a[n]={};

    ll lf=-1, rf=INF+1, lp=0, rp=n-1;
    while (lp <= rp) {
        ll mn, mx; MinMax(lf+1, rf-1, &mn, &mx);
        if (mn == -1) break;
        a[lp++]=mn, a[rp--]=mx;
        lf=mn, rf=mx;
    }

    ll ans=1;
    for (int i=0; i<n-1; ++i) ans=max(ans, a[i+1]-a[i]);
    return ans;
}

ll solve2(int n) {
    ll lf, rf; MinMax(0, INF, &lf, &rf);
    if (n == 2) return rf-lf;

    ll ans=(rf-lf)/n, d=(rf-lf+(n-2))/(n-1), lst=lf;
    while (lf < rf-1) {
        ll mn, mx; MinMax(lf+1, lf+d, &mn, &mx);
        if (mn != -1) ans=max(ans, mn-lst), lst=mx;
        lf+=d;
    } return ans;
}

ll findGap(int t, int n) {
    if (t == 1) return solve1(n);
    return solve2(n);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2444 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 7 ms 2780 KB Output is correct
17 Correct 7 ms 2752 KB Output is correct
18 Correct 7 ms 2584 KB Output is correct
19 Correct 7 ms 2584 KB Output is correct
20 Correct 6 ms 2572 KB Output is correct
21 Correct 28 ms 3624 KB Output is correct
22 Correct 27 ms 3636 KB Output is correct
23 Correct 31 ms 3876 KB Output is correct
24 Correct 28 ms 3644 KB Output is correct
25 Correct 29 ms 3624 KB Output is correct
26 Correct 28 ms 3624 KB Output is correct
27 Correct 27 ms 3624 KB Output is correct
28 Correct 27 ms 3624 KB Output is correct
29 Correct 27 ms 3820 KB Output is correct
30 Correct 23 ms 3644 KB Output is correct
31 Correct 0 ms 2404 KB Output is correct
32 Correct 0 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2404 KB Output is correct
16 Correct 9 ms 2580 KB Output is correct
17 Correct 9 ms 2580 KB Output is correct
18 Correct 10 ms 2584 KB Output is correct
19 Correct 9 ms 2580 KB Output is correct
20 Correct 5 ms 2588 KB Output is correct
21 Correct 41 ms 2856 KB Output is correct
22 Correct 38 ms 2852 KB Output is correct
23 Correct 38 ms 2860 KB Output is correct
24 Correct 38 ms 3024 KB Output is correct
25 Correct 37 ms 2844 KB Output is correct
26 Correct 39 ms 2676 KB Output is correct
27 Correct 38 ms 2856 KB Output is correct
28 Correct 44 ms 2720 KB Output is correct
29 Correct 45 ms 2856 KB Output is correct
30 Correct 23 ms 2848 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 0 ms 2392 KB Output is correct