# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
228724 | davitmarg | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 80 ms | 126588 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.
/*DavitMarg*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 100005;
int n;
int a[N], k[N],cnt[1050];
pair<int, int> d[1050][1050][15], dp[N],ans;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%d", a + i);
for (int i = 1; i <= n; i++)
scanf("%d", k + i);
for (int mask = 0; mask < (1 << 10); mask++)
for (int i = 0; i < 10; i++)
if ((1 << i) & mask)
cnt[mask]++;
for (int mask = 0; mask < (1 << 10); mask++)
for (int mask2 = 0; mask2 < (1 << 10); mask2++)
for (int i = 0; i <= 10; i++)
d[mask][mask2][i] = MP(-1, 0);
for (int i = 1; i <= n; i++)
{
dp[i] = MP(1, 0);
int msk = a[i] >> 10;
for (int mask = 0; mask < (1 << 10); mask++)
{
if (k[i] - cnt[mask & (a[i] % 1024)] >= 0)
dp[i] = max(dp[i], MP(d[mask][msk][k[i] - cnt[mask & (a[i] % 1024)]].first + 1, d[mask][msk][k[i] - cnt[mask & (a[i] % 1024)]].second));
}
for (int mask = 0; mask < (1 << 10); mask++)
d[a[i] % 1024][mask][cnt[msk & mask]] = max(d[a[i] % 1024][mask][cnt[msk & mask]], MP(dp[i].first, i));
ans = max(ans, MP(dp[i].first, i));
}
vector<int> x;
x.push_back(ans.second);
while (dp[ans.second].second)
{
ans.second = dp[ans.second].second;
x.PB(ans.second);
}
reverse(all(x));
cout << x.size() << endl;
for (int i = 0; i < x.size(); i++)
printf("%d ", x[i]);
cout << endl;
return 0;
}
/*
4
1 2 3 4
10 0 1 0
5
5 3 5 3 5
10 1 20 1 20
*/
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... |