이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pw(x) (1ll << x)
#define sz(x) (int)((x).size())
#define pb push_back
#define endl '\n'
#define mp make_pair
#define vec vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef unsigned long long ull;
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T>
using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
#define bcnt(x) __builtin_popcount(x)
pii ndp[pw(10)][pw(10)][21];
inline void solve () {
int n; cin >> n;
vector <int> a (n); for (auto &i : a) cin >> i;
vector <int> k (n); for (auto &i : k) cin >> i;
auto lef = [&] (int x) { return (x & (pw(10) - 1)); };
auto rig = [&] (int x) { return (x - lef(x)) >> 10; };
vector <int> dp (n, 1), p (n); iota(all(p), 0);
for (int i = 0; i < n; ++i) {
int q = lef(a[i]), w = rig(a[i]);
pii vdp = {0, -1};
for (int msk = 0; msk < pw(10); ++msk) {
int need = k[i] - bcnt(q & msk);
if (need < 0) continue;
umax(vdp, ndp[msk][w][need]);
}
++vdp.fr;
tie(dp[i], p[i]) = vdp;
vdp.sc = i;
for (int msk = 0; msk < pw(10); ++msk) umax(ndp[q][msk][bcnt(w & msk)], vdp);
}
int x = max_element(all(dp)) - dp.begin();
vector <int> res;
while (p[x] != x) res.pb(x), x = p[x];
res.pb(x);
reverse(all(res));
cout << sz(res) << endl;
for (auto i : res) cout << i + 1 << " ";
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1; // cin >> t;
while (t--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |