제출 #1109755

#제출 시각아이디문제언어결과실행 시간메모리
1109755Kirill22Longest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
10 ms49744 KiB
#include "bits/stdc++.h" using namespace std; //long long C(int n, int k) { // long long res = 1; // for (int i = 1; i <= n; i++) { // res *= (n - i + 1); // res /= i; // } // return res; //} const int N = 1 << 20, M = 1 << 10; int cnt[N], dp[N], pr[N], mx[N], a[N], k[N], n; //set<pair<int, int>> life[21]; int mitm[M][M][11]; void solve() { for (int i = 1; i < N; i++) { cnt[i] = cnt[i / 2] + (i % 2); } for (int i = 0; i < M; i++) { for (int j = 0; j < M; j++) { fill(mitm[i][j], mitm[i][j] + 11, -1); } } cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> k[i]; } for (int i = 0; i < n; i++) { int x = a[i]; dp[i] = 1, pr[i] = i; for (int msk = 0; msk < (1 << 10); msk++) { int need = k[i] - cnt[msk & (x >> 10)]; if (need < 0 || need > 10) { continue; } int& j = mitm[msk][x % 1024][need]; if (j != -1 && dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; pr[i] = j; } } for (int msk = 0; msk < (1 << 10); msk++) { int need = cnt[msk & (x % 1024)]; int& j = mitm[x >> 10][msk][need]; if (j == -1 || dp[j] < dp[i]) { j = i; } } } pair<int, int> res = {1, 0}; for (int i = 0; i < n; i++) { res = max(res, {dp[i], i}); } cout << res.first << '\n'; vector<int> ans = {res.second}; while (pr[res.second] != res.second) { res.second = pr[res.second]; ans.push_back(res.second); } std::reverse(ans.begin(), ans.end()); for (auto& i : ans) { cout << i + 1 << " "; } cout << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen("subsequence.in", "r", stdin); freopen("subsequence.out", "w", stdout); int t = 1; // cin >> t; while (t--) { solve(); } }

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:78:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |     freopen("subsequence.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:79:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |     freopen("subsequence.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...