제출 #160870

#제출 시각아이디문제언어결과실행 시간메모리
160870MohamedAhmed0Longest beautiful sequence (IZhO17_subsequence)C++14
40 / 100
6079 ms182272 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][22] , idx[Middle][Middle][22] , prv[MAX] , ans[MAX] ; void print(int now) { if(now == -1) return ; print(prv[now]) ; printf("%d " , now+1) ; } int vall , valr ; void MeetInTheMiddle(int now , int cnt , int cur , int i) { if(cnt > arr2[i]) return ; if(cur == 10) { if(f[now][valr][arr2[i] - cnt] + 1 > ans[i]) ans[i] = f[now][valr][arr2[i] - cnt] + 1 , prv[i] = idx[now][valr][arr2[i] - cnt] ; return ; } MeetInTheMiddle(now , cnt , cur+1 , i) ; MeetInTheMiddle(now + (1 << cur) , cnt + (!(!(vall & (1 << cur)))) , cur+1 , i) ; return ; } void Update(int now , int cnt , int cur , int i) { if(cur == 10) { if(ans[i] > f[vall][now][cnt]) f[vall][now][cnt] = ans[i] , idx[vall][now][cnt] = i ; return ; } Update(now , cnt , cur+1 , i) ; Update(now + (1 << cur) , cnt + (!(!(valr & (1 << cur)))) , cur+1 , i) ; } 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 ; vall = 0 , valr = 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 < (1 << 10) ; ++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 < (1 << 10) ; ++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 ; }*/ MeetInTheMiddle(0 , 0 , 0 , i) ; Update(0 , 0 , 0 , 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:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d" , &n) ;
  ~~~~~^~~~~~~~~~~
subsequence.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d" , &arr[i]) ;
   ~~~~~^~~~~~~~~~~~~~~~
subsequence.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d" , &arr2[i]) ;
   ~~~~~^~~~~~~~~~~~~~~~~
subsequence.cpp:54: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...