제출 #160878

#제출 시각아이디문제언어결과실행 시간메모리
160878MohamedAhmed04Longest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
14 ms1912 KiB
#include <bits/stdc++.h>
 
using namespace std ;
 
const int MAX = 1e5 + 10 ;
const int Middle = 1 << 10 ;
int arr[MAX] , arr2[MAX] , f[Middle][Middle][11] , idx[Middle][Middle][11] , prv[MAX] , ans[MAX] ;
 
void print(int now)
{
	if(now == -1)
		return ;
	print(prv[now]) ;
	printf("%d " , now+1) ;
}
 
int main()
{
	int n ;
	scanf("%d" , &n) ;
	for(int i = 0 ; i < n ; ++i)
		scanf("%d" , &arr[i]) ;
	for(int i = 0 ; i < n ; ++i)
		scanf("%d" , &arr2[i]) ;
	int Max = 0 , en ;
	for(int i = 0 ; i < n ; ++i)
	{
		prv[i] = -1 ;
		ans[i] = 1 ;
		int valr = 0 , vall = 0 ;
		for(int j = 0 ; j <= 9 ; ++j)
		{
			if((arr[i] & (1 << j)))
				valr += (1 << j) ;
			if((arr[i] & (1 << (j+10))))
				vall += (1 << j) ;
		}
		for(int j = 0 ; j < Middle ; ++j)
		{
			int x = __builtin_popcount((vall & j)) ;
			if(x > arr2[i])
				continue ;
			if(f[j][valr][arr2[i] - x] + 1 > ans[i])
				ans[i] = f[j][valr][arr2[i] - x] + 1 , prv[i] = idx[j][valr][arr2[i] - x] ;
		}
		for(int j = 0 ; j < Middle ; ++j)
		{
			int x = __builtin_popcount((valr & j)) ;
			if(ans[i] > f[vall][j][x])
				f[vall][j][x] = ans[i] , idx[vall][j][x] = i ;
		}
		if(ans[i] > Max)
			Max = ans[i] , en = i ;
	}
	printf("%d\n" , Max) ;
	print(en) ;
	return 0 ;
}

컴파일 시 표준 에러 (stderr) 메시지

subsequence.cpp: In function 'int main()':
subsequence.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d" , &n) ;
  ~~~~~^~~~~~~~~~~
subsequence.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d" , &arr[i]) ;
   ~~~~~^~~~~~~~~~~~~~~~
subsequence.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d" , &arr2[i]) ;
   ~~~~~^~~~~~~~~~~~~~~~~
subsequence.cpp:25:16: warning: 'en' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int Max = 0 , en ;
                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...