답안 #1108923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1108923 2024-11-05T16:53:20 Z csibe_csavo Global Warming (CEOI18_glo) C++14
55 / 100
2000 ms 6860 KB
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int n,d;
int lis(vector<int> &v)
{
	vector<int> s{v[1]};
	for(int i=2; i<=n; i++)
	{
		int ind=lower_bound(s.begin(),s.end(),v[i])-s.begin();
		if(ind>=s.size()) s.push_back(v[i]);
		else s[ind]=v[i];
	}
	int p=s.size();
	return p;
}
void brute()
{
	vector<int> v(n+1);
	for(int i=1; i<=n; i++)
		cin>>v[i];
	int ans=lis(v);
	for(int i=1; i<n; i++)
	{
		v[i]-=d;
		if(d!=0) ans=max(ans,lis(v));
	}
	cout<<ans<<"\n";
}
void nagyd()
{
	vector<int> v(n+2);
	for(int i=1; i<=n; i++)
		cin>>v[i];
	vector<int> dpel(n+2),dphat(n+2);
	vector<pair<int, int>> lis;
	dpel[1]=1;
	lis.push_back({0,0});
	v[n+1]=2e9+3;
	for(int i=1; i<=n; i++)
	{
		if(v[i]>lis.back().first)
		{
			dpel[i]=dpel[lis.back().second]+1;
			lis.push_back({v[i],i});
		}
		else
		{
			int lo=0,hi=lis.size();
			while(lo<hi-1)
			{
				int mid=(lo+hi)/2;
				if(lis[mid].first<v[i]) lo=mid;
				else hi=mid;
			}
			dpel[i]=dpel[lis[lo].second]+1;
			lis[hi]={v[i],i};
		}
	}
	lis.clear();
	for(int i=1; i<=n+1; i++)
		v[i]=-v[i];
	lis.push_back({v[n+1],n+1});
	for(int i=n; i>0; i--)
	{
		if(v[i]>lis.back().first)
		{
			dphat[i]=dphat[lis.back().second]+1;
			lis.push_back({v[i],i});
		}
		else
		{
			int lo=0,hi=lis.size();
			while(lo<hi-1)
			{
				int mid=(lo+hi)/2;
				if(lis[mid].first<v[i]) lo=mid;
				else hi=mid;
			}
			dphat[i]=dphat[lis[lo].second]+1;
			lis[hi]={v[i],i};
		}
	}
	vector<int> prefmax(n+1),sufmax(n+2);
	for(int i=1; i<=n; i++)
		prefmax[i]=max(prefmax[i-1],dpel[i]);
	for(int i=n; i>0; i--)
		sufmax[i]=max(sufmax[i+1],dphat[i]);
	int ans=1;
	for(int i=0; i<=n; i++)
		ans=max(ans,prefmax[i]+sufmax[i+1]);
	cout<<ans<<"\n";
}
int p=1e9;
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>d;
	if(p==d) nagyd();
	else brute();
}

Compilation message

glo.cpp: In function 'int lis(std::vector<int>&)':
glo.cpp:11:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |   if(ind>=s.size()) s.push_back(v[i]);
      |      ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 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 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 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 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 9 ms 336 KB Output is correct
20 Correct 9 ms 336 KB Output is correct
21 Correct 9 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 14 ms 464 KB Output is correct
24 Correct 10 ms 336 KB Output is correct
25 Correct 8 ms 336 KB Output is correct
26 Correct 8 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1104 KB Output is correct
2 Correct 28 ms 3028 KB Output is correct
3 Correct 25 ms 3152 KB Output is correct
4 Correct 25 ms 3164 KB Output is correct
5 Correct 20 ms 3020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2058 ms 592 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 2376 KB Output is correct
2 Correct 20 ms 3152 KB Output is correct
3 Correct 41 ms 6240 KB Output is correct
4 Correct 31 ms 6352 KB Output is correct
5 Correct 10 ms 3280 KB Output is correct
6 Correct 20 ms 6092 KB Output is correct
7 Correct 31 ms 6860 KB Output is correct
8 Correct 17 ms 3408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 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 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 9 ms 336 KB Output is correct
20 Correct 9 ms 336 KB Output is correct
21 Correct 9 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 14 ms 464 KB Output is correct
24 Correct 10 ms 336 KB Output is correct
25 Correct 8 ms 336 KB Output is correct
26 Correct 8 ms 468 KB Output is correct
27 Correct 23 ms 1104 KB Output is correct
28 Correct 28 ms 3028 KB Output is correct
29 Correct 25 ms 3152 KB Output is correct
30 Correct 25 ms 3164 KB Output is correct
31 Correct 20 ms 3020 KB Output is correct
32 Execution timed out 2058 ms 592 KB Time limit exceeded
33 Halted 0 ms 0 KB -