Submission #465426

#TimeUsernameProblemLanguageResultExecution timeMemory
465426YuisuyunoLongest beautiful sequence (IZhO17_subsequence)C++14
40 / 100
6083 ms2408 KiB
//Nguyen Huu Hoang Minh #include <bits/stdc++.h> #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define reset(x) memset(x, 0,sizeof(x)) #define bc(x) __builtin_popcount(x) #define pb push_back #define mp make_pair #define fi first #define se second #define N 100005 #define remain(x) if (x > MOD) x -= MOD #define ii pair<int, int> #define iiii pair< ii , ii > #define viiii vector< iiii > #define vi vector<int> #define vii vector< ii > #define bit(x, i) (((x) >> (i)) & 1) #define Task "test" using namespace std; typedef long double ld; const int inf = 1e10; const int minf = -1e10; int n; int a[N]; int k[N]; int dp[N]; int Mx[N], ptr; int trc[N]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); 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=1; i<=n; i++) dp[i] = 1; int mx=1, ptr=1; for(int i=1; i<=n; i++){ Mx[i] = max(Mx[i-1],dp[i]); if (bc(a[i]) < k[i]) continue; for(int j=i-1; j>=1; j--){ if (bc(a[i] & a[j])==k[i]){ if (dp[j] >= dp[i]){ dp[i] = dp[j]+1; trc[i] =j; } if (dp[i] > mx){ mx = dp[i]; ptr = i; } } if (Mx[j] < dp[i]) break; } Mx[i] = max(Mx[i-1],dp[i]); } vector<int> ans; while (ptr){ ans.pb(ptr); ptr=trc[ptr]; } reverse(all(ans)); cout << ans.size() << '\n'; for(auto x : ans) cout << x << ' '; return 0; }

Compilation message (stderr)

subsequence.cpp:24:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+10' to '2147483647' [-Woverflow]
   24 | const int inf = 1e10;
      |                 ^~~~
subsequence.cpp:25:18: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+10' to '-2147483648' [-Woverflow]
   25 | const int minf = -1e10;
      |                  ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...