이 제출은 이전 버전의 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 ans = 0;
int e = -1;
int max_val = (1 << 10);
vector<int> p(n, -1);
vector<vector<vector<int> > > pos(11, vector<vector<int> >(max_val, vector<int>(max_val, -1)));
vector<vector<vector<int> > > dp(11, vector<vector<int> >(max_val, vector<int>(max_val, 0)));
for(int i = 0; i < n; i++)
{
int left = a[i] & ((1 << 11) - 1);
int right = a[i] >> 10;
int max_ = 1;
int id = -1;
for(int mask = 0; mask < max_val; mask++)
{
int need = k[i] - __builtin_popcount(left & mask);
if(need < 0 || need > 10) continue;
if(max_ < dp[need][mask][right] + 1)
{
max_ = dp[need][mask][right] + 1;
id = pos[need][mask][right];
}
}
p[i] = id;
if(ans < max_)
{
ans = max_;
e = i;
}
for(int mask = 0; mask < max_val; mask++)
{
int cnt = __builtin_popcount(right & mask);
if(dp[cnt][left][mask] < max_)
{
dp[cnt][left][mask] = max_;
pos[cnt][left][mask] = i;
}
}
}
cout << ans << "\n";
vector<int> path;
while(e != -1)
{
path.push_back(e + 1);
e = p[e];
}
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);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
}
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... |