QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684655 | #6433. Klee in Solitary Confinement | ssx | WA | 3ms | 5728kb | C++20 | 1.9kb | 2024-10-28 15:04:04 | 2024-10-28 15:04:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
const int N = 3e6 + 50;
const int mod = 998244353;
ll a[N], res, ans = 0, n, k, st[N];
vector<ll> e[N];
vector<ll> v;
void solve()
{
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
a[i] += 1e6;
e[a[i]].push_back(i);
if (st[a[i]] == 0)
{
st[a[i]] = 1;
v.push_back(a[i]);
}
}
for (auto it : v) ans = max(ans, (ll)e[it].size());
if (k == 0)
{
cout << ans;
return ;
}
ll p1, p2 = 0, cnt2 = 0, mn = 1e18;
for (auto it : v)
{
p2 = 0, cnt2 = 0, mn = 1e18;
if (it + k < 0) continue;
if (st[it + k] == 0) continue;
for (int i = 0; i < e[it].size(); i++)
{
p1 = e[it][i];
p1 --;
if (cnt2 < e[it + k].size())
{
while (p2 < e[it + k].size() && p1 >= e[it + k][p2])
{
cnt2 ++; p2 ++;
}
}
mn = min(mn, i - 2 * cnt2);
p1 ++;
if (cnt2 < e[it + k].size())
{
while (p2 < e[it + k].size() && p1 >= e[it + k][p2])
{
cnt2 ++; p2 ++;
}
}
res = i + 1 - 2 * cnt2;
//cout << res - mn << '\n';
ans = max(ans, (ll)(res - mn + e[it + k].size()));
}
}
cout << ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
//freopen("C:/Users/fb03C/Desktop/cpp/code0/in.txt", "r", stdin);
//freopen("C:/Users/fb03C/Desktop/cpp/code0/output/std.txt", "w", stdout);
ll T = 1;
//cin >> T;
while (T --)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 5636kb
input:
5 2 2 2 4 4 4
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 3ms
memory: 5676kb
input:
7 1 3 2 3 2 2 2 3
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: 0
Accepted
time: 3ms
memory: 5620kb
input:
7 1 2 3 2 3 2 3 3
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 3ms
memory: 5684kb
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: 3ms
memory: 5728kb
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'