(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 #338049

#TimeUsernameProblemLanguageResultExecution timeMemory
338049BY_KUTBILIMLongest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
5415 ms47748 KiB
/** @BY_KUTBILIM **/ #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).end() const int N = (int)1e5+7; int dp[N], p[N]; int c[1024][1024][11]; int main(){ //ios_base::sync_with_stdio(false); //cin.tie(); int n; cin >> n; int a[n+1], k[n+1]; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i <= n; i++){ cin >> k[i]; } for(int i = 1; i <= n; i++){ int j = 0; int top10 = (a[i] >> 10); int last10 = (a[i] & 1023); for(int mask = 0; mask < (1 << 10); mask++){ int cnt = k[i] - (__builtin_popcount(mask & last10)); if(cnt >= 0 and cnt <= 10){ if(dp[j] < dp[c[top10][mask][cnt]]){ j = c[top10][mask][cnt]; } } } dp[i] = dp[j] + 1; p[i] = j; int cnt = 0; for(int mask = 0; mask < (1 << 10); mask++){ cnt = __builtin_popcount(mask & top10); if(dp[c[mask][last10][cnt]] < dp[i]){ c[mask][last10][cnt] = i; } } } int I = 0, ans = 0; vector<int> path; for(int i = 1; i <= n; i++){ if(dp[i] > ans){ I = i; ans = dp[i]; } } while(I){ path.pb(I); I = p[I]; } reverse(all(path)); cout << ans << endl; for(auto x : path){ cout << x << " "; } return 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...