Submission #699510

#TimeUsernameProblemLanguageResultExecution timeMemory
699510nguyentunglamLongest beautiful sequence (IZhO17_subsequence)C++17
100 / 100
1751 ms43176 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 1e5 + 10; int a[N], b[N], bit[1 << 11], f[11][1 << 10][1 << 10], k[N], dp[N]; int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n; cin >> n; for(int mask = 0; mask < (1 << 10); mask++) bit[mask] = __builtin_popcount(mask); for(int i = 1; i <= n; i++) { cin >> a[i]; b[i] = (a[i] >> 10); a[i] ^= (b[i] << 10); } int trace = 0; for(int i = 1; i <= n; i++) { cin >> k[i]; dp[i] = 1; for(int j = 0; j < (1 << 10); j++) { int x = bit[a[i] & j]; int y = k[i] - x; if (y < 0 || y > 10) continue; dp[i] = max(dp[i], f[y][j][b[i]] + 1); } for(int j = 0; j < (1 << 10); j++) { int y = bit[b[i] & j]; f[y][a[i]][j] = max(f[y][a[i]][j], dp[i]); } if (dp[trace] < dp[i]) trace = i; } vector<int> ans; ans.push_back(trace); for(int i = trace - 1; i >= 1; i--) { if (bit[a[i] & a[trace]] + bit[b[i] & b[trace]] == k[trace] && dp[i] + 1 == dp[trace]) { ans.push_back(i); trace = i; } } cout << ans.size() << endl; reverse(ans.begin(), ans.end()); for(int &j : ans) cout << j << " "; }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:13:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:14:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:17:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:18:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen (task".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...