# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
305148 | LucaDantas | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 5062 ms | 93304 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Define dp[left][right][y] = the best value for a value with mask equal
to left, whose right submask's and has exactly y values turned on
So when getting the value of current dp we can brute the left mask
we want and that uniquely defines the right segment
And when we want to update the dp we can brute the right segment
because the left is already defined
*/
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define ff first
#define ss second
#define pb push_back
constexpr int maxn = 4e5+10;
int a[maxn], k[maxn], n;
int dp[1<<10][1<<10][11]; // left submask, right submask, y
int ant[maxn], pos[1<<10][1<<10][11];
void print(int ans) {
vector<int> resp;
while(ans) {
resp.pb(ans);
ans = ant[ans];
}
reverse(resp.begin(), resp.end());
for(auto it : resp)
printf("%d ", it);
printf("\n");
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for(int i = 1; i <= n; i++)
scanf("%d", &k[i]);
int ans = 0, id = 0;
for(int i = 1; i <= n; i++) {
int here = 1, l = 0, r = 0;
for(int lg = 0; lg < 10; lg++)
l += ((1<<lg)&a[i]);
for(int lg = 10; lg < 20; lg++)
r += ((1<<lg)&a[i]);
r >>= 10;
// Updating my dp value
for(int mask = 0; mask < (1 << 10); mask++) {
int y = k[i] - __builtin_popcount(l&mask);
if(y >= 0 && y <= 10 && dp[mask][r][y] >= here)
here = dp[mask][r][y]+1, ant[i] = pos[mask][r][y];
}
// Updating the dp array
for(int mask = 0; mask < (1 << 10); mask++) {
int y = __builtin_popcount(r&mask);
if(dp[l][mask][y] < here)
dp[l][mask][y] = here, pos[l][mask][y] = i;
}
if(here > ans)
ans = here, id = i;
}
printf("%d\n", ans);
print(id);
}
컴파일 시 표준 에러 (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... |