# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
945265 | vjudge1 | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 2449 ms | 93564 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 2;
const int base = ((1 << 20) - 1) ^ ((1 << 10) - 1);
int val[(1 << 10)][(1 << 10)][22];
int a[N + 2];
int k[N + 2];
int bit_count[(1 << 10)];
int dp[N + 2];
int tv[N + 2];
void solve() {
int n;
cin >> n;
for(int i = 0 ; i <(1 << 10) ; i ++){
bit_count[i] = __builtin_popcount(i);
}
for(int i = 1; i <= n ; i ++)cin >> a[i];
for(int i = 1; i <= n ;i ++)cin >> k[i];
int res = 0;
for(int i = 1; i <= n ; i ++){
int first = a[i] ^ (a[i] & base);
int second = a[i] >> 10;
for(int j = 0 ; j < (1 << 10) ;j ++){
int x = bit_count[(j & first)];
if(k[i] < x) continue;
if(dp[tv[i]] < dp[val[second][j][k[i] - x]]){
tv[i] = val[second][j][k[i] - x];
}
}
dp[i] = dp[tv[i]] + 1;
for(int j = 0 ; j < ( 1 << 10) ; j ++){
// if(j == 0) cout << first << " " <<bit_count[j & second] << "\n";
if(dp[val[j][first][bit_count[j & second]]] < dp[i]){
// cout << j << " " << first << " " << bit_count[j & second] << " " << i <<"\n";
val[j][first][bit_count[j & second]] = i;
}
}
if(dp[res] < dp[i])res = i;
}
vector < int > ans;
while(res > 0){
ans.push_back(res);
res =tv[res];
}
reverse(ans.begin() , ans.end());
cout << ans.size() << '\n';
for(auto vl : ans)cout << vl << " ";
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
#define _ "test."
if (fopen(_ "inp", "r")) {
freopen(_ "inp", "r", stdin);
freopen(_ "out", "w", stdout);
}
solve();
}
컴파일 시 표준 에러 (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... |