이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
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 double eps = 1e-9;
int32_t main() {
int n;
cin >> n;
vector<int> a(n+1), k(n+1);
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=n; i++) cin >> k[i];
bool dp[n+1][n+1];
pii par[n+1][n+1];
memset(dp, 0, sizeof(dp));
for(int i=1; i<=n; i++) dp[i][1] = 1;
for(int i=0; i<=n; i++)
for(int j=0; j<=n; j++) par[i][j] = { -1, - 1 };
for(int j=2; j<=n; j++) {
for(int i=2; i<=n; i++) {
for(int x=1; x<i; x++) {
if(__builtin_popcount(a[i] & a[x]) == k[j] && dp[x][j-1]) dp[i][j] = 1, par[i][j] = { x, j - 1 };
}
}
}
int ans = 0;
pii curr = { 0, 0 };
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
if(dp[i][j] && ans < j) ans = j, curr = { i, j };
cout << ans << '\n';
vector<int> v;
while(curr != pii{ -1, -1 }) {
v.push_back(curr.first);
curr = par[curr.first][curr.second];
}
reverse(all(v));
for(int &x : v) 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... |