QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#644041 | #4629. Longest Increasing Subsequence | Mine_King | WA | 1ms | 3892kb | C++14 | 1.8kb | 2024-10-16 10:19:44 | 2024-10-16 10:19:52 |
Judging History
answer
// 長い夜の終わりを信じながら
// Think twice, code once.
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define eputchar(c) putc(c, stderr)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define eputs(str) fputs(str, stderr), putc('\n', stderr)
using namespace std;
int n;
long long a[100005];
struct node {
int h;
long long v1, v2;
node() = default;
node(int _h, long long _v1, long long _v2): h(_h), v1(_v1), v2(_v2) {}
node operator+(const node &b) const {
if (h >= b.h + 2) return *this;
else if (h + 2 <= b.h) return b;
else if (h == b.h + 1) return node(h, v1, v2 + b.v1);
else if (h + 1 == b.h) return node(b.h, b.v1, b.v2 + v1);
else return node(h, v1 + b.v1, v2 + b.v2);
}
};
map<long long, node> mp;
node dp(long long x) {
if (!x) return node(0, 0, 0);
else if (x == 1) return node(1, 1, 0);
else if (mp.count(x)) return mp[x];
else {
node ans = dp((x + 1) / 2 - 1) + dp(x / 2);
if (ans.h == 0) ans.v1++;
else if (ans.h == 1) ans.v2++;
ans.h++;
return mp[x] = ans;
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
node ans(1, 1, 0);
for (int i = 2; i <= n; i++) {
node now = dp(a[i] - a[i - 1] - 1);
if (now.h == 0) now.v1++;
else if (now.h == 1) now.v2++;
now.h++;
// eprintf("%d %lld %lld\n", now.h, now.v1, now.v2);
if (ans.h >= now.h + 2) continue;
else if (ans.h + 1 <= now.h)
ans =
node(now.h, max(ans.v1, ans.v2) + now.v2 - now.v1 / 2 + now.v1, max(ans.v1, ans.v2) + now.v2);
else if (ans.h == now.h + 1) ans = node(ans.h, ans.v1, ans.v2 + now.v1);
else ans = node(ans.h, max(ans.v1, ans.v2) + now.v2 - now.v1 / 2 + now.v1, ans.v2 + now.v2);
}
printf("%lld\n", max(ans.v1, ans.v2));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3892kb
input:
7 7 41 53 58 75 78 81
output:
18
result:
wrong answer 1st lines differ - expected: '22', found: '18'