답안 #885249

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885249 2023-12-09T10:41:04 Z hugsfromadicto Gap (APIO16_gap) C++14
100 / 100
40 ms 2204 KB
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
#define ll long long
#define vi vector<int>
#define vs vector<string>
#define vvi vector<vector<long>>
#define ff first
#define endl '\n'
#define all(a) a.begin(),a.end()
#define ss second
#define pb push_back
#define eb emplace_back
#define sz(x) (int) x.size()
#define vpair vector<pair<int,int>>
#define MAX(a,b,c) max(a,max(b,c))
#define prev name
const int INF=1e9;
const int dx[4]={-1,0,1,0};
const int dy[4]={0,-1,0,1};
const long MAXN=1e18;

ll a[100000],j=0;



ll findGap(int T, int N)
{
    if(T==1){
        ll l=1,r=MAXN;
        ll  mn,mx;
        vi v;
        for(ll i=0;i<(N+1)>>1;++i)
        {
            MinMax(l,r,&mn,&mx);
            a[j++]=mn;
            a[j++]=mx;
            l=mn+1,r=mx-1;
        }
        sort(a,a+N);
        ll ans=0;
        for(ll i=0;i<N;++i)
        {
            ans=max(ans,a[i+1]-a[i]);
        }
        return ans;
    }
    else{
        ll mn,mx;
        MinMax(1,MAXN,&mn,&mx);
        ll s=(mx-mn+N-2)/(N-1);
        ll ans=s,x,y,l=mn,i;
        for(i=mn;i+s<mx;i+=s+1)
        {
            MinMax(i,i+s,&x,&y);
            if(x!=-1)
            {
                ans=max(ans,x-l);
                l=y;
            }
        }
        MinMax(i,mx,&x,&y);
        if(x!=-1)
        {
            ans=max(ans,x-l);
        }
        return ans;
        
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 8 ms 644 KB Output is correct
17 Correct 8 ms 648 KB Output is correct
18 Correct 8 ms 644 KB Output is correct
19 Correct 8 ms 656 KB Output is correct
20 Correct 7 ms 804 KB Output is correct
21 Correct 32 ms 1812 KB Output is correct
22 Correct 31 ms 1976 KB Output is correct
23 Correct 31 ms 1768 KB Output is correct
24 Correct 31 ms 1980 KB Output is correct
25 Correct 28 ms 2204 KB Output is correct
26 Correct 33 ms 1868 KB Output is correct
27 Correct 31 ms 1984 KB Output is correct
28 Correct 31 ms 1976 KB Output is correct
29 Correct 34 ms 1972 KB Output is correct
30 Correct 27 ms 1964 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 10 ms 652 KB Output is correct
17 Correct 9 ms 648 KB Output is correct
18 Correct 9 ms 644 KB Output is correct
19 Correct 10 ms 812 KB Output is correct
20 Correct 5 ms 620 KB Output is correct
21 Correct 39 ms 1224 KB Output is correct
22 Correct 39 ms 1240 KB Output is correct
23 Correct 39 ms 1456 KB Output is correct
24 Correct 39 ms 1220 KB Output is correct
25 Correct 37 ms 1196 KB Output is correct
26 Correct 39 ms 1216 KB Output is correct
27 Correct 38 ms 1216 KB Output is correct
28 Correct 40 ms 1220 KB Output is correct
29 Correct 39 ms 1216 KB Output is correct
30 Correct 20 ms 1204 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 428 KB Output is correct