제출 #173016

#제출 시각아이디문제언어결과실행 시간메모리
173016juggernautLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
2 ms504 KiB
//Just try and the idea will come!
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int n,i,a[5001],k[5001],dp[5001],j,path[5001],mx,ind,m[(1ll<<20)],pos[(1ll<<20)];
vector<int>ans;
main(){
    scanf("%lld",&n);
    for(i=1;i<=n;i++)scanf("%lld",&a[i]);
    for(i=1;i<=n;i++)scanf("%lld",&k[i]),dp[i]=1;
    for(i=1;i<=n;i++){
        for(j=1;j<(1ll<<8);j++)
            if(__builtin_popcount(a[i]&j)==k[i]&&m[j]+1>dp[i]){
                dp[i]=m[j]+1;
                path[i]=pos[j];
            }
        if(dp[i]>m[a[i]]){
            m[a[i]]=dp[i];
            pos[a[i]]=i;
        }
        if(dp[i]>mx){
            mx=dp[i];
            ind=i;
        }
    }
    do{
        ans.push_back(ind);
        ind=path[ind];
    }while(ind!=0);
    reverse(ans.begin(),ans.end());
    printf("%lld\n",(int)(ans.size()));
    for(int res:ans)printf("%lld ",res);
}

컴파일 시 표준 에러 (stderr) 메시지

subsequence.cpp:7:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
subsequence.cpp: In function 'int main()':
subsequence.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
subsequence.cpp:9:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++)scanf("%lld",&a[i]);
                      ~~~~~^~~~~~~~~~~~~~
subsequence.cpp:10:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++)scanf("%lld",&k[i]),dp[i]=1;
                      ~~~~~~~~~~~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...