이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 1e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N], n, m, k[N];
#define count __builtin_popcount
int dp[N];
int par[N];
int f[1024][1024][11];
void solve(int test_case){
int i, j;
cin >> n;
for(i=1;i<=n;i++){
cin >> a[i];
}
for(i=1;i<=n;i++){
cin >> k[i];
}
vector<int> ans;
for(i=1;i<=n;i++){
int l = a[i]>>10;
int r = a[i]&1023;
int best = 0;
for(j=0;j<1024;j++){
int tmp = count(j&r);
tmp = k[i]-tmp;
if(tmp < 0 || tmp > 10)continue;
if(dp[best] < dp[f[l][j][tmp]])best = f[l][j][tmp];
}
dp[i] = dp[best]+1;
par[i] = best;
for(j=0;j<1024;j++){
int tmp = count(l&j);
if(dp[i] > dp[f[j][r][tmp]])f[j][r][tmp] = i;
}
}
m = 1;
for(i=2;i<=n;i++)if(dp[i] > dp[m])m = i;
cout << dp[m] << '\n';
while(m>0){
ans.pb(m);
m = par[m];
}
reverse(all(ans));
for(auto x : ans)cout << x << ' ';
cout << '\n';
return;
}
signed main(){
FASTIO;
#define MULTITEST 0
#if MULTITEST
int ___T;
cin >> ___T;
for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
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... |