이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include "gap.h"
using namespace std;
typedef long long ll;
#define mod 1000000007
#define SIZE 10000
long long findGap1(int T, int N){
ll l = 0, r = 1e18;
vector<ll> vec;
while(1){
ll a, b;
MinMax(l,r,&a,&b);
if(a==-1) break;
vec.push_back(a);
if(a==b) break;
vec.push_back(b);
if(a+1==b) break;
if(vec.size() == N) break;
l = a+1;
r = b-1;
}
sort(vec.begin(),vec.end());
ll ans = 0;
for(int i=1;i<vec.size();i++)
ans = max(ans, vec[i] - vec[i-1]);
return ans;
}
long long findGap(int T, int N){
if(T==1) return findGap1(T,N);
ll MAX = 1e18;
ll l, r;
vector<ll> vec;
MinMax(0,(ll)1e18,&l,&r); //N
ll D = r-l+1 - N;
ll B = (D+(N-1))/N + 2;
vec.push_back(l);
vec.push_back(r);
for(ll s = l+1;s<r;s+=B){
ll a,b;
MinMax(s,s+B-1,&a,&b);
if(a!=-1 && a==b){
vec.push_back(a);
}else if(a!=-1){
vec.push_back(a);
vec.push_back(b);
}
}
sort(vec.begin(),vec.end());
ll ans = 0;
for(int i=1;i<vec.size();i++)
ans = max(ans, vec[i] - vec[i-1]);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
gap.cpp: In function 'long long int findGap1(int, int)':
gap.cpp:35:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(vec.size() == N) break;
~~~~~~~~~~~^~~~
gap.cpp:45:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<vec.size();i++)
~^~~~~~~~~~~
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:83:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<vec.size();i++)
~^~~~~~~~~~~
gap.cpp:55:6: warning: unused variable 'MAX' [-Wunused-variable]
ll MAX = 1e18;
^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |