Submission #274710

# Submission time Handle Problem Language Result Execution time Memory
274710 2020-08-19T14:38:18 Z arnold518 Teams (CEOI11_tea) C++14
0 / 100
162 ms 262148 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;
 
int N, A[MAXN+10];
pii B[MAXN+10];
int dp1[MAXN+10], dp2[MAXN+10];
int pmax[MAXN+10];
deque<int> DQ[MAXN+10];
int memo[MAXN+10];
 
vector<int> V[MAXN+10];

int main()
{
	srand(time(NULL));
	scanf("%d", &N);
	for(int i=1; i<=N; i++) scanf("%d", &A[i]);
	//for(int i=1; i<=N; i++) A[i]=rand()%(N/2)+1;
	for(int i=1; i<=N; i++) B[i]={A[i], i}; 
	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++)
	{
		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;
			while(!DQ[p].empty() && dp2[DQ[p].front()]<=it-DQ[p].front())
			{
				val=DQ[p].front();
				DQ[p].pop_front();
			}
			if(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;
	while(now)
	{
		printf("%d ", now-memo[now]);
		for(int i=now; i>memo[now]; i--) printf("%d ", B[i].second);
		printf("\n"); now=memo[now];
	}
}

Compilation message

tea.cpp: In function 'int main()':
tea.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
tea.cpp:24:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |  for(int i=1; i<=N; i++) scanf("%d", &A[i]);
      |                          ~~~~~^~~~~~~~~~~~~
tea.cpp:47:8: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |    int val;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Runtime error 152 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 151 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 151 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 151 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 149 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 156 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 158 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 159 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 162 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 156 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -