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

#TimeUsernameProblemLanguageResultExecution timeMemory
518673LptN21Longest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
2743 ms92964 KiB
#include <bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL); #define PI acos(-1.0) #define eps 1e-9 #define FF first #define SS second // VECTOR (6) #define pb push_back #define lb lower_bound #define ub upper_bound #define sz(v) int((v).size()) #define all(v) (v).begin(), (v).end() #define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() ); // BIT (6) #define CNTBIT(x) __builtin_popcountll(x) #define ODDBIT(x) __builtin_parityll(x) #define MASK(i) (1LL<<(i)) #define BIT(x, i) (((x)>>(i))&1) #define SUBSET(big, small) (((big)&(small))==(small)) #define MINBIT(x) (x)&(-x) //typedef typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, int> ii; /* CODE BELOW */ const int N = 1e5 + 7, M = 10; const int oo = 1e9 + 7; const int MOD = 1e9 + 7; int n, m, k, t; int _dp[MASK(M)][MASK(M)][M+1]; int pos[MASK(M)][MASK(M)][M+1]; int trace[N], a[N], b[N]; int cnt[MASK(M)]; signed main() { //freopen("test.inp", "r", stdin); //freopen("test.out", "w", stdout); //fastIO; scanf("%d", &n); for(int i=1;i<=n;i++) { scanf("%d", &a[i]); } for(int i=1;i<=n;i++) { scanf("%d", &b[i]); } for(int i=0;i<MASK(M);i++) { cnt[i] = CNTBIT(i); } int ans = 0, ansIdx = 0; for(int i=1;i<=n;i++) { int pref = a[i]>>M; int suff = a[i]&(MASK(M)-1); int mx = 0, idx = 0; for(int j=0;j<MASK(M);j++) { int need = b[i] - cnt[pref&j]; if(need < 0 || need > M) continue; if(mx <= _dp[j][suff][need]) { mx = _dp[j][suff][need]; idx = pos[j][suff][need]; } } trace[i] = idx; if((++mx) > ans) { ans = mx, ansIdx = i; } for(int j=0;j<MASK(M);j++) { int need = cnt[suff&j]; if(_dp[pref][j][need] < mx) { _dp[pref][j][need] = mx; pos[pref][j][need] = i; } } } vector<int> result; while(ansIdx) { result.pb(ansIdx); ansIdx = trace[ansIdx]; } reverse(all(result)); printf("%d\n", ans); for(int v:result) printf("%d ", v); return 0; }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
subsequence.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
subsequence.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         scanf("%d", &b[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...