# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
854598 | Zero_OP | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 60 ms | 1624 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
if(fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
int n; cin>>n;
vector<int> a(n), k(n);
for(int i=0; i<n; ++i){
cin>>a[i];
}
for(int i=0; i<n; ++i){
cin>>k[i];
}
if(n<=20){
int ans=0, ans_mask=1;
for(int mask=1; mask<(1<<n); ++mask){
bool ok=true;
int pre=-1;
for(int i=0; i<n; ++i){
if((mask>>i)&1){
if(pre==-1){
pre=a[i];
}
else if(__builtin_popcount(a[i]&pre)==k[i]){
pre=a[i];
}
else {
ok=false;
break;
}
}
}
if(ok){
int cur=__builtin_popcount(mask);
if(cur>ans){
ans=cur;
ans_mask=mask;
}
}
}
cout<<ans<<'\n';
for(int i=0; i<n; ++i){
if((ans_mask>>i)&1){
cout<<i+1<<' ';
}
}
return 0;
}
if(n<=5000){
int end_idx=0;
vector<int> dp(n, 1), pre(n); iota(pre.begin(), pre.end(), 0);
for(int i=0; i<n; ++i){
for(int j=0; j<i; ++j){
if(__builtin_popcount(a[i]&a[j])==k[i]){
if(dp[i]<dp[j]+1){
dp[i]=dp[j]+1;
pre[i]=j;
}
}
if(dp[end_idx]<dp[i]){
end_idx=i;
}
}
}
stack<int> st;
while(end_idx!=pre[end_idx]){
st.push(end_idx);
end_idx=pre[end_idx];
}
st.push(end_idx);
cout<<st.size()<<'\n';
while(!st.empty()){
cout<<st.top()+1<<' ';
st.pop();
}
return 0;
}
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... |