Submission #1128737

#TimeUsernameProblemLanguageResultExecution timeMemory
1128737BilAktauAlmansurLongest beautiful sequence (IZhO17_subsequence)C++20
23 / 100
36 ms3652 KiB
#include <bits/stdc++.h> #pragma optimize("g", on) #pragma GCC optimize ("03") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native") void Freopen () { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } using namespace std; #define fi first #define se second #define int long long const int N = 1e6 + 7, M = 1e5 + 1, mod = 1e9 + 7; int n, a[N], b[N], dp[N], pr[N], last[N]; void solve() { cin>>n; int maxx = 0; for(int i = 1; i <= n; i++) { cin>>a[i]; maxx = max(maxx, a[i]); } for(int j = 1; j <= n; j++)cin>>b[j]; if(n <= 5000) { int mx = 0, cur = -1; for(int i = 1; i <= n; i++) { dp[i] = 1; for(int j = i - 1; j >= 1; j--) { if(__builtin_popcount(a[i] & a[j]) == b[i]) { if(dp[i] < (dp[j] + 1)) { dp[i] = dp[j] + 1, pr[i] = j; } } } if(mx < dp[i])mx = dp[i], cur = i; } cout << mx << '\n'; vector<int> vec; while(cur != 0) { vec.push_back(cur); cur = pr[cur]; } reverse(vec.begin(), vec.end()); for(auto j : vec)cout << j << ' '; cout << '\n'; return; } int mx = 0, cur = -1; for(int i = 1; i <= n; i++) { dp[i] = 1; for(int j = 0; j <= maxx; j++) { if(__builtin_popcount(a[i] & j) != b[i])continue; int ps = last[j]; if(dp[i] < (dp[ps] + 1)) { dp[i] = dp[ps] + 1, pr[i] = ps; } } last[a[i]] = i; if(mx < dp[i])mx = dp[i], cur = i; } cout << mx << '\n'; vector<int> vec; while(cur != 0) { vec.push_back(cur); cur = pr[cur]; } reverse(vec.begin(), vec.end()); for(auto j : vec)cout << j << ' '; cout << '\n'; } signed main() { // freopen("duty.in", "r", stdin); // freopen("duty.out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //Freopen(); int T = 1; // cin>>T; while(T --)solve(); }

Compilation message (stderr)

subsequence.cpp: In function 'void Freopen()':
subsequence.cpp:7:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen("output.txt", "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...