Submission #515478

#TimeUsernameProblemLanguageResultExecution timeMemory
515478MazaalaiLongest beautiful sequence (IZhO17_subsequence)C++17
7 / 100
6004 ms7996 KiB
#include <bits/stdc++.h> #define pb push_back #define LINE "--------------------\n" #define ALL(x) x.begin(),x.end() using namespace std; const int N = 1e5+5; const int M = (1<<20)+5; int n; int nums[N], bits[N], par[N], dpPos[N], dpVal[M], pos[M]; int bitCnt(int a) { return bitset <20>(a).count(); } int dfs(int& num, int leftBits, int tarBits, int pow, int pre) { // cout << num << " " << pre << ' ' << pow << ' ' << leftBits << ' ' << tarBits << '\n'; if (tarBits == 0 && pow < 0) { // cout << num << ": " << pre << "\n"; return pre; } if (leftBits < tarBits || pow < 0) return 0; int a = dfs(num, leftBits-(num&(1<<pow) ? 1 : 0), tarBits, pow-1, pre); int b = 0; if (num & (1<<pow)) b = dfs(num, leftBits-1, tarBits-1, pow-1, pre+(1<<pow)); else b = dfs(num, leftBits, tarBits, pow-1, pre+(1<<pow)); if (dpVal[b] > dpVal[a]) a = b; return a; } signed main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; int ans = 1; for (int i = 1; i <= n; i++) cin >> nums[i]; for (int i = 1; i <= n; i++) cin >> bits[i]; for (int i = 1; i <= n; i++) { int curPar = 0, x = bitCnt(nums[i]); int res = dfs(nums[i], x, bits[i], 19, 0); dpPos[i] = dpVal[res]+1; par[i] = pos[res]; dpVal[nums[i]] = dpPos[i]; pos[nums[i]] = i; } for (int i = 2; i <= n; i++) if (dpPos[i] > dpPos[ans]) ans = i; vector <int> tmp; while(ans != 0) { tmp.pb(ans); ans = par[ans]; } cout << tmp.size() << "\n"; while(!tmp.empty()) { cout << tmp.back() << ' '; tmp.pop_back(); } cout << "\n"; }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:39:7: warning: unused variable 'curPar' [-Wunused-variable]
   39 |   int curPar = 0, x = bitCnt(nums[i]);
      |       ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...