이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<string>
#include<time.h>
#include<iomanip>
#include<assert.h>
#include<math.h>
#include<chrono>
#include<random>
#include<bitset>
using namespace std;
const int64_t INF = (int64_t) 5 * 1e5 + 5;
const int64_t mINF = (int64_t) 1e9 + 5;
const int64_t MOD = (int64_t) 1e9 + 9;
const int nbit = 30;
const int ndig = 10;
const int nchar = 26;
const int p1 = 31;
const int p2 = 53;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};
// 0 right // 1 down // 2 left // 3 up
struct Solution
{
int n;
vector<int> a;
vector<int> k;
Solution() {}
void solve()
{
cin >> n;
a.resize(n, 0);
k.resize(n, 0);
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
for(int i = 0; i < n; i++)
{
cin >> k[i];
}
int max_ = (1 << 8) + 5;
vector<int> dp(n, 1);
vector<int> p(n, -1);
vector<int> pos(max_, -1);
for(int i = 0; i < n; i++)
{
int id = -1;
for(int val = 0; val < max_; val++)
{
int cnt = __builtin_popcount(a[i] & val);
if(cnt != k[i] || pos[val] == -1) continue;
if(dp[i] < dp[pos[val]] + 1)
{
dp[i] = dp[pos[val]] + 1;
id = pos[val];
}
}
p[i] = id;
if(pos[a[i]] == -1 || (pos[a[i]] != -1 && dp[pos[a[i]]] < dp[i])) pos[a[i]] = i;
}
int e = -1;
int ans = 0;
for(int i = 0; i < n; i++)
{
if(ans >= dp[i]) continue;
e = i;
ans = max(ans, dp[i]);
}
vector<int> path;
while(e != -1)
{
path.push_back(e + 1);
e = p[e];
}
cout << ans << "\n";
reverse(path.begin(), path.end());
for(int i = 0; i < (int) path.size(); i++)
{
cout << path[i] << " ";
}
cout << "\n";
}
};
void __startup()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int main()
{
__startup();
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
Solution().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... |