답안 #856616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856616 2023-10-04T05:00:02 Z nnhzzz Burza (COCI16_burza) C++14
0 / 160
11 ms 50008 KB
// cre: Nguyen Ngoc Hung - Train VOI 2024 :>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <unordered_set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <cmath>
#include <array>
#include <cassert>
#include <random>

using namespace std;

#define        __nnhzzz__  signed main()
#define          BIT(i,j)  ((i>>j)&1LL)
#define           MASK(i)  (1LL<<i)
#define            ALL(x)  (x).begin(),(x).end()
#define             SZ(x)  (int)(x).size()
#define                fi  first
#define                se  second
#define                ll  long long
#define                vi  vector<int>
#define               vvi  vector<vi>
#define               pii  pair<int,int>
#define              vpii  vector<pii>
#define REPDIS(i,be,en,j)  for(int i = (be); i<=(en); i+=j)
#define     REPD(i,be,en)  for(int i = (be); i>=(en); i--)
#define      REP(i,be,en)  for(int i = (be); i<=(en); i++)
//-------------------------------------------------------------//
const int oo = 1e9,LOG = 20,MAXN = 1e5+7,N = 1e2+3;
const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353;
//-------------------------------------------------------------//
template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}
template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; }
template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; }

/*
----------------------------------------------------------------
    END OF TEMPLATE
----------------------------------------------------------------
    Nguyen Ngoc Hung - nnhzzz
    Training for VOI24 gold medal
----------------------------------------------------------------
*/

int a[MAXN],k[MAXN],dp[MASK(10)|1][MASK(10)|1][11],cnt[MASK(20)|1];
int n;

void sub2(){
    vi dp(n+3),par(n+3),cnt(2100000,0);
    REP(i,0,SZ(cnt)-1) cnt[i] = __builtin_popcount(i);
    REP(i,1,n){
        dp[i] = 1;
        par[i] = 0;
    }
    REP(i,1,n){
        REP(j,1,i-1){
            int val = a[i]&a[j];
            if(cnt[val]==k[i]){
                if(maxi(dp[i],dp[j]+1)){
                    par[i] = j;
                }
            }
        }
    }
    int res = 0,pos = 0;
    REP(i,1,n){
        if(maxi(res,dp[i])) pos = i;
    }
    vi ans;
    while(pos!=0){
        ans.push_back(pos);
        pos = par[pos];
    }
    reverse(ALL(ans));
    cout << res << "\n";
    for(const auto &i:ans){
        cout << i << " ";
    }
}

void sub3(){
    vi pos(MASK(8)|1,-1),par(n+3,0),dp(n+3,1);
    REP(i,0,MASK(8)) cnt[i] = __builtin_popcount(i);
    REP(i,1,n){
        REP(j,0,MASK(8)){
            int val = a[i]&j;
            if(cnt[val]!=k[i] || pos[j]==-1) continue;
            if(maxi(dp[i],dp[pos[j]]+1)) par[i] = pos[j];
        }
        if(dp[pos[a[i]]]<dp[i]) pos[a[i]] = i;
    }
    vi ans;
    int res = 0,p = 0;
    REP(i,1,n){
        if(maxi(res,dp[i])) p = i;
    }
    while(p!=0){
        ans.push_back(p);
        p = par[p];
    }
    reverse(ALL(ans));
    cout << res << "\n";
    for(const auto &i:ans){
        cout << i << " ";
    }
}

void sub4(){
    // vector<vvi> dp(MASK(10)|1,vvi(MASK(10)|1,vi(11,-1)));
    REP(i,1,MASK(20)) cnt[i] = __builtin_popcount(i);
    memset(dp,-1,sizeof dp);
    vi f(n+3),pos(n+3);
    int res = 1,pres = 1;
    REP(i,1,n){
        int v1 = a[i]&(MASK(10)-1);
        int v2 = a[i]>>10;
        f[i] = 1; pos[i] = -1;
        REP(pre_v1,0,MASK(10)-1){
            int diff_v1 = cnt[v1&pre_v1];
            int diff_v2 = k[i]-diff_v1;
            if(diff_v2<0 || diff_v2>10) continue;
            int cur = dp[pre_v1][v2][diff_v2];
            if(cur==-1) continue;
            if(maxi(f[i],f[cur]+1)) pos[i] = cur;
        }
        if(maxi(res,f[i])) pres = i;
        REP(nxt_v2,0,MASK(10)-1){
            int diff_v2 = cnt[v2&nxt_v2];
            int &val = dp[v1][nxt_v2][diff_v2];
            if(val!=-1 && f[i]<f[val]) continue;
            val = i;
        }
    }
    cout << res << "\n";
    vi ans(1,pres);
    while(pos[ans.back()]!=-1) ans.push_back(pos[ans.back()]);
    reverse(ALL(ans));
    for(const auto &i:ans){
        cout << i << " ";
    }
}

void solve(){
    cin >> n;
    REP(i,1,n) cin >> a[i];
    REP(i,1,n) cin >> k[i];
    sub4(); return ;
    if(n<=5000){
        sub2(); return ;
    }
    int ma = 0;
    REP(i,1,n) maxi(ma,a[i]);
    if(ma<=MASK(8)){
        sub3(); return ;
    }
    sub4();
}

__nnhzzz__{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define name "test"
    if(fopen(name".inp","r")){
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    #define name1 "subsequence"
    if(fopen(name1".in","r")){
        freopen(name1".in","r",stdin);
        freopen(name1".out","w",stdout);
    }

    int test = 1;

    while(test--){
      solve();
    }
    cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Compilation message

burza.cpp: In function 'int main()':
burza.cpp:197:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  197 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
burza.cpp:198:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  198 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:202:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  202 |         freopen(name1".in","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
burza.cpp:203:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  203 |         freopen(name1".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 49756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 49756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 49756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 49884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 49756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 49888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 49752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 50008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 49896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 49756 KB Output isn't correct
2 Halted 0 ms 0 KB -