제출 #1082386

#제출 시각아이디문제언어결과실행 시간메모리
1082386steveonalexLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
42 ms90716 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() #define block_of_code if(true) ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(a, b);} ll lcm(ll a, ll b){return a / gcd(a, b) * b;} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ull mask){return __builtin_ctzll(mask);} int logOf(ull mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} double rngesus_d(double l, double r){ double cur = rngesus(0, MASK(60) - 1); cur /= MASK(60) - 1; return l + cur * (r - l); } template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const int N = 10; pair<int, int> ma[MASK(N)][MASK(N)][N+1]; int main(void){ ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); clock_t start = clock(); int n; cin >> n; vector<int> a(n), k(n); for(int i = 0; i<n; ++i) cin >> a[i]; for(int j = 0; j<n; ++j) cin >> k[j]; for(int i = 0; i<MASK(N); ++i) for(int j = 0; j < MASK(N); ++j) for(int k = 0; k<=N; ++k) ma[i][j][k] = {-1, -1}; vector<pair<int,int>> dp(n, {0, -1}); for(int i = 0; i<n; ++i){ int first_half = a[i] % MASK(N), second_half = a[i] / MASK(N); for(int mask = 0; mask < MASK(N); ++mask){ int cnt = pop_cnt(mask & first_half); if (cnt <= k[i]) maximize(dp[i], ma[mask][second_half][k[i] - cnt]); } dp[i].first++; for(int mask = 0; mask < MASK(N); ++mask){ maximize(ma[first_half][mask][pop_cnt(second_half & mask)], make_pair(dp[i].first, i)); } } int u = max_element(ALL(dp)) - dp.begin(); cout << dp[u].first << "\n"; vector<int> ans; while(u >= 0){ ans.push_back(u+1); u = dp[u].second; } reverse(ALL(ans)); printArr(ans); cerr << "Time elapsed: " << clock() - start << " ms\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...