이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 100'010;
int dp[N], pre[N];
int a[N], k[N];
int n;
__attribute__((optimize("O3,unroll-loops"),target("avx")))
int get(int l, int r, int x, int k)
{
#define MAX(a, b) ((a)>(b)?(a):(b))
int ans = 0;
Loop (j,l,r) {
int tmp = a[j] & x;
tmp = __builtin_popcount(tmp);
tmp = -(tmp == k);
tmp &= (dp[j] & -32768) ^ (j & 32767);
ans = MAX(ans, tmp);
}
return ans;
#undef MAX
}
void up(int i, int x, int k)
{
int ans = -1, ansi = -1;
const int S = 4096;
for (int l = 0; l < i; l += S) {
int r = min(l+S, i);
int tmp = get(l, r, x, k);
if (tmp > ans) {
ans = tmp;
ansi = l;
}
}
if (ansi >= 0) {
Loop (j,ansi,ansi+S) {
if ( dp[j]+1 == ans
&& __builtin_popcount(a[j]&x) == k) {
ansi = j;
break;
}
}
}
pre[i] = ansi;
dp[i] = ans;
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n;
Loop (i,0,n)
cin >> a[i];
Loop (i,0,n)
cin >> k[i];
Loop (i,0,n)
up(i, a[i], k[i]);
int i = 0;
Loop (j,0,n) {
if (dp[j] > dp[i])
i = j;
}
vector<int> vec;
while (i != -1) {
vec.push_back(i);
i = pre[i];
}
reverse(vec.begin(), vec.end());
cout << vec.size() << '\n';
for (int v : vec)
cout << v+1 << ' ';
cout << '\n';
}
# | 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... |