QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743792 | #5035. foo~ | zfs732 | 0 | 103ms | 7576kb | C++23 | 2.4kb | 2024-11-13 20:02:24 | 2024-11-13 20:02:25 |
Judging History
answer
/*
* _|_|_|_|_| _|_|_|_| _|_|_| _|_|_|_|_| _|_|_| _|_|
* _| _| _| _| _| _| _|
* _| _|_|_| _|_| _| _|_| _|
* _| _| _| _| _| _|
* _|_|_|_|_| _| _|_|_| _| _|_|_| _|_|_|_|
*/
#include <bits/stdc++.h>
constexpr int INF = 1E7;
namespace Solution {
int Solve(int K, const std::vector<int> &arr) {
for (auto v: arr) { std::cerr << v << ' '; }
std::cerr << '\n';
int N = (int) arr.size(), ans = 0;
std::vector dp(K + 1, std::vector(N, -INF));
std::vector pre(K + 1, std::vector(N, -INF));
std::vector suf(K + 1, std::vector(N, -INF));
std::vector smx(K + 1, std::vector(N, -INF));
dp[0][0] = 0;
std::stack<int> sta;
sta.emplace(0);
for (int i = 1; i < N; i++) {
for (int j = 1; j <= K; j++) {
smx[j][i] = dp[j - 1][i - 1] + 1;
pre[j][i] = dp[j - 1][i - 1] + 1;
suf[j][i] = dp[j - 1][i - 1] + 1;
}
while (!sta.empty() && arr[i] > arr[sta.top()]) {
int p = sta.top();
for (int j = 1; j <= K; j++) {
smx[j][i] = std::max(smx[j][i], smx[j][p]);
pre[j][i] = std::max(pre[j][i], pre[j][p] + 1);
}
sta.pop();
}
int p = sta.top();
for (int j = 1; j <= K; j++) {
suf[j][i] = std::max(suf[j][i], suf[j][p] + 1);
pre[j][i] = std::max(pre[j][i], pre[j][p]);
}
sta.emplace(i);
for (int j = 1; j <= K; j++) {
dp[j][i] = std::max({smx[j][i], suf[j][i], pre[j][i]});
}
}
for (int i = 1; i <= N; i++) { ans = std::max(ans, dp[K][i]); }
return ans;
}
}// namespace Solution
int main() {
#ifdef LOCAL
freopen("task.in", "r", stdin);
freopen("task.out", "w", stdout);
freopen("task.err", "w", stderr);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, K, pos = -1;
std::cin >> N >> K;
std::vector<int> arr(N), tmp(N);
for (int i = 0; i < N; i++) {
std::cin >> arr[i];
if (arr[i] == N) { pos = i; }
}
for (int i = 0; i < N; i++) { tmp[i] = arr[(i + pos) % N]; }
int ans = Solution::Solve(K, tmp);
std::reverse(tmp.begin() + 1, tmp.end());
ans = std::max(ans, Solution::Solve(K, tmp));
std::cout << ans + 1 << '\n';
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 1ms
memory: 3548kb
input:
23 6 16 20 22 4 21 10 3 7 5 8 15 12 9 1 6 17 23 13 11 19 18 14 2
output:
20
result:
ok "20"
Test #2:
score: 10
Accepted
time: 1ms
memory: 3520kb
input:
13 6 13 9 3 4 12 6 5 1 8 10 11 7 2
output:
13
result:
ok "13"
Test #3:
score: 0
Wrong Answer
time: 1ms
memory: 3548kb
input:
25 3 25 2 3 19 5 6 7 11 8 10 9 20 4 14 21 1 17 12 13 18 15 22 23 16 24
output:
19
result:
wrong answer 1st words differ - expected: '16', found: '19'
Subtask #2:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 103ms
memory: 7576kb
input:
93943 1 87243 48984 50611 19218 77699 25025 85769 28141 13380 34875 42459 66419 53472 4367 48292 16894 92171 87263 42527 67085 30687 29235 27515 81053 31421 34864 83591 70491 75344 7026 50250 63402 26773 5330 36308 76399 80032 15501 16205 71750 73964 67876 68901 70548 2043 79979 89479 19784 38838 44...
output:
46982
result:
wrong answer 1st words differ - expected: '25', found: '46982'
Subtask #3:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 7ms
memory: 4252kb
input:
1992 25 144 612 1315 1966 1779 1773 1529 625 36 1849 1783 1441 1388 1558 1258 724 137 397 542 353 1162 1213 406 792 1317 882 994 298 1864 1969 103 449 508 1501 89 1721 195 778 657 222 1152 1780 613 743 1206 694 829 142 69 1973 1465 1343 655 1540 155 146 350 491 759 1695 1082 1357 1329 1745 232 1850 ...
output:
7985
result:
wrong answer 1st words differ - expected: '237', found: '7985'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%