Submission #1125530

#TimeUsernameProblemLanguageResultExecution timeMemory
1125530zhasynLongest beautiful sequence (IZhO17_subsequence)C++20
0 / 100
1 ms328 KiB
#include <bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; #define F first #define S second typedef long long ll; #define pii pair <int, int> #define pll pair <ll, ll> typedef long double ld; const ll N = 5000 + 100, M = 500 + 10, len = 315, inf = 1e18; const ll mod = 998244353; ll um(ll a, ll b){ return (1LL * a * b) % mod; } ll subr(ll a, ll b){ return ((1LL * a - b) % mod + mod) % mod; } ll bp(ll x, ll step){ ll res = 1; while(step){ if(step & 1) res = um(res, x); x = um(x, x); step /= 2; } return res; } ll inv(ll x){ return bp(x, mod - 2); } int a[N], k[N], pred[N][N]; vector<int> vec[N]; int calc(int a, int b){ int res = 0; while(true){ if(a + b == 0) break; if(a % 2 + b%2 == 2) res++; a /= 2; b /= 2; } return res; } int main() { //ios_base::sync_with_stdio(false); //cin.tie(nullptr); //cout.tie(nullptr); int n; cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i <= n; i++){ cin >> k[i]; } int sz = 1, num = 1; for(int i = 1; i <= n; i++){ for(int j = n; j >= 1; j--){ for(auto u : vec[j]){ if(calc(a[u], a[i]) == k[j + 1]){ vec[j + 1].pb(i); pred[i][j + 1] = u; if(j + 1 > sz){ sz = j + 1; num = i; } break; } } } vec[1].pb(i); } cout << sz << endl; vector <int>ans; while(sz != 0){ ans.pb(num); num = pred[num][sz]; sz--; } reverse(ans.begin(), ans.end()); for(auto u : ans){ cout << u << " "; } 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...