제출 #779203

#제출 시각아이디문제언어결과실행 시간메모리
779203magicianLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
45 ms94792 KiB
#include<iostream> #include<vector> #include<algorithm> #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) using namespace std; const int N = (int)1e5 + 1; int n; int a[N]; int k[N]; struct State { int len, end; State(int _len = 0, int _end = 0) { len = _len; end = _end; } }; State f[MASK(10)][MASK(10)][11]; int bc[MASK(10)][MASK(10)]; int trace[N]; int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); for(int i = 0; i < MASK(10); i++) { for(int j = i; j < MASK(10); j++) { bc[i][j] = bc[j][i] = __builtin_popcount(i & j); } } cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) cin >> k[i]; int p = 1, ans = 1; for(int i = 1; i <= n; i++) { int l = a[i] >> 10; int r = a[i] % MASK(10); int lbs = 1; trace[i] = i; for(int j = 0; j < MASK(10); j++) { if(bc[j][l] < 0 || bc[j][l] > 10) continue; int needed = k[i] - bc[j][l]; if(f[j][r][needed].len + 1 > lbs) { lbs = f[j][r][needed].len + 1; trace[i] = f[j][r][needed].end; } } for(int j = 0; j < MASK(10); j++) { if(lbs > f[l][j][bc[j][r]].len) { f[l][j][bc[j][r]] = State(lbs, i); } } if(lbs > ans) { p = i; ans = lbs; } } vector<int> seq; while(p != trace[p]) { seq.push_back(p); p = trace[p]; } seq.push_back(p); reverse(seq.begin(), seq.end()); cout << ans << '\n'; for(int i = 0; i < (int)seq.size(); i++) cout << seq[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...