Submission #783080

#TimeUsernameProblemLanguageResultExecution timeMemory
783080mgl_diamondLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
10 ms8828 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
 
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define file "input"
 
void setIO() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  if (fopen(file".in", "r")) {
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
  }
}

const int N = 1e5+5;
const int V = 1 << 10;

int n, a[N], k[N], bc[V][V], from[N];
pair<int, int> best, dp[V][V][11];

int main() {
  setIO();

  cin >> n;
  foru(i, 1, n) cin >> a[i];
  foru(i, 1, n) cin >> k[i];
  
  foru(i, 0, V-1)
    foru(j, 0, V-1)
      bc[i][j] = __builtin_popcount(i & j);
    
  foru(i, 1, n) {
    int l = 0, r = 0;
    foru(j, 0, 9) if (a[i] >> j & 1) l += 1 << j;
    foru(j, 10, 19) if (a[i] >> j & 1) r += 1 << j;
    r >>= 1;

    pair<int, int> at({0, 0});
    foru(mask, 0, V-1) {
      int need = k[i] - bc[l][mask];
      if (need < 0 || need > 10) continue;
      if (dp[mask][r][need] > at) at = dp[mask][r][need];
    }

    at.first += 1;
    from[i] = at.second;
    at.second = i;
    if (at > best) best = at;

    foru(mask, 0, V-1) {
      pair<int, int> &xet = dp[l][mask][bc[r][mask]];
      if (at > xet) xet = at;
    }
  }

  vector<int> ind;
  while (true) {
    ind.push_back(best.second);
    if (!from[best.second]) break;
    best.second = from[best.second];
  }
  cout << sz(ind) << "\n";
  reverse(all(ind));
  fore(x, ind) cout << x << " ";
}

Compilation message (stderr)

subsequence.cpp: In function 'void setIO()':
subsequence.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen(file".in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen(file".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...