제출 #798075

#제출 시각아이디문제언어결과실행 시간메모리
798075PanosPaskLongest beautiful sequence (IZhO17_subsequence)C++14
23 / 100
6012 ms2360 KiB
#include <bits/stdc++.h> using namespace std; int N; vector<int> dp; vector<int> prv; vector<int> a; vector<int> k; int main(void) { scanf("%d", &N); a.resize(N); k.resize(N); for (int i = 0; i < N; i++) { scanf("%d", &a[i]); } for (int i = 0; i < N; i++) { scanf("%d", &k[i]); } dp.resize(N); prv.resize(N); int maxv = 0, maxpos = 0; for (int i = 0; i < N; i++) { dp[i] = 0; prv[i] = -1; for (int j = i - 1; j >= 0; j--) { if (__builtin_popcount(a[i] & a[j]) == k[i] && dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; prv[i] = j; } } if (dp[i] > maxv) { maxv = dp[i]; maxpos = i; } } vector<int> ans; for (int i = maxpos; i != -1; i = prv[i]) ans.push_back(i); reverse(ans.begin(), ans.end()); printf("%d\n", (int)ans.size()); for (auto i : ans) printf("%d ", i + 1); printf("\n"); return 0; }

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

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