제출 #1098567

#제출 시각아이디문제언어결과실행 시간메모리
1098567hahahoang132Longest beautiful sequence (IZhO17_subsequence)C++17
7 / 100
81 ms121052 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; #define bit(x,y) ((x >> y) & 1) const ll mod = 1000000007; const ll N = 1e5 + 5; const ll inf = LLONG_MAX/4; ll a[N],k[N]; ll n; ll maxv[12][(1 << 10) + 5][(1 << 10) + 5]; ll d[N],v[N]; vector<ll> siu[11][(1 << 10) + 5]; ll cnt[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; ll i,j; for(i = 0;i < (1 << 10);i++) { for(j = 0;j < 10;j++) { cnt[i] += bit(i,j); } } for(i = 0;i < (1 << 10);i++) { for(j = 0;j < (1 << 10);j++) { siu[cnt[i & j]][i].push_back(j); } } for(i = 1;i <= n;i++) cin >> a[i]; for(i = 1;i <= n;i++) cin >> k[i]; for(i = 1;i <= n;i++) { ll x = a[i]; ll px = x & ((1 << 10) - 1); ll sx = x >> 10; ll cm = 0; for(j = 0;j <= 10;j++) { for(auto y : siu[k[i] - j][sx]) { if(cm < d[maxv[j][px][y]]) { cm = d[maxv[j][px][y]]; v[i] = maxv[j][px][y]; } } } cm++; for(j = 0;j < (1 << 10);j++) { ll c = cnt[px & j]; if(d[maxv[c][j][sx]] < cm) { maxv[c][j][sx] = i; } } d[i] = cm; } ll mp,ans = 0; for(i = 1;i <= n;i++) { if(ans < d[i]) { mp = i; ans = d[i]; } } cout << ans << "\n"; vector<ll> tmp; while(ans--) { tmp.push_back(mp); mp = v[mp]; } reverse(tmp.begin(),tmp.end()); for(auto hahasus : tmp) cout << hahasus << " "; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...