# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
55228 | BThero | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 2 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Why I am so dumb? :c
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
const bool SEND = 1;
const int MAXN = 1e5+5;
int need[MAXN];
int arr[MAXN];
int par[MAXN];
int dp[MAXN];
int n;
void calcSlow() {
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
if (__builtin_popcount(arr[i] & arr[j]) == need[j]) {
if (dp[i] + 1 > dp[j]) {
dp[j] = dp[i] + 1;
par[j] = i;
}
}
}
}
}
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &arr[i]);
}
for (int i = 1; i <= n; ++i) {
scanf("%d", &need[i]);
}
for (int i = 1; i <= n; ++i) {
dp[i] = 1;
}
if (n <= 5000 && SEND) {
calcSlow();
return;
}
else {
vector<int> M(256, 0);
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 256; ++j) {
if (__builtin_popcount(arr[i] & j) == need[i]) {
if (dp[M[j]] + 1 > dp[i]) {
dp[i] = dp[M[j]] + 1;
par[i] = M[j];
}
}
}
if (dp[i] > dp[M[arr[i]]]) {
M[arr[i]] = i;
}
}
}
vector<int> vv;
int mx = 1;
for (int i = 2; i <= n; ++i) {
if (dp[i] > dp[mx]) {
mx = i;
}
}
for (int x = mx; x; x = par[x]) {
vv.pb(x);
}
reverse(all(vv));
printf("%d\n", vv.size());
for (int it : vv) {
printf("%d ", it);
}
}
int main() {
int tt = 1;
while (tt--) {
solve();
}
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... |