# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1155703 | eudhsyf | Round words (IZhO13_rowords) | C++20 | 1 ms | 396 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define task "file"
const int nmax = 1e5 + 5;
pii dp[(1 << 10) + 5][(1 << 10) + 5][25];
int a[nmax], b[nmax], pre[nmax], ma, pos, n;
signed main ()
{
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
for (int i = 1; i <= n; i++) {
int l = (a[i] >> 10);
int r = a[i] % (1 << 10);
int lbs = 1;
for (int mask = 0; mask < (1 << 10); mask ++) {
int x = __builtin_popcount(l & mask);
int need = b[i] - x;
if(need < 0 || need > 10) {
continue;
}
if(dp[mask][r][need].fi + 1 > lbs) {
lbs = dp[mask][r][need].fi + 1;
pre[i] = dp[mask][r][need].se;
}
}
if(lbs > ma) {
pos = i;
ma = lbs;
}
for (int mask = 0; mask < (1 << 10); mask ++) {
int x = __builtin_popcount(r & mask);
if(dp[l][mask][x].fi < lbs) {
dp[l][mask][x].fi = lbs;
dp[l][mask][x].se = i;
}
}
}
vector<int> ans;
while(pos != 0) {
ans.emplace_back(pos);
pos = pre[pos];
}
cout << ma << '\n';
reverse(ans.begin(), ans.end());
for (auto x : ans) {
cout << x << ' ';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |