# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
692254 | Huy | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 1 ms | 212 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>
//#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#pragma GCC tarGet ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC tarGet("avx,avx2,fma")
using namespace std;
using ll = long long;
const int mod = 1e9+7;
const int maxN = 1e5+5;
const int N = 3e5;
const ll infty = 1e16;
void InputFile()
{
freopen("ATHM.inp","r",stdin);
freopen("ATHM.out","w",stdout);
//freopen("test.out","r",stdin);
}
int n;
int a[maxN];
int k[maxN];
int cbit[1001];
int dp[maxN];
void Read()
{
cin >> n;
for(int i = 1;i <= n;i++)
cin >> a[i];
for(int i = 1;i <= n;i++)
cin >> k[i];
}
void Sub1()
{
for(int i = 1;i <= n;i++)
{
dp[i] = 1;
for(int j = 1;j < i;j++)
{
int x = (a[j] & a[i]);
if(__builtin_popcount(x) == k[i])
{
dp[i] = max(dp[i],dp[j] + 1);
}
}
}
cout << *max_element(dp + 1,dp + n + 1);
}
void Sub3()
{
for(int i = 0;i <= 1000;i++)
cbit[i] = __builtin_popcount(i);
for(int i = 1;i <= n;i++)
{
//dp[a[i]] = max(dp[a[i]],1);
for(int j = 0;j <= 1000;j++)
{
if(cbit[a[i]&j] == k[i])
{
dp[a[i]] = max(dp[a[i]],dp[j] + 1);
}
}
dp[a[i]] = max(dp[a[i]],1);
}
cout << *max_element(dp,dp + 1000 + 1);
}
void Solve()
{
if(n <= 5000) Sub1();
else Sub3();
//Sub3();
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//InputFile();
//int sub_type;
//cin >> sub_type;
//Sieve();
//Prepare();
int test;
//cin >> test;
test = 1;
while(test--)
//for(int prc = 1; prc <= test; prc++)
{
Read();
Solve();
//Debug();
}
}
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... |