답안 #706803

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706803 2023-03-07T19:01:27 Z 600Mihnea Gap (APIO16_gap) C++17
100 / 100
54 ms 3628 KB
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>

#include "gap.h"

using namespace std;

long long findGap1(int t, int n)
{
	long long ST = 0;
	long long DR = (long long)1e18;
	
	vector<long long> a(n);

	for (int i = 0; i <= n - 1 - i; i++)
	{
		MinMax(ST, DR, &ST, &DR);
		int j = n - 1 - i;
		a[i] = ST;
		a[j] = DR;
		ST++;
		DR--;
	}
	long long best_gap = (a[n - 1] - a[0] + (n - 2)) / (n - 1);
	for (int i = 0; i + 1 < n; i++)
	{
		best_gap = max(best_gap, a[i + 1] - a[i]);
	}
	return best_gap;
}

long long findGap(int t, int n)
{
	if (t == 1)
	{
		return findGap1(t, n);
	}
	long long ST = 0;
	long long DR = (long long)1e18;

	MinMax(ST, DR, &ST, &DR);
	
	long long best_gap = (DR - ST + (n - 2)) / (n - 1);

	vector<long long> pivots;
	for (int j = 0; j < n; j++)
	{
		pivots.push_back(ST + j * best_gap);
	}
	pivots.back() = DR + 1;


	vector<pair<long long, long long>> intel(n - 1);
	for (int i = 0; i < n - 1; i++)
	{
		if (pivots[i] > pivots[i + 1] - 1)
		{
			intel[i] = { -1, -1 };
			continue;
		}
		MinMax(pivots[i], pivots[i + 1] - 1, &intel[i].first, &intel[i].second);
		//cout << i<<" : "<<intel[i].first << " " << intel[i].second << "\n";
	}
	for (int i = 0; i < n - 2; i++)
	{
		if (intel[i].second == -1)
		{
			continue;
		}
		int j = i + 1;
		while (j < n - 1 && intel[j].first == -1)
		{
			j++;
		}
		if (j < n - 1)
		{
			assert(intel[j].first != -1);
			best_gap = max(best_gap, intel[j].first - intel[i].second);
		}
	}

	return best_gap;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 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 1 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 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 8 ms 684 KB Output is correct
17 Correct 10 ms 680 KB Output is correct
18 Correct 10 ms 724 KB Output is correct
19 Correct 8 ms 720 KB Output is correct
20 Correct 7 ms 720 KB Output is correct
21 Correct 33 ms 1824 KB Output is correct
22 Correct 32 ms 1840 KB Output is correct
23 Correct 33 ms 1812 KB Output is correct
24 Correct 34 ms 1832 KB Output is correct
25 Correct 28 ms 1852 KB Output is correct
26 Correct 34 ms 1768 KB Output is correct
27 Correct 33 ms 1864 KB Output is correct
28 Correct 37 ms 1840 KB Output is correct
29 Correct 32 ms 1832 KB Output is correct
30 Correct 28 ms 1824 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 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 324 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 1240 KB Output is correct
17 Correct 12 ms 1148 KB Output is correct
18 Correct 13 ms 1120 KB Output is correct
19 Correct 11 ms 1228 KB Output is correct
20 Correct 6 ms 1228 KB Output is correct
21 Correct 47 ms 3480 KB Output is correct
22 Correct 49 ms 3480 KB Output is correct
23 Correct 50 ms 3628 KB Output is correct
24 Correct 48 ms 3472 KB Output is correct
25 Correct 45 ms 3524 KB Output is correct
26 Correct 54 ms 3580 KB Output is correct
27 Correct 48 ms 3524 KB Output is correct
28 Correct 49 ms 3480 KB Output is correct
29 Correct 49 ms 3572 KB Output is correct
30 Correct 27 ms 3484 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct