Submission #1269154

#TimeUsernameProblemLanguageResultExecution timeMemory
1269154BuiDucManh123Longest beautiful sequence (IZhO17_subsequence)C++20
100 / 100
2520 ms129372 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define ull unsigned long long #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define taskname "" #define ld long double const int mod = 1e9+7; using namespace std; int a[100009], k[100009], dp[100009], f[2009][2009][30], cnt[2009], trace[100009]; signed main() { if (fopen(taskname".inp","r")) { freopen(taskname".inp","r",stdin); freopen(taskname".out","w",stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i <= n; i++){ cin >> k[i]; } for(int i = 0; i < (1 << 10); i++){ for(int j = 0; j < 10; j++){ if((i >> j) & 1){ cnt[i]++; } } } int ans = 0; int chose = 0; for(int i = 1; i <= n; i++){ int left = a[i] >> 10; int right = a[i] - (left << 10); //cout << left << " " << right << "\n"; int ma = 0; int pos = 0; for(int j = 0; j < (1 << 10); j++){ int sz = j & left; if(ma < dp[f[j][right][k[i] - cnt[sz]]]){ ma = dp[f[j][right][k[i] - cnt[sz]]]; pos = f[j][right][k[i] - cnt[sz]]; } } dp[i] = ma + 1; trace[i] = pos; for(int j = 0; j < (1 << 10); j++){ int x = j & right; if(dp[i] > dp[f[left][j][cnt[x]]]){ f[left][j][cnt[x]] = i; } } if(ans < dp[i]){ ans = dp[i]; chose = i; } } vector<int> hehe; while(chose){ hehe.pb(chose); chose = trace[chose]; } cout << hehe.size() << "\n"; reverse(hehe.begin(), hehe.end()); for(int x : hehe){ cout << x << " "; } return 0; }

Compilation message (stderr)

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