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

#TimeUsernameProblemLanguageResultExecution timeMemory
502455wwddLongest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
2105 ms50328 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vl; const int MB = 10; const int MA = 1<<MB; const int LIM = MA-1; int dp[MA][MA][MB+1]; int poc[MA]; int main() { ios::sync_with_stdio(0);cin.tie(0); ll n; cin >> n; vl mol(n,0),pt(n,-1); vl wo,wk; memset(dp,-1,sizeof(dp)); for(int i=0;i<n;i++) { ll t; cin >> t; wo.push_back(t); } for(int i=0;i<n;i++) { ll t; cin >> t; wk.push_back(t); } poc[0] = 0; for(int i=1;i<MA;i++) { poc[i] = poc[i>>1]+(i&1); } for(int i=0;i<n;i++) { int ho = wo[i]>>MB; int lo = wo[i]&LIM; mol[i] = 1; for(int j=0;j<MA;j++) { int rem = wk[i]-poc[ho&j]; if(rem < 0 || rem > MB) {continue;} int cand = dp[j][lo][rem]; if(cand == -1) {continue;} if(mol[cand]+1 > mol[i]) { mol[i] = mol[cand]+1; pt[i] = cand; } } for(int j=0;j<MA;j++) { int kt = poc[j&lo]; int dv = dp[ho][j][kt]; if(dv == -1 || mol[dv] < mol[i]) { dp[ho][j][kt] = i; } } } int mi = 0; for(int i=0;i<n;i++) { if(mol[i] > mol[mi]) { mi = i; } } vl ans; while(mi != -1) { ans.push_back(mi); mi = pt[mi]; } reverse(ans.begin(),ans.end()); cout << ans.size() << '\n'; for(int i=0;i<ans.size();i++) { if(i > 0) {cout << " ";} cout << ans[i]+1; } cout << '\n'; }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:66:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  for(int i=0;i<ans.size();i++) {
      |              ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...