제출 #36927

#제출 시각아이디문제언어결과실행 시간메모리
36927top34051Longest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
5926 ms93448 KiB
#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define X first
#define Y second

const int maxn = 1e5 + 5;
const int cut = 1024;

int n;
int p[maxn], k[maxn];
int cnt[cut];
pii dp[cut][cut][11];
int track[maxn];
vector<int> res;

int main() {
    int i,x,y,a,b,mx,pos;
    pii ans;
    scanf("%d",&n);
    for(i=1;i<=n;++i) scanf("%d",&p[i]);
    for(i=1;i<=n;++i) scanf("%d",&k[i]);
    for(x=0;x<cut;++x) cnt[x] = __builtin_popcount(x);
    ans = {0,0};
    for(i=1;i<=n;++i) {
        a = p[i]>>10; b = p[i]%cut; mx = 1; pos = 0;
        //fix C (x)
        for(x=0;x<cut;++x) {
            int want = k[i] - cnt[a&x];
            if(want<0 || want>10) continue;
            if(mx < dp[x][b][want].X + 1) mx = dp[x][b][want].X + 1, pos = dp[x][b][want].Y;
        }
        track[i] = pos;
        if(ans.X < mx) ans = make_pair(mx, i);
        //fix B (x)
        for(x=0;x<cut;++x) {
            int want = cnt[b&x];
            if(dp[a][x][want].X < mx) dp[a][x][want] = make_pair(mx, i);
        }
    }
    printf("%d\n",ans.X);
    x = ans.Y;
    while(x) res.emplace_back(x), x = track[x];
    reverse(res.begin(), res.end());
    for(auto t : res) printf("%d ",t);
}

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:19:13: warning: unused variable 'y' [-Wunused-variable]
     int i,x,y,a,b,mx,pos;
             ^
subsequence.cpp:21:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
subsequence.cpp:22:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;++i) scanf("%d",&p[i]);
                                        ^
subsequence.cpp:23:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;++i) scanf("%d",&k[i]);
                                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...