답안 #469690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469690 2021-09-01T15:29:13 Z ymm Gap (APIO16_gap) C++17
100 / 100
61 ms 2036 KB
///
///   Let the voice of love take you higher!
///
 
#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(int x = (l); x < (r); ++x)
#define LoopR(x, l, r) for(int x = (r)-1; x >= (l); --x)
#define all(x) x.begin(), x.end()
#define Kill(x) exit((cout << (x) << '\n', 0))
#define YN(flag) ((flag)? "YES": "NO")
#define F first
#define S second
typedef          long long   ll;
typedef unsigned long long  ull;
typedef std::pair<int,int>  pii;
typedef std::pair<ll ,ll >  pll;
using namespace std;
 
#include "gap.h"
 
/*ll N;
vector<ll> A;
int m1, m2;
void MinMax(ll s, ll t, ll* mn, ll* mx)
{
    int cnt = 0;
    *mn = *mx = -1;
    Loop(i,0,N)
    {
        if(s <= A[i] && A[i] <= t)
        {
            if(!cnt) *mn = A[i];
            *mx = A[i];
            ++cnt;
        }
    }
    m1 += 1;
    m2 += cnt+1;
}*/
 
ll findGap(int t, int n)
{
    if(t==1)
    {
        vector<ll> a, b;
        ll l=0, r=1e18;
        Loop(_,0,n/2)
        {
            MinMax(l,r,&l,&r);
            a.push_back(l);
            b.push_back(r);
            ++l; --r;
        }
        if(n&1) MinMax(l,r,&l,&r), a.push_back(l);
        ll ans = 0;
        Loop(i,1,a.size()) ans = max(ans, a[i]-a[i-1]);
        Loop(i,1,b.size()) ans = max(ans, b[i-1]-b[i]);
        ans = max(ans, b.back()-a.back());
        return ans;
    }
    else
    {
        ll l=0, r=1e18;
        MinMax(l,r,&l,&r);
        ll tmp = (r-l+n-2)/(n-1);
      	ll ans = tmp;
        for(ll m = l+1; m <= r; m += tmp)
        {
            ll mn, mx;
            MinMax(m,m+tmp-1,&mn,&mx);
            if(~mn){
                ans = max(ans, mn-l);
                l = mx;
            }
        }
        return ans;
    }
}
 
/*int main()
{
    A = {1, 2, 3, 5, 6, (ll)1e18};
    N = A.size();
    cout << findGap(2, N) << '\n';
    cout << m1 << ' ' << m2 << '\n';
}
*/

Compilation message

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:8:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define Loop(x, l, r) for(int x = (l); x < (r); ++x)
      |                                          ^
gap.cpp:58:9: note: in expansion of macro 'Loop'
   58 |         Loop(i,1,a.size()) ans = max(ans, a[i]-a[i-1]);
      |         ^~~~
gap.cpp:8:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define Loop(x, l, r) for(int x = (l); x < (r); ++x)
      |                                          ^
gap.cpp:59:9: note: in expansion of macro 'Loop'
   59 |         Loop(i,1,b.size()) ans = max(ans, b[i-1]-b[i]);
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 0 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 0 ms 200 KB Output is correct
9 Correct 0 ms 200 KB Output is correct
10 Correct 0 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 10 ms 800 KB Output is correct
17 Correct 13 ms 712 KB Output is correct
18 Correct 11 ms 712 KB Output is correct
19 Correct 11 ms 712 KB Output is correct
20 Correct 8 ms 712 KB Output is correct
21 Correct 44 ms 1900 KB Output is correct
22 Correct 54 ms 1900 KB Output is correct
23 Correct 42 ms 2004 KB Output is correct
24 Correct 42 ms 1928 KB Output is correct
25 Correct 40 ms 2036 KB Output is correct
26 Correct 53 ms 1996 KB Output is correct
27 Correct 42 ms 1960 KB Output is correct
28 Correct 43 ms 1920 KB Output is correct
29 Correct 45 ms 1944 KB Output is correct
30 Correct 35 ms 2008 KB Output is correct
31 Correct 0 ms 200 KB Output is correct
32 Correct 0 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 0 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 0 ms 200 KB Output is correct
9 Correct 0 ms 200 KB Output is correct
10 Correct 0 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 16 ms 412 KB Output is correct
17 Correct 14 ms 456 KB Output is correct
18 Correct 15 ms 456 KB Output is correct
19 Correct 14 ms 456 KB Output is correct
20 Correct 7 ms 456 KB Output is correct
21 Correct 59 ms 1004 KB Output is correct
22 Correct 59 ms 1168 KB Output is correct
23 Correct 60 ms 1028 KB Output is correct
24 Correct 58 ms 980 KB Output is correct
25 Correct 53 ms 1048 KB Output is correct
26 Correct 61 ms 1076 KB Output is correct
27 Correct 57 ms 1004 KB Output is correct
28 Correct 58 ms 1048 KB Output is correct
29 Correct 58 ms 1052 KB Output is correct
30 Correct 32 ms 1064 KB Output is correct
31 Correct 0 ms 200 KB Output is correct
32 Correct 0 ms 200 KB Output is correct