Submission #1155704

#TimeUsernameProblemLanguageResultExecution timeMemory
1155704eudhsyfLongest beautiful sequence (IZhO17_subsequence)C++20
100 / 100
4173 ms207832 KiB
/* Author : */ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define fi first #define se second #define pii pair<int, int> #define pb push_back #define eb emplace_back #define task "file" const int nmax = 1e5 + 5; pii dp[(1 << 10) + 5][(1 << 10) + 5][25]; int a[nmax], b[nmax], pre[nmax], ma, pos, n; signed main () { if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } for (int i = 1; i <= n; i++) { int l = (a[i] >> 10); int r = a[i] % (1 << 10); int lbs = 1; for (int mask = 0; mask < (1 << 10); mask ++) { int x = __builtin_popcount(l & mask); int need = b[i] - x; if(need < 0 || need > 10) { continue; } if(dp[mask][r][need].fi + 1 > lbs) { lbs = dp[mask][r][need].fi + 1; pre[i] = dp[mask][r][need].se; } } if(lbs > ma) { pos = i; ma = lbs; } for (int mask = 0; mask < (1 << 10); mask ++) { int x = __builtin_popcount(r & mask); if(dp[l][mask][x].fi < lbs) { dp[l][mask][x].fi = lbs; dp[l][mask][x].se = i; } } } vector<int> ans; while(pos != 0) { ans.emplace_back(pos); pos = pre[pos]; } cout << ma << '\n'; reverse(ans.begin(), ans.end()); for (auto x : ans) { cout << x << ' '; } return 0; }

Compilation message (stderr)

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