Submission #94437

#TimeUsernameProblemLanguageResultExecution timeMemory
94437KastandaLongest beautiful sequence (IZhO17_subsequence)C++11
0 / 100
3 ms632 KiB
#include<bits/stdc++.h> using namespace std; const int N = 100005, SQ = 1024; int n, ts, A[N], K[N], P[N], R[N]; pair < int , int > dp[SQ+1][SQ+1][11+1]; inline void MAX(pair < int , int > &a, pair < int , int > b) { a = max(a, b); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &A[i]); for (int i = 1; i <= n; i++) scanf("%d", &K[i]); int nw = 0, _max = 0; for (int i = 1; i <= n; i++) { int a = A[i], k = K[i]; if (__builtin_popcount(a) < k) continue; pair < int , int > Mx = {0, 0}; for (int j = 0; j < SQ; j++) if (k - __builtin_popcount((a >> 10) & j) >= 0) MAX(Mx, dp[j][a & (SQ - 1)][k - __builtin_popcount((a >> 10) & j)]); Mx.first ++; P[i] = Mx.second; Mx.second = i; for (int j = 0; j < SQ; j++) MAX(dp[a >> 10][j][__builtin_popcount(a & (SQ - 1) & j)], Mx); if (Mx.first > _max) _max = Mx.first, nw = i; } if (!nw) nw = 1; while (nw) { R[ts ++] = nw; nw = P[nw]; } printf("%d\n", ts); for (int i = ts - 1; ~i; i--) printf("%d ", R[i]); return 0; }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
subsequence.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
subsequence.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &K[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...