Submission #344127

#TimeUsernameProblemLanguageResultExecution timeMemory
344127IZhO_2021_I_want_SilverLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
1 ms492 KiB
#include <iostream> #include <algorithm> #include <vector> #include <cassert> using namespace std; typedef pair <int, int> pii; #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define pb push_back #define F first #define S second const int N = 1e5 + 5; const int MX = (1 << 8) + 5; int n, a[N], k[N], pre[N], dp[N], pos[MX]; vector <int> vec; void solve() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { cin >> k[i]; } for (int i = 0; i < MX-5; ++i) { pos[i] = -1; } for (int i = 1; i <= n; ++i) { dp[i] = 1; for (int m = 0; m < MX-5; ++m) { if (__builtin_popcount((a[i] & m)) != k[i] || pos[m] == -1) { continue; } if (dp[i] < dp[pos[m]] + 1) { dp[i] = dp[pos[m]] + 1; pre[i] = pos[m]; } } if (pos[a[i]] == -1) { pos[a[i]] = i; continue; } if (dp[i] > dp[pos[a[i]]]) { pos[a[i]] = i; } } int ans = 0, ps = 0; for (int i = 1; i <= n; ++i) { if (ans < dp[i]) { ans = dp[i]; ps = i; } } while (pre[ps]) { vec.pb(ps); ps = pre[ps]; } vec.pb(ps); reverse(all(vec)); cout << sz(vec) <<"\n"; for (int i = 0; i < sz(vec); ++i) { cout << vec[i] <<" "; } } int main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int tests = 1; //cin >> tests; while (tests --) { solve(); } return 0; } /* Just Chalish! 4 1 2 3 4 10 0 1 0 2 8 9 20 0 5 5 3 5 3 5 10 1 20 1 20 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...