답안 #238197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238197 2020-06-10T07:24:49 Z thtsshz_bgwrswh Gap (APIO16_gap) C++17
100 / 100
74 ms 2288 KB
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<vector>
#include<assert.h>
#include<algorithm>
#include "gap.h"
using namespace std;
vector<long long> num;
long long findGap(int T,int N){
	long long i;
	if(T==1){
		long long i,maxv=1000000000000000000,minv=0,ans,ans2;
		while(maxv>=minv&&num.size()<N){
			MinMax(minv,maxv,&ans,&ans2);
			if(ans==-1||ans2==-1)
				break;
			if(ans==ans2){
				num.emplace_back(ans);
				break;
			}
			num.emplace_back(ans);
			num.emplace_back(ans2);
			maxv=ans2-1;
			minv=ans+1;
		}
		sort(num.begin(),num.end());
		ans=0;
		for(i=1;i<num.size();i++)
			ans=max(ans,num[i]-num[i-1]);
		return ans;
	}
	else{
		long long minv,maxv;
		MinMax(0,1000000000000000000,&minv,&maxv);
		long long block=(maxv-minv)/(N-1)+1;
		long long ans=block-1,pre=minv,l,r;
		for(i=minv+1;i+block-1<maxv;i+=block){
			MinMax(i,i+block-1,&l,&r);
			if(pre!=-1&&l!=-1)
				ans=max(ans,l-pre);
			if(r!=-1)
				pre=r;
		}
		if(i<maxv&&pre!=-1){
			MinMax(i,maxv-1,&l,&r);
			if(l==-1)
				l=maxv;
			ans=max(ans,l-pre);
		}
		else if(i==maxv&&pre!=-1)
			ans=max(ans,maxv-pre);	
		return ans;
	}
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:13:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(maxv>=minv&&num.size()<N){
                     ~~~~~~~~~~^~
gap.cpp:28:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(i=1;i<num.size();i++)
           ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 17 ms 872 KB Output is correct
17 Correct 21 ms 896 KB Output is correct
18 Correct 19 ms 896 KB Output is correct
19 Correct 19 ms 896 KB Output is correct
20 Correct 14 ms 896 KB Output is correct
21 Correct 59 ms 2288 KB Output is correct
22 Correct 65 ms 2224 KB Output is correct
23 Correct 57 ms 2288 KB Output is correct
24 Correct 58 ms 2264 KB Output is correct
25 Correct 50 ms 2208 KB Output is correct
26 Correct 57 ms 2288 KB Output is correct
27 Correct 57 ms 2288 KB Output is correct
28 Correct 66 ms 2288 KB Output is correct
29 Correct 57 ms 2260 KB Output is correct
30 Correct 43 ms 2288 KB Output is correct
31 Correct 4 ms 256 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 432 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 22 ms 512 KB Output is correct
17 Correct 20 ms 640 KB Output is correct
18 Correct 19 ms 512 KB Output is correct
19 Correct 19 ms 512 KB Output is correct
20 Correct 12 ms 512 KB Output is correct
21 Correct 71 ms 1144 KB Output is correct
22 Correct 71 ms 1144 KB Output is correct
23 Correct 67 ms 1116 KB Output is correct
24 Correct 74 ms 1124 KB Output is correct
25 Correct 61 ms 1172 KB Output is correct
26 Correct 70 ms 1108 KB Output is correct
27 Correct 72 ms 1200 KB Output is correct
28 Correct 74 ms 1068 KB Output is correct
29 Correct 68 ms 1148 KB Output is correct
30 Correct 37 ms 1280 KB Output is correct
31 Correct 4 ms 256 KB Output is correct
32 Correct 4 ms 256 KB Output is correct