# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
89954 | Vardanyan | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 8 ms | 504 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC optimize "-O3"
#include<bits/stdc++.h>
using namespace std;
const int N = 1000*1000+5;
struct elem{
int val,ind,par;
};
elem ANS[(1<<24)];
int ALL[N];
int PAR[N];
int a[N];
int k[N];
int CNT(int x){
int ans = 0;
for(int i = 0;i<22;i++) if((x>>i)&1) ans++;
return ans;
}
bool have[(1<<21)];
int main()
{
int n;
scanf("%d",&n);
int mx = 0;
vector<int> bmask;
for(int i = 1;i<=n;i++){
scanf("%d",&a[i]);
mx = max(mx,a[i]);
}
for(int i = 1;i<=n;i++) scanf("%d",&k[i]);
int mx_ans = 0;
int pos = 0;
for(int i = 1;i<=n;i++){
/*if(i == 2){
cout<<0<<endl;
}*/
for(int q = 0;q<bmask.size();q++){
int mask = bmask[q];
int now = mask&a[i];
if(CNT(now) == k[i]){
if(ANS[a[i]].val<=ANS[mask].val+1){
int x =ANS[mask].ind;
int y = ANS[mask].val+1;
PAR[i] = x;
ANS[a[i]].val = y;
ANS[a[i]].par = x;
ANS[a[i]].ind = i;
ALL[i] = ANS[a[i]].val;
if(mx_ans<=ANS[a[i]].val){
mx_ans = ANS[a[i]].val;
pos = i;
}
}
}
}
if(ANS[a[i]].val == 0){
ANS[a[i]].val = 1;
ANS[a[i]].ind = i;
ALL[i] = 1;
if(mx_ans<1){
mx_ans = 1;
pos = i;
}
}
if(!have[a[i]]){
have[a[i]] = 1;
bmask.push_back(a[i]);
}
}
vector<int> ans;
cout<<mx_ans<<endl;
while(mx_ans--){
// cout<<ANS[pos].ind<<" ";
int px = pos;
if(pos == ans[ans.size()-1]){
pos--;
while(1){
if(pos == 0) break;
if(a[pos] == a[px]) break;
pos--;
}
}
ans.push_back(pos);
pos = PAR[pos];
}
reverse(ans.begin(),ans.end());
for(int i = 0;i<ans.size();i++) cout<<ans[i]<<" ";
cout<<endl;
return 0;
}
컴파일 시 표준 에러 (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... |