제출 #746208

#제출 시각아이디문제언어결과실행 시간메모리
746208PVSekharLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
113 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MOD = 1e9+7; const ll N=(1<<10); int a[21],k[21]; int dp[N][N][11]; //prev right,cur left half,extra k to match cur left half int ind[N][N][11]; //ind used to reach this state int bc[N][N]; //bit count int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif for(int i=0;i<N;i++)for(int j=0;j<N;j++)for(int k=0;k<21;k++)dp[i][j][k]=0; for(int i=0;i<N;i++)for(int j=0;j<N;j++)for(int k=0;k<21;k++)ind[i][j][k]=-1; for(int i=0;i<N;i++)for(int j=0;j<N;j++)bc[i][j]=__builtin_popcount(i&j); int n; cin>>n; for (int i = 0; i < n; i++)cin>>a[i]; for (int i = 0; i < n; i++)cin>>k[i]; int p[n]; //stores previous index for(int i=0;i<n;i++)p[i]=i; int ans=0,ans_i,len,extra; for (int i = 0; i < n; i++) { int l=a[i]>>(10),r=a[i]%(N); // cout<<l<<" "<<r<<"\n"; len=1; for (int j = 0; j < N; j++) { extra=k[i]-bc[j][r]; if(extra<0||extra>10)continue; if(len<(dp[j][l][extra]+1)){ len=dp[j][l][extra]+1; p[i]=ind[j][l][extra]; } } for (int j = 0; j < N; j++) { if(len>dp[r][j][bc[j][l]]){ dp[r][j][bc[j][l]]=len; ind[r][j][bc[j][l]]=i; // cout<<j<<"\n"; } } if(len>ans){ ans=len; ans_i=i; } // cout<<ans<<"\n"; } cout<<ans<<"\n"; vector<int> temp; while(p[ans_i]!=ans_i){ temp.push_back(ans_i); ans_i=p[ans_i]; } temp.push_back(ans_i); for (int i = ans-1; i >=0 ; i--) { cout<<temp[i]+1<<" "; } cout<<"\n"; return 0; }

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:17:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  freopen("output.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:19:77: warning: iteration 11 invokes undefined behavior [-Waggressive-loop-optimizations]
   19 |     for(int i=0;i<N;i++)for(int j=0;j<N;j++)for(int k=0;k<21;k++)dp[i][j][k]=0;
      |                                                                  ~~~~~~~~~~~^~
subsequence.cpp:19:58: note: within this loop
   19 |     for(int i=0;i<N;i++)for(int j=0;j<N;j++)for(int k=0;k<21;k++)dp[i][j][k]=0;
      |                                                         ~^~~
subsequence.cpp:20:78: warning: iteration 11 invokes undefined behavior [-Waggressive-loop-optimizations]
   20 |     for(int i=0;i<N;i++)for(int j=0;j<N;j++)for(int k=0;k<21;k++)ind[i][j][k]=-1;
      |                                                                  ~~~~~~~~~~~~^~~
subsequence.cpp:20:58: note: within this loop
   20 |     for(int i=0;i<N;i++)for(int j=0;j<N;j++)for(int k=0;k<21;k++)ind[i][j][k]=-1;
      |                                                         ~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...