제출 #1269058

#제출 시각아이디문제언어결과실행 시간메모리
1269058ThanhsLongest beautiful sequence (IZhO17_subsequence)C++20
100 / 100
4074 ms174468 KiB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define name "TENBAI"
#define fi first
#define se second
#define endl '\n'
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define all(x) x.begin(), x.end()

mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}

const int NM = 1e5 + 5;
const int ALL = 1 << 10;

int n, a[NM], b[NM], f[NM], tr[NM];
pair<int, int> F[1024][1024][21];

void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
    {
        f[i] = 1;
        cin >> b[i];
        int x = a[i] >> 10, y = a[i] & (ALL - 1);
        for (int j = 0; j < ALL; j++)
        {
            int t = b[i] - (int)__builtin_popcount(x & j);
            if (t < 0)
                continue;
            if (f[i] < F[j][y][t].fi)
            {
                f[i] = F[j][y][t].fi;
                tr[i] = F[j][y][t].se;
            }
        }
        for (int j = 0; j < ALL; j++)
            setmax(F[x][j][__builtin_popcount(y & j)], make_pair(f[i] + 1, i));
    }
    pair<int, int> t = {0, 0};
    for (int i = 1; i <= n; i++)
        setmax(t, make_pair(f[i], i));
    cout << t.fi << endl;
    int cr = t.se;
    vector<int> ans;
    while (cr)
    {
        ans.push_back(cr);
        cr = tr[cr];
    }
    reverse(all(ans));
    for (int t : ans)
        cout << t << ' ';
}

signed main()
{
    if (fopen("in.txt", "r")) 
    {
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    else if (fopen(name".inp", "r"))
    {
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int tc = 1; 
    // cin >> tc;
    while (tc--)
        solve();
}

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...