Submission #1276991

#TimeUsernameProblemLanguageResultExecution timeMemory
1276991icebearLongest beautiful sequence (IZhO17_subsequence)C++20
0 / 100
9 ms3132 KiB
// ~~ icebear ~~ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; template<class T> bool minimize(T &a, const T &b) { if (a > b) return a = b, true; return false; } template<class T> bool maximize(T &a, const T &b) { if (a < b) return a = b, true; return false; } #define FOR(i,a,b) for(int i=(a); i<=(b); ++i) #define FORR(i,a,b) for(int i=(a); i>=(b); --i) #define REP(i, n) for(int i=0; i<(n); ++i) #define RED(i, n) for(int i=(n)-1; i>=0; --i) #define MASK(i) (1LL << (i)) #define BIT(S, i) (((S) >> (i)) & 1) #define mp make_pair #define pb push_back #define fi first #define se second #define all(x) x.begin(), x.end() #define task "icebear" const int MOD = 1e9 + 7; const int inf = 1e9 + 27092008; const ll INF = 1e18 + 27092008; const int N = 1e5 + 5; int n, a[N], k[N]; ii f[MASK(10)][MASK(10)][22]; int dp[N], trace[N]; void init(void) { cin >> n; FOR(i, 1, n) cin >> a[i]; FOR(i, 1, n) cin >> k[i]; } void process(void) { FOR(i, 1, n) { int l = a[i] & (MASK(10) - 1); int r = a[i] >> 10; ii mx = mp(0, 0); REP(mask, MASK(10)) maximize(mx, f[mask][r][k[i] - __builtin_popcount(l & mask)]); dp[i] = mx.fi + 1; trace[i] = mx.se; ii nxt = mp(mx.fi + 1, i); REP(mask, MASK(10)) maximize(f[l][mask][__builtin_popcount(mask & l)], nxt); } int j = max_element(dp + 1, dp + n + 1) - dp; vector<int> ans; while(j > 0) { ans.pb(j); j = trace[j]; } reverse(all(ans)); cout << ans.size() << '\n'; for(int x : ans) cout << x << ' '; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int tc = 1; // cin >> tc; while(tc--) { init(); process(); } return 0; }

Compilation message (stderr)

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