# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
299390 | luciocf | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 5586 ms | 93520 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5+10;
int n;
int a[maxn], b[maxn];
int dp[maxn], ant[maxn];
pii best[1<<10][1<<10][11];
void print(int ans)
{
printf("%d\n", ans);
int at;
for (int i = 1; i <= n; i++)
if (dp[i] == ans)
at = i;
vector<int> out;
while (at)
{
out.push_back(at);
at = ant[at];
}
reverse(out.begin(), out.end());
for (auto x: out)
printf("%d ", x);
printf("\n");
}
int main(void)
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
scanf("%d", &b[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
{
dp[i] = 1, ant[i] = 0;
int half1 = 0, half2 = 0;
for (int j = 0; j < 10; j++)
{
if (a[i]&(1<<j))
half1 += (1<<j);
if (a[i]&(1<<(j+10)))
half2 += (1<<j);
}
for (int mask = 0; mask < (1<<10); mask++)
{
int x = __builtin_popcount(half1&mask);
if (b[i] >= x && b[i]-x <= 10)
{
if (1 + best[mask][half2][b[i]-x].ff > dp[i])
{
dp[i] = 1 + best[mask][half2][b[i]-x].ff;
ant[i] = best[mask][half2][b[i]-x].ss;
}
}
}
for (int mask = 0; mask < (1<<10); mask++)
{
int x = __builtin_popcount(half2&mask);
if (dp[i] > best[half1][mask][x].ff)
best[half1][mask][x] = {dp[i], i};
}
ans = max(ans, dp[i]);
}
print(ans);
}
컴파일 시 표준 에러 (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... |