QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#297954 | #4629. Longest Increasing Subsequence | defyers# | WA | 1ms | 5740kb | C++17 | 1.4kb | 2024-01-05 14:44:47 | 2024-01-05 14:44:47 |
Judging History
answer
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC targetr("avx2")
using namespace std;
using ll = long long;
using LL = long long;
using pii = pair<int, int>;
LL n;
LL a[100005];
LL dp[100005][65];
LL par[100005][65];
void solve(int TC) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i <= 61; i++) {
dp[1][i] = 1;
par[1][i] = 1;
}
for (int i = 2; i <= n; i++) {
LL gap = a[i] - a[i - 1] - 1;
LL lay = 0;
LL one = 1;
while (gap >= one) {
lay++;
gap -= one;
one *= 2;
}
dp[i][0] = dp[i - 1][0] + 1;
for (int j = 1; j <= 61; j++) {
if (j > lay + 1) {
dp[i][j] = par[i - 1][j];
}
else if (j == lay + 1) {
if (!gap) dp[i][j] = par[i - 1][j];
else {
LL take = max(gap + 1, one / 2 + 1);
dp[i][j] = par[i - 1][j - 1] + take;
dp[i][j] = max(dp[i][j], dp[i - 1][j] + gap);
}
}
else {
dp[i][j] = dp[i - 1][j] + (1 << (j - 1));
}
}
par[i][0] = dp[i][0];
for (int j = 1; j <= 61; j++) {
par[i][j] = max(par[i][j - 1], dp[i][j]);
}
}
LL mx = 0;
for (int i = 0; i <= 61; i++) {
mx = max(mx, dp[n][i]);
}
cout << mx << "\n";
return;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5676kb
input:
7 7 41 53 58 75 78 81
output:
22
result:
ok single line: '22'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5740kb
input:
8 174 223 259 368 618 738 893 1810
output:
671
result:
ok single line: '671'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5704kb
input:
62 145 189 225 631 638 643 880 1349 1399 1574 1655 1713 1714 2383 2496 2706 2787 2904 2985 3030 3050 3318 3461 3466 3500 3908 3945 4287 4379 4412 4579 4612 4630 4722 4781 4811 4858 4998 5098 5276 6181 6185 6412 6427 6464 6498 6548 6887 6917 7344 7532 7776 8347 8711 8928 8983 9269 9486 9517 9833 9855...
output:
2490
result:
wrong answer 1st lines differ - expected: '2506', found: '2490'