제출 #1182747

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

#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) "[" #x " = " << (x) << "]"
///#define int long long

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}

const int B = 10;
const int MAX = (1 << 10);


pair<int,int> dp[MAX][MAX][11];

int cntB[MAX], ans, Mx;

void solve()
{
    int n; cin >> n;

    vector<int> a(n + 1), k(n + 1);
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) cin >> k[i];

    FOR(i, 0, MAX - 1) cntB[i] = __builtin_popcount(i);

    vector<int> trace(n + 1, 0);
    FOR(i, 1, n){
        int cur_dp = 1;

        int head = (a[i] >> B), tail = (a[i] & (MAX - 1));
        FOR(mask, 0, MAX - 1){
            int needB = k[i] - cntB[mask & head];
            if(needB < 0 || needB > B) continue;

            if(ckmx(cur_dp, dp[mask][tail][needB].first + 1)){
                trace[i] = dp[mask][tail][needB].second;
            }
        }

        FOR(mask, 0, MAX - 1){
            if(ckmx(dp[head][mask][cntB[mask & tail]].first, cur_dp)){
                dp[head][mask][cntB[mask & tail]].second = i;
            }
        }

        if(ckmx(ans, cur_dp)){
            Mx = i;
        }
    }

    cout << ans << "\n";

    vector<int> st;
    while(Mx){
        st.emplace_back(Mx);
        Mx = trace[Mx];
    }
    ROF(i, sz(st) - 1, 0) cout << st[i] <<" ";
}

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

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP","r",stdin);
        freopen(name".OUT","w",stdout);
    }

    int t = 1; //cin >> t;
    while(t--) solve();
    return 0;
}

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         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...