QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687807 | #6433. Klee in Solitary Confinement | LightFeather | WA | 8ms | 5840kb | C++20 | 2.6kb | 2024-10-29 21:22:46 | 2024-10-29 21:22:47 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
constexpr int N = 1e6 + 10;
int n, k;
int a[N];
vector<int> v[4 * N];
vector<PII> p[4 * N];
unordered_map<int, int> mp;
void solve(){
int ans = 1;
cin >> n >> k;
for(int i = 1; i <= n; i ++){
cin >> a[i];
a[i] += N;
mp[a[i]] ++;
}
for(auto it : mp)
ans = max(ans, it.second);
for(int i = 1; i <= n; i ++){
v[a[i]].push_back(a[i]);
v[a[i] + k].push_back(a[i]);
}
for(int i = 1; i <= n; i ++){
if(p[a[i] + k].empty()){
PII t = {10 * N + 1, 0};
for(auto it : v[a[i] + k]){
if(t.first == 10 * N + 1){
t.first = it;
t.second = 1;
continue;
}
if(it == t.first)
t.second ++;
else{
p[a[i] + k].push_back(t);
t = {it, 1};
}
}
p[a[i] + k].push_back(t);
}
}
// for(int i = 1; i <= n; i ++){
// cout << a[i] + k << endl;
// for(int j = 0; j < p[a[i] + k].size(); j ++){
// auto t = p[a[i] + k][j];
// cout << t.first << " " << t.second << endl;
// }
// }
for(int i = 1; i <= n; i ++){
int cnt = 0, tmp = 0;
bool flag = false;
for(int j = 0; j < p[a[i] + k].size(); j ++){
auto t = p[a[i] + k][j];
if(!flag && t.first == a[i] + k){
continue;
}
if(t.first != a[i] + k){
flag = true;
cnt += t.second;
tmp = max(tmp, cnt);
continue;
}
if(j + 1 >= p[a[i] + k].size())
break;
if(p[a[i] + k][j + 1].second - p[a[i] + k][j].second >= 0){
cnt += p[a[i] + k][j + 1].second - p[a[i] + k][j].second;
cnt = max(cnt, p[a[i] + k][j + 1].second);
tmp = max(tmp, cnt);
}
else{
cnt = p[a[i] + k][j + 1].second;
tmp = max(tmp, cnt);
}
j ++;
}
p[a[i] + k].clear();
ans = max(ans, mp[a[i] + k] + tmp);
}
cout << ans << endl;
}
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: 8ms
memory: 5616kb
input:
5 2 2 2 4 4 4
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 7ms
memory: 5680kb
input:
7 1 3 2 3 2 2 2 3
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: 0
Accepted
time: 7ms
memory: 5684kb
input:
7 1 2 3 2 3 2 3 3
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 8ms
memory: 5840kb
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: 7ms
memory: 5756kb
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'