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

#TimeUsernameProblemLanguageResultExecution timeMemory
388369DymoLongest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
5608 ms102540 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull long long #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" const ll maxn =4e5+10; const ll mod=998244353 ; const ll base=1e18; ll n; ll a[maxn]; ll k[maxn]; ll ans[maxn]; ll dp[(1ll<<10)][(1ll<<10)][12]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen("t.inp","r")) { freopen("test.inp","r",stdin); freopen("test.out","w",stdout); } cin>> n; for (int i=1;i<=n;i++) { cin>>a[i]; } for (int i=1;i<=n;i++) { cin>>k[i]; } ll pos=-1; ll mx=0; for (int i=1;i<=n;i++) { ans[i]=1; ll lf=a[i]>>10; ll rt=a[i]&((1ll<<10)-1); for (int j=0;j<(1ll<<10);j++) { ll cnt=__builtin_popcount(j&rt); if (k[i]-cnt>=0&&k[i]-cnt<=10) ans[i]=max(ans[i],dp[lf][j][k[i]-cnt]+1); } for (int j=0;j<(1ll<<10);j++) { dp[j][rt][__builtin_popcount(lf&j)]=max(dp[j][rt][__builtin_popcount(lf&j)],ans[i]); } if (ans[i]>mx) { mx=ans[i]; pos=i; } } cout <<mx<<endl; ll t=pos; vector<ll> vt; vt.pb(pos); for (int i=pos-1;i>=1;i--) { // cout <<ans[i]<<" "<<ans[t]<<" "<<<<endl; if (ans[i]+1==ans[t]&&__builtin_popcount(a[i]&a[t])==k[t]) { // cout <<"WYTF"<<endl; vt.pb(i); t=i; if (ans[t]==1) break; } } reverse(vt.begin(),vt.end()); for (auto to:vt) cout<<to<<" "; /*4 1 2 3 4 10 0 1 0*/ /*5 5 3 5 3 5 10 1 20 1 20*/ }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   27 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...