답안 #544084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544084 2022-04-01T02:40:00 Z azberjibiou Gap (APIO16_gap) C++17
100 / 100
62 ms 3264 KB
#include "gap.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll solv1(int T, int N)
{
    vector <ll> v;
    ll s=0, e=1000000000000000000, mn, mx;
    for(int i=N;i>0;i-=2)
    {
        MinMax(s, e, &mn, &mx);
        if(i==1)
        {
            v.push_back(mn);
        }
        else    v.push_back(mn), v.push_back(mx);
        s=mn+1;
        e=mx-1;
    }
    sort(v.begin(), v.end());
    ll ans=0;
    for(int i=0;i+1<v.size();i++)
    {
        ans=max(ans, v[i+1]-v[i]);
    }
    return ans;
}
ll solv2(int T, int N)
{
    ll s, e, mn, mx;
    vector <ll> v;
    MinMax(0, 1000000000000000000, &mn, &mx);
    s=mn, e=mx;
    v.push_back(s); v.push_back(e);
    if(N==2)    return mx-mn;
    ll L=e-s, rng=(L%(N-1)==0 ? L/(N-1)-1 : L/(N-1));
    ll pos=s+1;
    while(pos<e)
    {
        MinMax(pos, pos+rng, &mn, &mx);
        if(mn!=-1)
        {
            v.push_back(mn);    v.push_back(mx);
        }
        pos+=rng+1;
    }
    sort(v.begin(), v.end());
    ll ans=0;
    for(int i=0;i+1<v.size();i++)
    {
        ans=max(ans, v[i+1]-v[i]);
    }
    return ans;
}

ll findGap(int T, int N)
{
    if(T==1)    return solv1(T, N);
    else    return solv2(T, N);
}

Compilation message

gap.cpp: In function 'll solv1(int, int)':
gap.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i=0;i+1<v.size();i++)
      |                 ~~~^~~~~~~~~
gap.cpp: In function 'll solv2(int, int)':
gap.cpp:49:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int i=0;i+1<v.size();i++)
      |                 ~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 11 ms 812 KB Output is correct
17 Correct 13 ms 856 KB Output is correct
18 Correct 10 ms 928 KB Output is correct
19 Correct 11 ms 812 KB Output is correct
20 Correct 8 ms 848 KB Output is correct
21 Correct 42 ms 2208 KB Output is correct
22 Correct 41 ms 2240 KB Output is correct
23 Correct 42 ms 2164 KB Output is correct
24 Correct 44 ms 2220 KB Output is correct
25 Correct 43 ms 2188 KB Output is correct
26 Correct 41 ms 2240 KB Output is correct
27 Correct 42 ms 2204 KB Output is correct
28 Correct 41 ms 2212 KB Output is correct
29 Correct 42 ms 2240 KB Output is correct
30 Correct 34 ms 2252 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 13 ms 848 KB Output is correct
17 Correct 13 ms 848 KB Output is correct
18 Correct 16 ms 880 KB Output is correct
19 Correct 13 ms 892 KB Output is correct
20 Correct 7 ms 464 KB Output is correct
21 Correct 55 ms 2192 KB Output is correct
22 Correct 56 ms 2240 KB Output is correct
23 Correct 62 ms 2204 KB Output is correct
24 Correct 59 ms 2200 KB Output is correct
25 Correct 53 ms 3264 KB Output is correct
26 Correct 57 ms 2204 KB Output is correct
27 Correct 52 ms 2172 KB Output is correct
28 Correct 61 ms 2200 KB Output is correct
29 Correct 54 ms 2220 KB Output is correct
30 Correct 28 ms 1444 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct