제출 #1127241

#제출 시각아이디문제언어결과실행 시간메모리
1127241GrayLongest beautiful sequence (IZhO17_subsequence)C++20
0 / 100
291 ms327680 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define ff first
#define ss second
#define ln "\n"
#define mp make_pair
#define popcnt __builtin_popcount
void solve(){
    ll n; cin >> n;
    vector<ll> a(n), k(n);
    for (ll i=0; i<n; i++){
        cin >> a[i];
    }
    for (ll i=0; i<n; i++){
        cin >> k[i];
    }
    vector<vector<vector<pair<ll, ll>>>> past((1<<10), vector<vector<pair<ll, ll>>>(1<<10, vector<pair<ll, ll>>(11, {0, -1})));
    vector<ll> ldp(n, 1), dep(n, -1);
    for (ll i=0; i<n; i++){
        ll l = a[i]>>10, r=a[i]&((1<<10)-1);
        for (ll j=0; j<(1<<10); j++){
            if (k[i]>=popcnt(j&l) and k[i]-popcnt(j&l)<=10 and ldp[i]<past[j][r][k[i]-popcnt(j&l)].ff+1){

                ldp[i]=past[j][r][k[i]-popcnt(j&l)].ff+1;
                dep[i]=past[j][r][k[i]-popcnt(j&l)].ss;
            }
        }
        for (ll j=0; j<(1<<10); j++){
            past[l][j][popcnt(r&j)]=max(past[l][j][popcnt(r&j)], {ldp[i], i});
        }
    }
    ll mx = *max_element(ldp.begin(), ldp.end());
    cout << mx << ln;
    for (ll i=0; i<n; i++){
        if (ldp[i]==mx){
            ll cur = i;
            vector<ll> res;
            while (cur!=-1){
                res.push_back(cur+1);
                cur=dep[cur];
            }
            reverse(res.begin(), res.end());
            for (auto ch:res) cout << ch << " ";
            cout << ln; break;
        }
    }
}

int main(){
    #ifdef LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #else
    freopen("subsequence.in", "r", stdin);
    freopen("subsequence.out", "w", stdout);
    #endif
    auto start = chrono::high_resolution_clock::now();
    ll t=1;
    // cin >> t;
    while (t--) solve();
    #ifdef LOCAL
    auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
    cout << setprecision(0) << fixed << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
    #endif
}

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

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