이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 1e6 + 2;
const ll inf = 3e18;
const ll buben = 2000;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
template <typename T> void vout(T s){cout << s << endl;exit(0);}
int Dp[MAXN], Wh[MAXN];
pii DP[MAXN][21];
vector <int> v[MAXN];
bool f[MAXN];
int main(){
ios_base :: sync_with_stdio(0);
cin.tie(0);
ll n;
cin >> n;
vector <ll> a(n + 1), k(n + 1);
for(int i = 1; i <= n; i++)cin >> a[i];
for(int i = 1; i <= n; i++)cin >> k[i];
vector <ll> dp(n + 1), pr(n + 1);
if(n <= 5000){
for(int i = 1; i <= n; i++){
dp[i] = 1;
pr[i] = 0;
for(int j = 1; j < i; j++)if(__builtin_popcountll(a[i] & a[j]) == k[i]){
if(dp[i] < dp[j] + 1){
dp[i] = dp[j] + 1;
pr[i] = j;
}
}
}
ll Mx = *max_element(dp.begin() + 1, dp.end());
cout << Mx << "\n";
for(int i = 1; i <= n; i++)if(dp[i] == Mx){
ll x = i;
vector <ll> ans;
while(x){
ans.p_b(x);
x = pr[x];
}
reverse(all(ans));
for(auto i : ans)cout << i << " ";
cout << "\n";
return 0;
}
}
if(*max_element(a.begin() + 1, a.end()) < pw(8)){
for(int i = 1; i <= n; i++){
dp[i] = 1;
pr[i] = 0;
for(int j = 0; j < pw(8); j++)if(__builtin_popcountll(a[i] & j) == k[i]){
if(dp[i] < Dp[j] + 1){
dp[i] = Dp[j] + 1;
pr[i] = Wh[j];
}
}
if(Dp[a[i]] < dp[i]){
Dp[a[i]] = dp[i];
Wh[a[i]] = i;
}
}
ll Mx = *max_element(dp.begin() + 1, dp.end());
cout << Mx << "\n";
for(int i = 1; i <= n; i++)if(dp[i] == Mx){
ll x = i;
vector <ll> ans;
while(x){
ans.p_b(x);
x = pr[x];
}
reverse(all(ans));
for(auto i : ans)cout << i << " ";
cout << "\n";
return 0;
}
}
ll last = 1;
for(int i = 1; i <= n; i++){
if(i % buben == 0){
last = i;
for(int j = pw(20) - 1; j >= 0; j--){
for(auto x : v[j]){
if(Dp[j ^ pw(x)] < Dp[j]){
Dp[j ^ pw(x)] = Dp[j];
Wh[j ^ pw(x)] = Wh[j];
}
}
}
for(int i = 0; i < 20; i++)if(!v[i].empty())shuffle(all(v[i]), rnd);
}
dp[i] = 1;
pr[i] = 0;
for(int j = last; j < i; j++)if(__builtin_popcountll(a[i] & a[j]) == k[i]){
if(dp[i] < dp[j] + 1){
dp[i] = dp[j] + 1;
pr[i] = j;
}
}
ll x = ll(__builtin_popcount(a[i])) - k[i];
if(x >= 0){
for(int j = 0; j < min(ll(v[x].size()), 500ll); j++){
if(__builtin_popcountll(a[i] & v[x][j]) == k[i]){
if(dp[i] < Dp[v[x][j]] + 1){
dp[i] = Dp[v[x][j]] + 1;
pr[i] = Wh[v[x][j]];
}
}
}
}
if(DP[a[i]][k[i]].fi + 1 > dp[i]){
dp[i] = DP[a[i]][k[i]].fi + 1;
pr[i] = DP[a[i]][k[i]].se;
}
if(Dp[a[i]] < dp[i]){
Dp[a[i]] = dp[i];
Wh[a[i]] = i;
}
if(!f[a[i]])v[__builtin_popcount(a[i])].p_b(i);f[a[i]] = 1;
}
ll Mx = *max_element(dp.begin() + 1, dp.end());
cout << Mx << "\n";
for(int i = 1; i <= n; i++)if(dp[i] == Mx){
ll x = i;
vector <ll> ans;
while(x){
ans.p_b(x);
x = pr[x];
}
reverse(all(ans));
for(auto i : ans)cout << i << " ";
cout << "\n";
return 0;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
subsequence.cpp: In function 'int main()':
subsequence.cpp:167:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(!f[a[i]])v[__builtin_popcount(a[i])].p_b(i);f[a[i]] = 1;
^~
subsequence.cpp:167:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(!f[a[i]])v[__builtin_popcount(a[i])].p_b(i);f[a[i]] = 1;
^
# | 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... |