QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#638061 | #6433. Klee in Solitary Confinement | 333zhan | WA | 69ms | 112588kb | C++20 | 1.6kb | 2024-10-13 14:47:19 | 2024-10-13 14:47:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1E6;
constexpr int inf = 1E9;
void solve () {
int n, k;
cin >> n >> k;
vector <int> a (n + 1);
vector <vector <int>> id2 (N * 2 + 1);
for (int i = 0; i <= N * 2; i ++) {
id2[i].push_back (0);
}
map <int, int> mp;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
a[i] += N;
mp[a[i]] ++;
id2[a[i]].push_back (i);
if (k != 0 && a[i] + k >= 0 && a[i] + k <= 2 * N) {
id2[a[i] + k].push_back (i);
}
}
int ans = 0;
int ttt = 0;
for (auto [x, y] : mp) {
ans = max (ans, y);
}
for (int i = 0; i <= N * 2; i ++) {
if (id2[i].size () == 1) {
continue;
}
const int m = id2[i].size () - 1;
vector <int> c (m + 1);
vector <int> pre (m + 1), suf (m + 2);
for (int j = 1; j <= m; j ++) {
c[j] = c[j - 1] + (a[id2[i][j]] == i ? -1 : 1);
pre[j] = pre[j - 1] + (a[id2[i][j]] == i);
}
vector <int> maxx (m + 2, -inf);
for (int j = m; j >= 1; j --) {
suf[j] = suf[j + 1] + (a[id2[i][j]] == i);
maxx[j] = max (maxx[j + 1], c[j] + suf[j + 1]);
}
for (int j = 1; j <= m; j ++) {
ans = max (ans, maxx[j] - c[j - 1] + pre[j - 1]);
}
}
cout << ans << '\n';
}
signed main () {
ios::sync_with_stdio (false);
cin.tie (nullptr);
int T = 1;
// cin >> T;
while (T --) {
solve ();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 43ms
memory: 112468kb
input:
5 2 2 2 4 4 4
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 66ms
memory: 112544kb
input:
7 1 3 2 3 2 2 2 3
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: 0
Accepted
time: 61ms
memory: 112440kb
input:
7 1 2 3 2 3 2 3 3
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 44ms
memory: 112584kb
input:
9 -100 -1 -2 1 2 -1 -2 1 -2 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: -100
Wrong Answer
time: 69ms
memory: 112588kb
input:
200 121649 0 527189 -1000000 -306471 -998939 527189 -1000000 -1000000 0 527189 0 527189 0 527189 -306471 -998939 -306471 -306471 -306471 0 0 527189 527189 1000000 527189 -1000000 1000000 648838 -1000000 -998939 -998939 -998939 0 1000000 -1000000 -998939 527189 1000000 648838 -1000000 1000000 648838 ...
output:
36
result:
wrong answer 1st numbers differ - expected: '37', found: '36'