이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7, pr = 31;
const int mxn = 1e5 + 5, mxq = 1e5 + 5, sq = 450, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e18 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
// <3;
int n;
int mx[(1 << 10)][(1 << 10)][21], a[mxn + 1], k[mxn + 1], dp[mxn + 1], trace[mxn + 1];
int cnt[(1 << 10)][(1 << 10)];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++)cin >> a[i];
for(int i = 1; i <= n; i++)cin >> k[i];
for(int i = 0; i < (1 << 10); i++){
for(int j = 0; j < (1 << 10); j++){
cnt[i][j] = __builtin_popcount(i & j);
}
}
int ans = 0, node = -1;
for(int i = 1; i <= n; i++){
int fir = (a[i] % (1 << 10)), fin = (a[i] >> 10);
dp[i] = 1; trace[i] = -1;
for(int j = 0; j < (1 << 10); j++){
int need = k[i] - cnt[fir][j];
if(need < 0)continue;
int cand = mx[j][fin][need];
if(dp[cand] + 1 > dp[i]){
dp[i] = dp[cand] + 1; trace[i] = cand;
}
}
for(int j = 0; j < (1 << 10); j++){
int have = cnt[j][fin], curr = mx[fir][j][have];
if(dp[curr] < dp[i]){
mx[fir][j][have] = i;
}
}
if(dp[i] > ans){
ans = dp[i]; node = i;
}
}
vt<int>v;
while(node != -1){
v.pb(node); node = trace[node];
}
reverse(ALL(v));
cout << ans << "\n";
for(auto i: v)cout << i << " ";
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("netw.inp", "r", stdin);
//freopen("netw.out", "w", stdout)
int tt; tt = 1;
while(tt--){
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... |