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

#TimeUsernameProblemLanguageResultExecution timeMemory
1112966adiyerLongest beautiful sequence (IZhO17_subsequence)C++17
40 / 100
83 ms7496 KiB
// #pragma optimize ("g",on) // #pragma GCC optimize("inline") // #pragma GCC optimize ("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC optimize ("03") #include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0); cin.tie(0); #define pb push_back using namespace std; typedef long long ll; const int N = 1e5 + 2; const int M = (1 << 8); ll n, pos; ll a[N], k[N], dp[N], it[M], par[N]; void sol(){ cin >> n, pos = 1; for(ll i = 1; i <= n; i++) cin >> a[i]; for(ll i = 1; i <= n; i++) cin >> k[i]; if(n <= 5e3){ for(ll i = 1; i <= n; i++){ dp[i] = 1; for(ll j = 1; j < i; j++) if((__builtin_popcount(a[j] & a[i]) == k[i])) dp[i] = max(dp[i], dp[j] + 1); if(dp[i] > dp[pos]) pos = i; // cout << dp[i] << '\n'; } vector < ll > ans; ans.pb(pos); while(ans.size() < dp[ans[0]]){ if(ans.size() == dp[ans[0]]) break; for(ll i = pos - 1; i >= 1; i--){ if(__builtin_popcountll(a[pos] & a[i]) == k[pos] && dp[pos] == dp[i] + 1){ pos = i; break; } } ans.pb(pos); } reverse(ans.begin(), ans.end()); cout << ans.size() << '\n'; for(ll x : ans) cout << x << ' '; } else{ for(ll i = 1; i <= n; i++){ dp[i] = 1; for(ll msk = 0; msk < M; msk++) if((__builtin_popcount(msk & a[i]) == k[i]) && dp[it[msk]] + 1 > dp[i]) dp[i] = dp[it[msk]] + 1, par[i] = it[msk]; if(dp[i] > dp[it[a[i]]]) it[a[i]] = i; if(dp[i] > dp[pos]) pos = i; // cout << dp[i] << '\n'; } vector < ll > ans; ans.pb(pos); while(ans.size() < dp[ans[0]]){ if(ans.size() == dp[ans[0]]) break; pos = par[pos]; ans.pb(pos); } reverse(ans.begin(), ans.end()); cout << ans.size() << '\n'; for(ll x : ans) cout << x << ' '; } } signed main(){ ios sol(); // slow(); // stress(); }

Compilation message (stderr)

subsequence.cpp: In function 'void sol()':
subsequence.cpp:37:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   37 |   while(ans.size() < dp[ans[0]]){
      |         ~~~~~~~~~~~^~~~~~~~~~~~
subsequence.cpp:38:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   38 |    if(ans.size() == dp[ans[0]]) break;
      |       ~~~~~~~~~~~^~~~~~~~~~~~~
subsequence.cpp:63:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   63 |   while(ans.size() < dp[ans[0]]){
      |         ~~~~~~~~~~~^~~~~~~~~~~~
subsequence.cpp:64:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   64 |    if(ans.size() == dp[ans[0]]) break;
      |       ~~~~~~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...