# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1273847 | chanhchuong123 | Longest beautiful sequence (IZhO17_subsequence) | C++20 | 2410 ms | 169948 KiB |
#include<bits/stdc++.h>
using namespace std;
const bool multiTest = false;
#define task "C"
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define BIT(mask, i) ((mask) >> (i) & 1)
template<typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) a = b; else return 0; return 1;
}
template<typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) a = b; else return 0; return 1;
}
const int MAX = 100010;
int n;
int a[MAX];
int k[MAX];
int prv[MAX];
int cnt[1 << 10][1 << 10];
pair<int, int> dp[1 << 10][1 << 10][20];
void process(void) {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> k[i];
for (int i = 0; i < (1 << 10); ++i) for (int j = 0; j < (1 << 10); ++j) {
cnt[i][j] = __builtin_popcount(i & j);
}
int ans = 0, bestPos = 0;
for (int i = 1; i <= n; ++i) {
int l = a[i] >> 10, r = a[i] & ((1 << 10) - 1), cur = 1;
for (int mask = 0; mask < (1 << 10); ++mask) {
int numBit = k[i] - cnt[l][mask]; if (numBit < 0 || numBit > 10) continue;
pair<int, int> &pp = dp[mask][r][numBit];
if (maximize(cur, pp.fi + 1)) {
if (pp.se > 0) prv[i] = pp.se;
}
}
if (maximize(ans, cur)) {
bestPos = i;
}
for (int mask = 0; mask < (1 << 10); ++mask) {
pair<int, int> &pp = dp[l][mask][cnt[r][mask]];
if (maximize(pp.fi, cur)) {
pp.se = i;
}
}
}
cout << ans << '\n';
vector<int> res;
while (bestPos > 0) {
res.push_back(bestPos);
bestPos = prv[bestPos];
}
reverse(all(res));
for (int &pos: res) cout << pos << ' ';
}
int main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int nTest = 1; if (multiTest) cin >> nTest;
while (nTest--) {
process();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |