답안 #1060828

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1060828 2024-08-16T01:42:53 Z sssamui Global Warming (CEOI18_glo) C++17
42 / 100
47 ms 7384 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	ll x;
	cin >> n >> x;
	vector<ll> t(n);
	for (int i = 0; i < n; i++) cin >> t[i];

	vector<pair<int, int>> pref(n);
	vector<ll> lis(0);
	for (int i = 0; i < n; i++)
	{
		if (lis.empty() || (t[i] > lis.back())) pref[i].second = lis.size() + 1;
		else
		{
			int l = 0, r = lis.size() - 1;
			while (l < r)
			{
				int m = l + (r - l) / 2;
				if (lis[m] < t[i]) l = m + 1;
				else r = m;
			}

			pref[i].second = l + 1;
		}

		t[i] -= x;
		if (lis.empty() || (t[i] > lis.back()))
		{
			pref[i].first = lis.size() + 1;
			lis.push_back(t[i]);
		}

		else
		{
			int l = 0, r = lis.size() - 1;
			while (l < r)
			{
				int m = l + (r - l) / 2;
				if (lis[m] < t[i]) l = m + 1;
				else r = m;
			}
			
			pref[i].first = l + 1;
			lis[l] = t[i];
		}
	}

	vector<pair<int, int>> sfx(n);
	vector<ll> lds(0);
	for (int i = n - 1; i > -1; i--)
	{
		if (lds.empty() || (t[i] < lds.back())) sfx[i].second = lds.size() + 1;
		else
		{
			int l = 0, r = lds.size() - 1;
			while (l < r)
			{
				int m = l + (r - l) / 2;
				if (lds[m] > t[i]) l = m + 1;
				else r = m;
			}

			sfx[i].second = l + 1;
		}

		t[i] += x;
		if (lds.empty() || (t[i] < lds.back()))
		{
			sfx[i].first = lds.size() + 1;
			lds.push_back(t[i]);
		}

		else
		{
			int l = 0, r = lds.size() - 1;
			while (l < r)
			{
				int m = l + (r - l) / 2;
				if (lds[m] > t[i]) l = m + 1;
				else r = m;
			}

			sfx[i].second = l + 1;
			lds[l] = t[i];
		}
	}

	int ans = 2;
	for (int i = 0; i < n; i++) ans = fmax(ans, pref[i].first + sfx[i].second);
	for (int i = 0; i < n; i++) ans = fmax(ans, pref[i].second + sfx[i].first);
	ans--;
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 4948 KB Output is correct
2 Correct 47 ms 5172 KB Output is correct
3 Correct 44 ms 4956 KB Output is correct
4 Correct 45 ms 4956 KB Output is correct
5 Correct 23 ms 7384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1628 KB Output is correct
2 Correct 11 ms 1628 KB Output is correct
3 Correct 11 ms 1632 KB Output is correct
4 Incorrect 6 ms 2140 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 2652 KB Output is correct
2 Correct 18 ms 2652 KB Output is correct
3 Correct 36 ms 5104 KB Output is correct
4 Correct 21 ms 7384 KB Output is correct
5 Correct 13 ms 4112 KB Output is correct
6 Correct 17 ms 7124 KB Output is correct
7 Correct 23 ms 7124 KB Output is correct
8 Correct 16 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Halted 0 ms 0 KB -