| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1306166 | dex111222333444555 | Longest beautiful sequence (IZhO17_subsequence) | C++20 | 154 ms | 90216 KiB |
#include <bits/stdc++.h>
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define all(v) begin(v), end(v)
#define siz(v) (int)(v).size()
using namespace std;
const int MAXN = 1e5 + 5, MAXB = 10;
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}
template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
int numVal, val[MAXN], req[MAXN], dp[MASK(MAXB)][MASK(MAXB)][MAXB + 1], pos[MASK(MAXB)][MASK(MAXB)][MAXB + 1], trace[MAXN];
void input(){
cin >> numVal;
for(int i = 1; i <= numVal; i++) cin >> val[i];
for(int i = 1; i <= numVal; i++) cin >> req[i];
}
#define left(x) (x >> MAXB)
#define right(x) (x & (MASK(MAXB) - 1))
#define cntb(x) (__builtin_popcount(x))
void solve(){
for(int i = 1; i <= numVal; i++){
int L = left(val[i]);
int R = right(val[i]);
int best = 0, bestPos = 0;
for(int l = 0; l < MASK(MAXB); l++) if (req[i] >= cntb(l & L) && req[i] <= MAXB) {
if (maximize(best, dp[l][R][req[i] - cntb(l & L)]))
bestPos = pos[l][R][req[i] - cntb(l & L)];
}
trace[i] = bestPos;
for(int r = 0; r < MASK(MAXB); r++){
if (maximize(dp[L][r][cntb(r & R)], best + 1))
pos[L][r][cntb(r & R)] = i;
}
}
int res = 0, cur = 0;
for(int l = 0; l < MASK(MAXB); l++)
for(int r = 0; r < MASK(MAXB); r++)
for(int k = 0; k <= MAXB; k++) if (maximize(res, dp[l][r][k])){
cur = pos[l][r][k];
}
cout << res << '\n';
vector<int> canPos;
while(cur > 0){
canPos.push_back(cur);
cur = trace[cur];
}
reverse(all(canPos));
for(int x: canPos) cout << x << ' '; cout << '\n';
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
input();
solve();
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
