제출 #384534

#제출 시각아이디문제언어결과실행 시간메모리
384534antimirageLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define mk make_pair #define pb emplace_back #define all(s) s.begin(), s.end() using namespace std; const int N = 1e5 + 5; int dp[25][1025][1025], p[N], n, ar[N], k, ans, ind[25][1025][1025], last, path[N], sz, cn[N]; main() { freopen("subsequence.in", "r", stdin); freopen("subsequence.out", "w", stdout); for (int j = 0; j < 1024; j++) cn[j] = __builtin_popcount(j); cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &ar[i]); for (int i = 1; i <= n; i++){ scanf("%d", &k); int pref = (ar[i] >> 10); int suf = ar[i] - (pref << 10), res = 0; for (int j = 0; j < 1024; j++) { if ( cn[ j & suf ] <= k && dp[ k - cn[ j & suf ] ][pref][j] > res ) { res = dp[ k - cn[ j & suf ] ][pref][j]; p[i] = ind[ k - cn[ j & suf ] ][pref][j]; } } res++; if (res > ans){ ans = res; last = i; } for (int j = 0; j < 1024; j++){ if (res > dp[cn[pref & j] ][j][suf]) { dp[cn[pref & j] ][j][suf] = res; ind[cn[pref & j] ][j][suf] = i; } } } cout << ans << endl; while (ans--){ path[++sz] = last; last = p[last]; } for (int i = sz; i >= 1; i--) printf("%d ", path[i]); }

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

subsequence.cpp:15:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   15 | main()
      |      ^
subsequence.cpp: In function 'int main()':
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("subsequence.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:18:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   18 |  freopen("subsequence.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |   scanf("%d", &ar[i]);
      |   ~~~~~^~~~~~~~~~~~~~
subsequence.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |   scanf("%d", &k);
      |   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...