제출 #516655

#제출 시각아이디문제언어결과실행 시간메모리
516655Dasha_GnedkoLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
303 ms262148 KiB
#include <bits/stdc++.h>

//#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

using namespace std;

//using namespace __gnu_pbds;
//template <typename T> using ordered_set = tree <T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 gen(time(0));

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define sz(a) int32_t(a.size())
#define endl '\n'
//#define int long long

const int N = 1e5 + 100;
const int M = 31;
const int mod = 998244353;
const int inf = 1e9 + 7;

int a[N], b[N], dp[N], pr[N], bit[1030][1030];
pair < int, int > c[1025][1025][11];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    freopen("subsequence.in", "r", stdin);
    freopen("subsequence.out", "w", stdout);
#endif // LOCAL

    for(int i = 0; i < 1024; i++)
        for(int j = 0; j < 1024; j++)
            bit[i][j] = __builtin_popcount((i & j));

    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < n; i++)
        cin >> b[i];
    for(int i = 0; i < n; i++)
    {
        dp[i] = 1;
        pr[i] = -1;
        int x = 0, y = 0;
        for(int j = 10; j < 20; j++)
            if (a[i] & (1 << j)) x += (1 << (j - 10));
        for(int j = 0; j < 10; j++)
            if (a[i] & (1 << j)) y += (1 << j);
        for(int mask = 0; mask < 1024; mask++)
        {
            int cnt = bit[mask][y];
            int need = b[i] - cnt;
            if (need < 0 || need > 10) continue;
            if (c[x][mask][need].F + 1 > dp[i])
            {
                dp[i] = c[x][mask][need].F + 1;
                pr[i] = c[x][mask][need].S;
            }
        }
        for(int mask = 0; mask < 1024; mask++)
        {
            int cnt = bit[mask][x];
            c[mask][y][cnt] = max(c[mask][y][cnt], {dp[i], i});
        }
    }
    int i = 0;
    for(int j = 1; j < n; j++)
        if (dp[j] > dp[i]) i = j;
    vector < int > ans;
    while (i >= 0)
    {
        ans.pb(i);
        i = pr[i];
    }
    reverse(ans.begin(), ans.end());
    cout << sz(ans) << endl;
    for(auto to: ans)
        cout << to + 1 << " ";
}

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

subsequence.cpp: In function 'int32_t main()':
subsequence.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     freopen("subsequence.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen("subsequence.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...