(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #337990

#TimeUsernameProblemLanguageResultExecution timeMemory
337990spike1236Longest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
3041 ms61548 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define f first #define s second #define ll long long #define ld long double #define all(_v) _v.begin(), _v.end() #define sz(_v) (int)_v.size() #define pii pair <int, int> #define pll pair <ll, ll> #define veci vector <int> #define vecll vector <ll> const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const double PI = 3.1415926535897932384626433832795; const double eps = 1e-9; const int MOD1 = 1e9 + 7; const int MOD2 = 998244353; const int MAXN = (1 << 20) + 10, MAXN2 = (1 << 10) + 10; int n; int dp[MAXN]; int p2[MAXN2][MAXN2][12]; int a[MAXN]; int k[MAXN]; int bp[MAXN]; int p[MAXN]; void solve() { for(int i = 0; i < (1 << 20); ++i) bp[i] = __builtin_popcount(i); cin >> n; int mxb = 0; for(int i = 1; i <= n; ++i) cin >> a[i]; for(int i = 1; i <= n; ++i) cin >> k[i]; memset(p, -1, sizeof(p)); memset(p2, -1, sizeof(p2)); for(int i = 1; i <= n; ++i) { dp[i] = 1; int mask1 = (a[i] % (1 << 10)); int mask2 = (a[i] / (1 << 10)); for(int j = 0; j < (1 << 10); ++j) { int x = bp[(mask2 & j)]; if(k[i] >= x && k[i] - x <= 10 && p2[j][mask1][k[i] - x] != -1) { int res = dp[p2[j][mask1][k[i] - x]] + 1; if(res > dp[i]) { dp[i] = res; p[i] = p2[j][mask1][k[i] - x]; } } } for(int j = 0; j < (1 << 10); ++j) { int x = bp[mask1 & j]; if(p2[mask2][j][x] == -1 || dp[p2[mask2][j][x]] < dp[i]) p2[mask2][j][x] = i; } } int mx = max_element(dp + 1, dp + n + 1) - dp; veci ans; while(mx != -1) { ans.pb(mx); mx = p[mx]; } reverse(all(ans)); cout << sz(ans) << '\n'; for(auto it : ans) cout << it << ' '; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; ///cin >> T; while(T--) solve(), cout << '\n'; return 0; }

Compilation message (stderr)

subsequence.cpp: In function 'void solve()':
subsequence.cpp:35:9: warning: unused variable 'mxb' [-Wunused-variable]
   35 |     int mxb = 0;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...