이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<algorithm>
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
using namespace std;
const int N = (int)1e5 + 1;
int n;
int a[N];
int k[N];
struct State {
int len, end;
State(int _len = 0, int _end = 0) {
len = _len;
end = _end;
}
};
State f[MASK(10)][MASK(10)][11];
int bc[MASK(10)][MASK(10)];
int trace[N];
int main(void) {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
for(int i = 0; i < MASK(10); i++) {
for(int j = i; j < MASK(10); j++) {
bc[i][j] = bc[j][i] = __builtin_popcount(i & j);
}
}
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> k[i];
int p = 1, ans = 1;
for(int i = 1; i <= n; i++) {
int l = a[i] >> 10;
int r = a[i] % MASK(10);
int lbs = 1;
trace[i] = i;
for(int j = 0; j < MASK(10); j++) {
if(bc[j][l] < 0 || bc[j][l] > 10) continue;
int needed = k[i] - bc[j][l];
if(f[j][r][needed].len + 1 > lbs) {
lbs = f[j][r][needed].len + 1;
trace[i] = f[j][r][needed].end;
}
}
for(int j = 0; j < MASK(10); j++) {
if(lbs > f[l][j][bc[j][r]].len) {
f[l][j][bc[j][r]] = State(lbs, i);
}
}
if(lbs > ans) {
p = i;
ans = lbs;
}
}
vector<int> seq;
while(p != trace[p]) {
seq.push_back(p);
p = trace[p];
}
seq.push_back(p);
reverse(seq.begin(), seq.end());
cout << ans << '\n';
for(int i = 0; i < (int)seq.size(); i++) cout << seq[i] << ' ';
}
# | 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... |