Submission #1306166

#TimeUsernameProblemLanguageResultExecution timeMemory
1306166dex111222333444555Longest beautiful sequence (IZhO17_subsequence)C++20
7 / 100
154 ms90216 KiB
#include <bits/stdc++.h> #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define all(v) begin(v), end(v) #define siz(v) (int)(v).size() using namespace std; const int MAXN = 1e5 + 5, MAXB = 10; template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;} template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;} int numVal, val[MAXN], req[MAXN], dp[MASK(MAXB)][MASK(MAXB)][MAXB + 1], pos[MASK(MAXB)][MASK(MAXB)][MAXB + 1], trace[MAXN]; void input(){ cin >> numVal; for(int i = 1; i <= numVal; i++) cin >> val[i]; for(int i = 1; i <= numVal; i++) cin >> req[i]; } #define left(x) (x >> MAXB) #define right(x) (x & (MASK(MAXB) - 1)) #define cntb(x) (__builtin_popcount(x)) void solve(){ for(int i = 1; i <= numVal; i++){ int L = left(val[i]); int R = right(val[i]); int best = 0, bestPos = 0; for(int l = 0; l < MASK(MAXB); l++) if (req[i] >= cntb(l & L) && req[i] <= MAXB) { if (maximize(best, dp[l][R][req[i] - cntb(l & L)])) bestPos = pos[l][R][req[i] - cntb(l & L)]; } trace[i] = bestPos; for(int r = 0; r < MASK(MAXB); r++){ if (maximize(dp[L][r][cntb(r & R)], best + 1)) pos[L][r][cntb(r & R)] = i; } } int res = 0, cur = 0; for(int l = 0; l < MASK(MAXB); l++) for(int r = 0; r < MASK(MAXB); r++) for(int k = 0; k <= MAXB; k++) if (maximize(res, dp[l][r][k])){ cur = pos[l][r][k]; } cout << res << '\n'; vector<int> canPos; while(cur > 0){ canPos.push_back(cur); cur = trace[cur]; } reverse(all(canPos)); for(int x: canPos) cout << x << ' '; cout << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "test" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } input(); solve(); }

Compilation message (stderr)

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