답안 #57509

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57509 2018-07-15T08:01:27 Z 김세빈(#1671) Teams (CEOI11_tea) C++11
100 / 100
855 ms 88848 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

vector <int> V[1010101];
pii K[1010101];
int T[2202020];
int D[1010101], M[1010101];
int n, sz;

void insert(int p)
{
	T[p + sz] = p;
	p += sz;
	
	for(p>>=1;p;p>>=1){
		if(D[T[p<<1]] > D[T[p<<1|1]]) T[p] = T[p<<1];
		else T[p] = T[p<<1|1];
	}
}

int get_max(int l, int r)
{
	int ret = 0;
	
	l += sz; r += sz;
	for(;l<r;){
		if(l & 1){
			if(D[ret] < D[T[l]] || (D[ret] == D[T[l]] && ret < T[l])) ret = T[l];
		}
		if(~r & 1){
			if(D[ret] < D[T[r]] || (D[ret] == D[T[r]] && ret < T[r])) ret = T[r];
		}
		l = l+1 >> 1;
		r = r-1 >> 1;
	}
	if(l == r){
		if(D[ret] < D[T[l]] || (D[ret] == D[T[l]] && ret < T[l])) ret = T[l];
	}
	
	return ret;
}

int main()
{
	int i, j, a, k;
	
	scanf("%d", &n);
	
	for(sz=1;sz<=n;sz<<=1);
	
	for(i=1;i<=n;i++){
		scanf("%d", &a);
		K[i] = pii(a, i);
	}
	
	sort(K+1, K+n+1);
	
	for(i=1;i<=n;i++){
		for(auto t: V[i]) insert(t);
		
		if(i >= K[i].first){
			k = get_max(0, i - K[i].first);
			D[i] = D[k] + 1;
			M[i] = i - k;

			if(i + M[i] <= n){
				V[i + M[i]].push_back(i);
			}
		}
	}
	
	printf("%d\n", D[n]);
	
	for(i=n;i;){
		k = M[i];
		printf("%d ", k);
		for(j=0;j<k;j++,i--) printf("%d ", K[i].second); 
		printf("\n");
	}

	return 0;
}

Compilation message

tea.cpp: In function 'int get_max(int, int)':
tea.cpp:36:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   l = l+1 >> 1;
       ~^~
tea.cpp:37:8: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   r = r-1 >> 1;
       ~^~
tea.cpp: In function 'int main()':
tea.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
tea.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a);
   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 24056 KB Output is correct
2 Correct 26 ms 24056 KB Output is correct
3 Correct 28 ms 24200 KB Output is correct
4 Correct 24 ms 24228 KB Output is correct
5 Correct 24 ms 24228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 24228 KB Output is correct
2 Correct 23 ms 24332 KB Output is correct
3 Correct 21 ms 24332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 24332 KB Output is correct
2 Correct 26 ms 24332 KB Output is correct
3 Correct 22 ms 24332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 24456 KB Output is correct
2 Correct 27 ms 24556 KB Output is correct
3 Correct 24 ms 24648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 24648 KB Output is correct
2 Correct 25 ms 24648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 27404 KB Output is correct
2 Correct 92 ms 29196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 29196 KB Output is correct
2 Correct 103 ms 29196 KB Output is correct
3 Correct 92 ms 29196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 637 ms 69668 KB Output is correct
2 Correct 666 ms 70700 KB Output is correct
3 Correct 536 ms 70700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 647 ms 75992 KB Output is correct
2 Correct 704 ms 88848 KB Output is correct
3 Correct 683 ms 88848 KB Output is correct
4 Correct 766 ms 88848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 628 ms 88848 KB Output is correct
2 Correct 388 ms 88848 KB Output is correct
3 Correct 689 ms 88848 KB Output is correct
4 Correct 855 ms 88848 KB Output is correct