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

#TimeUsernameProblemLanguageResultExecution timeMemory
502066ismoilovLongest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
5357 ms7664 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define all(x) (x).begin(), (x).end() #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++) #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++) #define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--) #define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--) const int maxx = 1e6+6; int a[maxx], b[maxx], c[1<<20+1], dp[maxx], pd[maxx], p[maxx]; void S(){ int n; cin >> n; fpp(i,1,n) cin >> a[i]; fpp(i,1,n) cin >> b[i], dp[i] = 1; fp(i,0,1<<20) c[i] = __builtin_popcount(i); fpp(i,1,n){ int k = b[i]; if(k <= c[a[i]]){ fmm(j,i-1,1){ if(c[a[i] & a[j]] == k){ if(dp[i] <= dp[j]){ dp[i] = dp[j] + 1; p[i] = j; } } if(dp[i] > pd[j]) break; } } pd[i] = max(pd[i-1], dp[i]); } int m = max_element(dp + 1, dp + n + 1) - dp; vector <int> ans = {m}; while(p[m]){ ans.push_back(p[m]); m = p[m]; } reverse(all(ans)); cout << ans.size() << "\n"; for(auto it : ans) cout << it << " "; } int main() { IOS; S(); }

Compilation message (stderr)

subsequence.cpp:11:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   11 | int a[maxx], b[maxx], c[1<<20+1], dp[maxx], pd[maxx], p[maxx];
      |                            ~~^~
subsequence.cpp: In function 'void S()':
subsequence.cpp:7:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
      |                            ^
subsequence.cpp:15:2: note: in expansion of macro 'fpp'
   15 |  fpp(i,1,n)
      |  ^~~
subsequence.cpp:7:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
      |                            ^
subsequence.cpp:17:2: note: in expansion of macro 'fpp'
   17 |  fpp(i,1,n)
      |  ^~~
subsequence.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
subsequence.cpp:19:2: note: in expansion of macro 'fp'
   19 |  fp(i,0,1<<20)
      |  ^~
subsequence.cpp:7:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
      |                            ^
subsequence.cpp:21:2: note: in expansion of macro 'fpp'
   21 |  fpp(i,1,n){
      |  ^~~
subsequence.cpp:9:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    9 | #define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
      |                            ^
subsequence.cpp:24:4: note: in expansion of macro 'fmm'
   24 |    fmm(j,i-1,1){
      |    ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...