제출 #578759

#제출 시각아이디문제언어결과실행 시간메모리
578759jeroenodbLongest beautiful sequence (IZhO17_subsequence)C++14
23 / 100
6061 ms1644 KiB
#pragma GCC optimize "Ofast" #pragma GCC optimize "unroll-loops" #include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; const int mxN = 1e5+1, oo = 1e9; int main() { int n; cin >> n; vi a(n); vector<short> k(n); for(auto& i : a) cin >> i; for(auto& i : k) cin >> i; vi dp(n),par(n,-1); for(int i=0;i<n;++i) { for(int j=0;j<i;++j) if(__builtin_popcount(a[i]&a[j])==k[i]){ dp[i] = max(dp[i],dp[j]); if(dp[i]==dp[j]) par[i]=j; } dp[i]++; } auto it = max_element(all(dp)); int i = it-dp.begin(); cout << *it << '\n'; vi b; while(i!=-1) { b.push_back(i+1); i=par[i]; } reverse(all(b)); cout << b << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...