제출 #94427

#제출 시각아이디문제언어결과실행 시간메모리
94427KastandaLongest beautiful sequence (IZhO17_subsequence)C++11
40 / 100
133 ms2936 KiB
#include<bits/stdc++.h> using namespace std; const int N = 100005, MAX = 256; int n, ts, A[N], K[N], dp[N], P[N], R[N]; pair < int , int > dp2[MAX]; inline void BruteForce() { int nw = 0; for (int i = 1; i <= n; i++) { int k = K[i]; int &Mx = dp[i], &a = A[i], &p = P[i]; for (int j = 1; j < i; j++) if (__builtin_popcount(a & A[j]) == k && Mx < dp[j]) {Mx = dp[j]; p = j;} dp[i] ++; if (dp[i] > dp[nw]) nw = i; } while (nw) { R[ts ++] = nw; nw = P[nw]; } printf("%d\n", ts); for (int i = ts - 1; ~i; i--) printf("%d ", R[i]); exit(0); } 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]); if (n <= 10000) BruteForce(); int nw = 0, _max = 0; for (int i = 1; i <= n; i++) { int Mx = 0; for (int j = 0; j < MAX; j++) if (__builtin_popcount(A[i] & j) == K[i] && Mx < dp2[j].first) Mx = dp2[j].first, P[i] = dp2[j].second; Mx ++; if (Mx > dp2[A[i]].first) dp2[A[i]] = {Mx, i}; if (Mx > _max) nw = i, _max = Mx; } 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; }

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
subsequence.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
subsequence.cpp:36: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...