Submission #1130403

#TimeUsernameProblemLanguageResultExecution timeMemory
1130403zhasynLongest beautiful sequence (IZhO17_subsequence)C++20
23 / 100
6085 ms22548 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); } bool was[5010][5010]; int check(int a, int b){ int res = 0; while(true){ if(a == 0 || b == 0) break; if(a%2 + b%2 == 2) res++; a /= 2; b /= 2; } return res; } int a[N], k[N]; int main() { //ios_base::sync_with_stdio(false); //cin.tie(nullptr); //cout.tie(nullptr); int n, cnt = 1, num = 0; cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; } for(int i = 0; i < n; i++){ cin >> k[i]; } for(int i = 0; i < n; i++){ for(int j = i - 1; j >= 0; j--){ //cout << i << " "<< j << " "<< k[i] << " "<< check(a[i], a[j]) << endl; if(check(a[i], a[j]) != k[i]) continue; for(int nw = 1; nw < n; nw++){ was[i][nw + 1] |= was[j][nw]; if(was[i][nw + 1] && nw + 1 > cnt){ cnt = nw + 1; num = i; } } } was[i][1] = true; } cout << cnt << endl; vector <int> vec; while(cnt > 1){ vec.pb(num); cnt--; for(int j = num - 1; j >= 0; j--){ if(check(a[num], a[j]) != k[num]) continue; if(was[j][cnt]){ num = j; break; } } } cout << num + 1 << " "; for(int i = (int)vec.size() - 1; i >= 0; i--){ cout << vec[i] + 1 << " "; } 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...