이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const int M = 8;
signed main() {
int n, id = 1, res = 0;
cin >> n;
vector<int> a(n+1), k(n+1), prv(n+1);
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=n; i++) cin >> k[i];
if(n <= 5000) {
vector<int> dp(n+1);
for(int i=1; i<=n; i++) {
dp[i] = 1;
for(int j=1; j<i; j++) {
if(__builtin_popcount(a[i] & a[j]) == k[i] && dp[i] < dp[j] + 1) {
dp[i] = dp[j] + 1;
prv[i] = j;
if(dp[i] > dp[id]) id = i;
}
}
}
cout << dp[id] << '\n';
vector<int> ans;
while(id) {
ans.push_back(id);
id = prv[id];
}
reverse(ans.begin(), ans.end());
for(int &x : ans) cout << x << " ";
return 0;
}
vector<pair<int, int> > dp(256, { -1, -1 });
for(int i=1; i<=n; i++) {
if(dp[a[i]] == pii{ -1, -1 }) dp[a[i]] = { 1, i };
for(int j=0; j<256; j++) {
if(__builtin_popcount(a[i] & j) == k[i] && dp[a[i]].first < dp[j].first + 1) {
dp[a[i]].first = dp[j].first + 1;
prv[i] = dp[j].second;
dp[a[i]].second = i;
}
}
if(dp[a[i]].first > res) {
res = dp[a[i]].first;
id = i;
}
}
cout << res << '\n';
vector<int> ans;
while(id > 0) {
ans.push_back(id);
id = prv[id];
}
reverse(ans.begin(), ans.end());
for(int &x : ans) cout << x << " ";
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... |