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

#TimeUsernameProblemLanguageResultExecution timeMemory
472434ShinLongest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
5652 ms48344 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define TASK "task" #define all(x) x.begin(), x.end() #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) using namespace std; const int N = 2e5 + 7; const int MOD = 1e9 + 7; // 998244353; const int INF = 1e9 + 7; const long long INFLL = 1e18 + 7; typedef long long ll; typedef unsigned long long ull; template <class X, class Y> bool minimize(X &a, Y b) { if (a > b) return a = b, true; return false; } template <class X, class Y> bool maximize(X &a, Y b) { if (a < b) return a = b, true; return false; } #define right __right #define left __left #define get_left(mask) (mask >> 10) #define get_right(mask) (mask & 1023) int n; int a[N]; int k[N]; int best[N]; int trace[N]; int dp[MASK(10)][MASK(10)][11]; void solve(void) { scanf("%d", &n); for (int i = 1; i <= n; i ++) scanf("%d", &a[i]); for (int i = 1; i <= n; i ++) scanf("%d", &k[i]); for (int i = 1; i <= n; i ++) { int left = get_left(a[i]); int right = get_right(a[i]); for (int mask = 0; mask < MASK(10); mask ++) { int need = k[i] - __builtin_popcount(right & mask); if (0 > need || need > 10) continue; if (maximize(best[i], best[dp[left][mask][need]])) { trace[i] = dp[left][mask][need]; } } best[i] ++; for (int mask = 0; mask < MASK(10); mask ++) { int cntbit = __builtin_popcount(mask & left); if (best[i] > best[dp[mask][right][cntbit]]) dp[mask][right][cntbit] = i; } } int res = 0; for (int i = 1; i <= n; i ++) if (best[i] > best[res]) res = i; vector<int> idx; for (int i = res; i; i = trace[i]) idx.push_back(i); printf("%d\n", (int) idx.size()); reverse(all(idx)); for (int i: idx) printf("%d ", i); } int main(void) { int test = 1; // cin >> test; while (test --) { solve(); } return 0; }

Compilation message (stderr)

subsequence.cpp: In function 'void solve()':
subsequence.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
subsequence.cpp:42:40: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
      |                                   ~~~~~^~~~~~~~~~~~~
subsequence.cpp:43:40: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     for (int i = 1; i <= n; i ++) scanf("%d", &k[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...