# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
36120 | aome | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 29 ms | 93852 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int M = 1024;
const int INF = 1e9;
int n, a[N], b[N], cnt[M];
pair<int, int> f[N];
pair<int, int> g[M][M][11];
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> b[i];
for (int i = 0; i < M; ++i) {
for (int j = 0; j < 10; ++j) cnt[i] += i >> j & 1;
}
for (int i = 0; i < M; ++i) for (int j = 0; j < M; ++j) {
for (int k = 0; k < 10; ++k) {
g[i][j][k] = make_pair(-INF, 0);
}
}
int pos = 0;
for (int i = 1; i <= n; ++i) {
int pre = 0, suf = 0;
for (int j = 0; j < 10; ++j) {
if (a[i] >> j & 1) pre |= 1 << j;
}
for (int j = 10; j < 20; ++j) {
if (a[i] >> j & 1) suf |= 1 << (j - 10);
}
f[i] = make_pair(1, 0);
for (int j = 0; j < M; ++j) {
int tmp = j & pre;
if (cnt[tmp] > b[i]) continue;
f[i] = max(f[i], g[j][suf][b[i] - cnt[tmp]]);
}
for (int j = 0; j < M; ++j) {
int tmp = suf & j;
g[pre][j][cnt[tmp]] = max(g[pre][j][cnt[tmp]], make_pair(f[i].first + 1, i));
}
if (f[pos].first < f[i].first) pos = i;
}
vector<int> res;
int cur = pos;
while (cur) {
res.push_back(cur), cur = f[cur].second;
}
reverse(res.begin(), res.end());
printf("%d\n", res.size());
for (int i = 0; i < res.size(); ++i) printf("%d ", res[i]);
}
컴파일 시 표준 에러 (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... |