# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
386248 | patrikpavic2 | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 5069 ms | 93528 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define PB push_back
using namespace std;
const int N = 1e5 + 500;
const int MSK = (1 << 20);
const int BS = (1 << 10);
int n, A[N], K[N], dp[N], rek[N], krj;
int naj[MSK][11], sol, naj2[MSK][11];
void dodaj(int xx, int y, int gdje){
int i = xx >> 10, x = xx & (BS - 1);
for(int j = 0;j < BS;j++){
int ds = __builtin_popcount(j & x);
if(y > naj[(i << 10) + j][ds]){
naj[(i << 10) + j][ds] = y;
naj2[(i << 10) + j][ds] = gdje;
}
}
}
int GDJE;
int pitaj(int x, int k){
int ret = 0, i = x >> 10;
for(int j = 0;j < BS;j++){
int ds = __builtin_popcount(i & j);
if(k - ds >= 0 && k - ds <= 10 && naj[(j << 10) + (x & (BS - 1))][k - ds] > ret){
ret = naj[(j << 10) + (x & (BS - 1))][k - ds];
GDJE = naj2[(j << 10) + (x & (BS - 1))][k - ds];
}
}
return ret;
}
int main(){
scanf("%d", &n);
for(int i = 0;i < n;i++)
scanf("%d", A + i);
for(int i = 0;i < n;i++)
scanf("%d", K + i);
for(int i = 0;i < n;i++){
dp[i] = pitaj(A[i], K[i]) + 1;
if(dp[i] > 1){
rek[i] = GDJE;
}
if(sol < dp[i]){
sol = dp[i];
krj = i;
}
dodaj(A[i], dp[i], i);
}
printf("%d\n", sol);
vector < int > fin;
for(;;){
fin.PB(krj + 1);
if(dp[krj] == 1) break;
krj = rek[krj];
}
reverse(fin.begin(), fin.end());
for(int x : fin)
printf("%d ", x);
printf("\n");
return 0;
}
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... |