제출 #700965

#제출 시각아이디문제언어결과실행 시간메모리
700965messiuuuuuLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
3 ms4436 KiB
///
#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e5 + 5;
const ll INF = 1e18 + 5;

int n;
int a[MAXN], k[MAXN];

void Input()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> k[i];
}

int f[1 << 10][1 << 10][11], dp[MAXN], trace[MAXN];

void Solve()
{
    for (int i = 1; i <= n; i++)
    {
        int prei = a[i] & 1023;
        int sufi = a[i] >> 10;
        for (int suf = 0; suf < (1 << 10); suf++)
        {
            if (dp[f[prei][suf][k[i] - __builtin_popcount(suf & sufi)]] + 1 > dp[i])
            {
                dp[i] = dp[f[prei][suf][k[i] - __builtin_popcount(suf & sufi)]] + 1;
                trace[i] = f[prei][suf][k[i] - __builtin_popcount(suf & sufi)];
            }
        }
        for (int pre = 0; pre < (1 << 10); pre++)
        {
            if (dp[f[pre][sufi][__builtin_popcount(pre & prei)]] < dp[i])
            {
                f[pre][sufi][__builtin_popcount(pre & prei)] = i;
            }
        }
    }

    int p = max_element(dp + 1, dp + n + 1) - dp;
    cout << dp[p] << '\n';
    while (p)
    {
        cout << p << ' ';
        p = trace[p];
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    Input();
    Solve();
}

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...