답안 #274854

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
274854 2020-08-19T17:24:48 Z arnold518 Teams (CEOI11_tea) C++14
80 / 100
591 ms 153244 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int MAXN = 1e6;
const int INF = 987654321;

struct dequeue
{
	int st;
	vector<int> V;
	dequeue() : st(0) {} 
	bool empty() { return st==V.size(); }
	void push_back(int x) { V.push_back(x); }
	void push_front(int x) { V[--st]=x; }
	void pop_back() { V.pop_back(); }
	void pop_front() { st++; }
	int front() { return V[st]; }
	int back() { return V.back(); }
};

int N;
pii B[MAXN+10];
int dp1[MAXN+10], dp2[MAXN+10];
int pmax[MAXN+10];
dequeue DQ[MAXN+10];
int memo[MAXN+10]; 
vector<int> V[MAXN+10];

int main()
{
	scanf("%d", &N);
	for(int i=1; i<=N; i++) scanf("%d", &B[i].first), B[i].second=i;
	//for(int i=1; i<=N; i++) A[i]=rand()%(N/2)+1;
	sort(B+1, B+N+1);
 
	for(int i=1; i<=N; i++)
	{
		dp1[i]=-INF;
		if(i-B[i].first>=0)
		{
			dp1[i]=pmax[i-B[i].first]+1;
			V[i-B[i].first].push_back(i);
		}
		pmax[i]=max(pmax[i-1], dp1[i]);
	}

	for(int i=0; i<=N; i++)
	{
		if(dp1[i]!=-INF)
		{
			while(!DQ[dp1[i]].empty() && dp2[DQ[dp1[i]].back()]>=dp2[i]) DQ[dp1[i]].pop_back();
			DQ[dp1[i]].push_back(i);
		}
		for(auto it : V[i])
		{
			int p=dp1[it]-1;
			int val=-1;
			while(!DQ[p].empty() && dp2[DQ[p].front()]<=it-DQ[p].front())
			{
				val=DQ[p].front();
				DQ[p].pop_front();
			}
			if(val!=-1 && (DQ[p].empty() || max(it-val, dp2[val])<dp2[DQ[p].front()])) DQ[p].push_front(val);
			dp2[it]=max(it-DQ[p].front(), dp2[DQ[p].front()]);
			memo[it]=DQ[p].front();
		}
	}

	printf("%d\n", dp1[N]);
	int now=N; int cnt=0;
	while(now)
	{
		printf("%d ", now-memo[now]); cnt++;
		for(int i=now; i>memo[now]; i--) printf("%d ", B[i].second);
		printf("\n"); now=memo[now];
	}
	assert(cnt==dp1[N]);
}

Compilation message

tea.cpp: In member function 'bool dequeue::empty()':
tea.cpp:16:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  bool empty() { return st==V.size(); }
      |                        ~~^~~~~~~~~~
tea.cpp: In function 'int main()':
tea.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
tea.cpp:36:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |  for(int i=1; i<=N; i++) scanf("%d", &B[i].first), B[i].second=i;
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 55288 KB Output is correct
2 Correct 37 ms 55204 KB Output is correct
3 Correct 36 ms 55168 KB Output is correct
4 Correct 35 ms 55168 KB Output is correct
5 Correct 36 ms 55168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 55180 KB Output is correct
2 Correct 37 ms 55216 KB Output is correct
3 Correct 36 ms 55160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 55160 KB Output is correct
2 Correct 37 ms 55104 KB Output is correct
3 Correct 37 ms 55160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 55424 KB Output is correct
2 Correct 43 ms 55416 KB Output is correct
3 Correct 40 ms 55424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 55424 KB Output is correct
2 Correct 37 ms 55424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 70 ms 59896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 73 ms 60792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 396 ms 104852 KB Output is correct
2 Correct 352 ms 104312 KB Output is correct
3 Correct 359 ms 100980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 484 ms 118112 KB Output is correct
2 Correct 591 ms 153244 KB Output is correct
3 Correct 510 ms 119416 KB Output is correct
4 Correct 509 ms 109944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 503 ms 102884 KB Output is correct
2 Correct 388 ms 78840 KB Output is correct
3 Correct 498 ms 119288 KB Output is correct
4 Correct 548 ms 116216 KB Output is correct