답안 #170969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170969 2019-12-26T19:59:22 Z osaaateiasavtnl Gap (APIO16_gap) C++17
100 / 100
73 ms 2680 KB
#include<bits/stdc++.h>
#include "gap.h"
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e5 + 7;
const int T = 1000 * 1000 * 1000;
const int INF = T * T;
int al[N], ar[N];
long long findGap(signed group, signed n)
{
    if (group == 2) {
        int l, r;
        MinMax(0, INF, &l, &r);

        if (n == 2)
            return r - l;

        int len = r - l + 1;
        int k = len % (n - 1);
        int t = len / (n - 1) + 1;
        
        int ptr = l;
        for (int i = 0; i < k; ++i) {
            MinMax(ptr, ptr + t - 1, &al[i], &ar[i]);
            ptr += t;
        }   
        --t;
        for (int i = k; i < n - 1; ++i) {
            MinMax(ptr, ptr + t - 1, &al[i], &ar[i]);
            ptr += t;
        }   

        int ans = 0;
        r = -1;
        for (int i = 0; i < n - 1; ++i) {
            if (al[i] == -1)
                continue;
            if (r != -1) 
                ans = max(ans, al[i] - r);
            r = ar[i];
        }   
        return ans;
    }
    else {
        int l = -1, r = INF + 1;
        int ans = 0;
        for (int i = 0; i < (n + 1) / 2; ++i) {
            int nl, nr;
            MinMax(l + 1, r - 1, &nl, &nr);
            if (nl == -1) {
                break;
            }
            else {
                if (l != -1)
                    ans = max(ans, nl - l);
                if (r != INF + 1)
                    ans = max(ans, r - nr);
                l = nl;
                r = nr;
            }   
        }   
        ans = max(ans, r - l);
        return ans;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 380 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 15 ms 504 KB Output is correct
17 Correct 14 ms 504 KB Output is correct
18 Correct 15 ms 632 KB Output is correct
19 Correct 15 ms 504 KB Output is correct
20 Correct 11 ms 504 KB Output is correct
21 Correct 54 ms 1144 KB Output is correct
22 Correct 54 ms 1144 KB Output is correct
23 Correct 53 ms 1272 KB Output is correct
24 Correct 54 ms 1148 KB Output is correct
25 Correct 45 ms 1144 KB Output is correct
26 Correct 53 ms 1144 KB Output is correct
27 Correct 54 ms 1176 KB Output is correct
28 Correct 54 ms 1144 KB Output is correct
29 Correct 53 ms 1144 KB Output is correct
30 Correct 40 ms 1144 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 19 ms 1016 KB Output is correct
17 Correct 19 ms 888 KB Output is correct
18 Correct 19 ms 888 KB Output is correct
19 Correct 19 ms 892 KB Output is correct
20 Correct 10 ms 1016 KB Output is correct
21 Correct 72 ms 2680 KB Output is correct
22 Correct 72 ms 2680 KB Output is correct
23 Correct 72 ms 2680 KB Output is correct
24 Correct 72 ms 2680 KB Output is correct
25 Correct 68 ms 2680 KB Output is correct
26 Correct 73 ms 2680 KB Output is correct
27 Correct 72 ms 2680 KB Output is correct
28 Correct 72 ms 2664 KB Output is correct
29 Correct 72 ms 2680 KB Output is correct
30 Correct 39 ms 2680 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct