이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define N 100010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <int, int>
#define sz(a) int(a.size())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}
int n;
int Pr[N];
int sz[N];
int in[N];
int dp[N];
int v[N], k[N];
int main()
{
cin >> n;
for(int i = 1; i <= n; i++) cin >> v[i];
for(int i = 1; i <= n; i++) cin >> k[i];
if(n <= 5000) {
for(int i = 1; i <= n; i++) {
sz[i] = 1;
for(int h = 1; h < i; h++) {
int x = (v[i]&v[h]);
if(__builtin_popcount(x) != k[i]) continue;
if(sz[i] < sz[h]+1) {
sz[i] = sz[h]+1;
Pr[i] = h;
}
}
}
int mx = 0, pos = 0;
for(int i = 1; i <= n; i++)
if(mx < sz[i]) {
mx = sz[i];
pos = i;
}
vector <int> A;
while(pos) A.pb(pos), pos = Pr[pos];
reverse(A.begin(), A.end());
cout << A.size() << "\n";
for(auto i: A) cout << i << " ";
return 0;
}
for(int i = 1; i <= n; i++) {
int now = 1;
for(int h = 0; h < (1<<8); h++) {
int x = (v[i]&h);
if(__builtin_popcount(x) != k[i]) continue;
if(now < dp[h]+1) {
now = dp[h]+1;
Pr[i] = in[h];
}
}
sz[i] = now;
if(dp[v[i]] < now) {
dp[v[i]] = now;
in[v[i]] = i;
}
}
int mx = 0, pos = 0;
for(int i = 1; i <= n; i++) if(mx < sz[i]) {
mx = sz[i];
pos = i;
}
vector <int> A;
while(pos) A.pb(pos), pos = Pr[pos];
reverse(A.begin(), A.end());
cout << A.size() << "\n";
for(auto i: A) cout << i << " ";
}
/*
4
1 2 3 4
10 0 1 0
5
5 3 5 3 5
10 1 20 1 20
*/
컴파일 시 표준 에러 (stderr) 메시지
subsequence.cpp:23: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
23 | #pragma GCC optimization ("O3")
|
subsequence.cpp:24: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
24 | #pragma GCC optimization ("unroll-loops")
|
# | 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... |