# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1012095 | codefox | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 0 ms | 348 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<bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define pipii pair<int, pii>
#pragma GCC optimize("Ofast")
#pragma GCC target("popcnt")
int N = 1<<20;
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n;
cin >> n;
vector<bitset<20>> a(n);
vector<int> k(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> k[i];
vector<pii> best(n);
for (int i = 0; i < n; i++)
{
best[i] = {1, -1};
for (int j = 0; j < i; j++)
{
if ((a[j]&a[i]).count()==k[i])
{
if (best[i].first<best[j].first+1)
{
best[i] = {best[j].first+1, j};
}
}
}
}
int mx = 0;
int nn = 0;
for (int i = 0; i < n; i++)
{
if (best[i].first>mx)
{
mx = best[i].first;
nn = i;
}
}
cout << mx << "\n";
vector<int> sol;
while (nn != -1)
{
sol.push_back(nn);
nn = best[nn].second;
}
reverse(sol.begin(), sol.end());
for (int ele:sol) cout << ele+1 << " ";
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... |