Submission #1126630

#TimeUsernameProblemLanguageResultExecution timeMemory
1126630Yang8onLongest beautiful sequence (IZhO17_subsequence)C++20
0 / 100
7 ms1352 KiB
#include <bits/stdc++.h> #define Y8o "subsequence" #define maxn (int) 1e5 + 5 #define ll long long #define pii pair<int, int> #define gb(i, j) ((i >> j) & 1) #define all(x) x.begin(), x.end() #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define fi(i, a, b) for(int i = a; i <= b; i ++) #define fid(i, a, b) for(int i = a; i >= b; i --) #define cntbit(x) __builtin_popcount(x) //#define f first //#define s second using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll GetRandom(ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rng); } void iof() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); if(fopen(Y8o".inp", "r")) { freopen(Y8o".inp", "r", stdin); // freopen(Y8o".out", "w", stdout); } } void ctime() { cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; } int n; int a[maxn], b[maxn]; namespace sub1 { int dp[maxn], pre[maxn]; vector<int> cur; void solve() { fi(i, 1, n) { dp[i] = 1, pre[i] = i; fi(j, 1, i - 1) if( __builtin_popcount(a[i] & a[j]) == b[i] ) { if(dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; pre[i] = j; } } } int vt = max_element(dp + 1, dp + n + 1) - dp; while(1) { cur.push_back(vt); if(vt == pre[vt]) break; vt = pre[vt]; } reverse(all(cur)); cout << cur.size() << '\n'; for(int x : cur) cout << x << ' '; } }; namespace sub2 { int dp[maxn]; int prepare[1 << 11][1 << 11][11]; vector<int> cur; void trace(int i) { cur.push_back(i); int pre = i; fid(j, i - 1, 1) { if(dp[j] == dp[pre] - 1 && cntbit(a[j] & a[pre]) == b[pre]) { cur.push_back(j); pre = j; } } reverse(all(cur)); } pii cb(int x) { int lef = 0, rig = 0; fi(i, 0, 10) if(gb(x, i)) lef += (1 << i); fi(i, 11, 20) if(gb(x, i)) rig += (1 << (i - 10)); return { lef, rig }; } void solve() { fi(i, 1, n) { int lef, rig; tie(lef, rig) = cb(a[i]); int k = b[i]; fi(l, 0, (1 << 10) - 1) dp[i] = max(dp[i], prepare[l][rig][k - cntbit(l & lef)] + 1); fi(r, 0, (1 << 10) - 1) prepare[lef][r][cntbit(r & rig)] = max(prepare[lef][r][cntbit(r & rig)], dp[i]); } int ans = *max_element(dp + 1, dp + n + 1); fi(i, 1, n) { if(dp[i] == ans) { trace(i); break; } } cout << ans << '\n'; for(int x : cur) cout << x << ' '; } } void solve() { cin >> n ; fi(i, 1, n) cin >> a[i]; fi(i, 1, n) cin >> b[i]; // sub1 :: solve(); sub2 :: solve(); } int main() { iof(); int nTest = 1; // cin >> nTest; while(nTest --) { solve(); } ctime(); return 0; }

Compilation message (stderr)

subsequence.cpp: In function 'void iof()':
subsequence.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...