Submission #967196

# Submission time Handle Problem Language Result Execution time Memory
967196 2024-04-21T13:35:55 Z AlphaMale06 Longest beautiful sequence (IZhO17_subsequence) C++17
0 / 100
34 ms 127316 KB
#include <bits/stdc++.h>

using namespace std;
const int N = 1e5+3;
const int bits=11;
const int mask = 1<<bits;
int dp[bits+1][mask][mask], prv[N], from[bits+1][mask][mask], cnt[mask], a[N], b[N], l[N], r[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for(int i=0; i<mask; i++)cnt[i]=__builtin_popcount(i);
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        l[i]=a[i]>>10;
        r[i]=a[i]&((1<<11)-1);
    }
    for(int i=1; i<=n; i++)cin >> b[i];
    int mxans=0, mxst=0;
    for(int i=1; i<=n; i++){
        int mx=0;
        for(int j=0; j<mask; j++){
            int share = cnt[j&r[i]];
            if(b[i]-share>=0 && b[i]-share<=10){
                mx=max(mx, dp[b[i]-share][l[i]][j]);
                if(mx==dp[b[i]-share][l[i]][j])prv[i]=from[b[i]-share][l[i]][j];
            }
        }
        mx++;
        for(int j=0; j<mask; j++){
            dp[cnt[j&l[i]]][j][r[i]]=max(dp[cnt[j&l[i]]][j][r[i]], mx);
            if(dp[cnt[j&l[i]]][j][r[i]]==mx)from[cnt[j&l[i]]][j][r[i]] = i;
        }
        if(mx>mxans){
            mxans=mx;
            mxst = i;
        }
    }
    cout << mxans << '\n';
    vector<int> cons;
    while(mxst!=0){
        cons.push_back(mxst);
        mxst=prv[mxst];
    }
    reverse(cons.begin(), cons.end());
    for(int e : cons)cout << e << " ";
    cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29016 KB answer = 4
2 Correct 6 ms 27224 KB answer = 1
3 Correct 6 ms 29020 KB answer = 2
4 Correct 6 ms 26972 KB answer = 1
5 Correct 6 ms 28964 KB answer = 2
6 Correct 30 ms 85012 KB answer = 1
7 Correct 11 ms 65624 KB answer = 1
8 Incorrect 34 ms 127316 KB there is incorrect path (1, 3)
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29016 KB answer = 4
2 Correct 6 ms 27224 KB answer = 1
3 Correct 6 ms 29020 KB answer = 2
4 Correct 6 ms 26972 KB answer = 1
5 Correct 6 ms 28964 KB answer = 2
6 Correct 30 ms 85012 KB answer = 1
7 Correct 11 ms 65624 KB answer = 1
8 Incorrect 34 ms 127316 KB there is incorrect path (1, 3)
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29016 KB answer = 4
2 Correct 6 ms 27224 KB answer = 1
3 Correct 6 ms 29020 KB answer = 2
4 Correct 6 ms 26972 KB answer = 1
5 Correct 6 ms 28964 KB answer = 2
6 Correct 30 ms 85012 KB answer = 1
7 Correct 11 ms 65624 KB answer = 1
8 Incorrect 34 ms 127316 KB there is incorrect path (1, 3)
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29016 KB answer = 4
2 Correct 6 ms 27224 KB answer = 1
3 Correct 6 ms 29020 KB answer = 2
4 Correct 6 ms 26972 KB answer = 1
5 Correct 6 ms 28964 KB answer = 2
6 Correct 30 ms 85012 KB answer = 1
7 Correct 11 ms 65624 KB answer = 1
8 Incorrect 34 ms 127316 KB there is incorrect path (1, 3)
9 Halted 0 ms 0 KB -