QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#249980 | #6433. Klee in Solitary Confinement | He2717970784 | WA | 15ms | 98916kb | C++17 | 1.2kb | 2023-11-12 19:00:11 | 2023-11-12 19:00:11 |
Judging History
answer
#include<cstdio>
#include<algorithm>
#include<vector>
#include<ctype.h>
#define int long long
using namespace std;
const int N = 1e6 + 9,M = 1e6;
vector<int>a(N * 2, 0), vis(N * 2, 0);
vector<vector<int>>v(2 * N);
int read() {
int ans = 0;
char ch = getchar();
while (!isdigit(ch)) {
ch = getchar();
}
while (isdigit(ch)) {
ans = ans * 10 + ch - '0';
ch = getchar();
}
return ans;
}
int solve() {
int n = read(), k = read();
for (int i = 1; i <= n; i++) {
int x = read();
x += M;
if (!vis[x]) {
vis[x] = 1;
a.push_back(x);
}
v[x].push_back(x);
if (x + k >= 0 && x + k <= 2 * M) {
v[x + k].push_back(x);
}
}
int ans = 0;
for (int num : a) {
if (v[num].empty()) {
continue;
}
int addk = 0, nok = 0, Max = 0, all = 0;
for (int x : v[num]) {
if (x == num) {
all++;
}
}
ans = max(ans, all);
for (int x : v[num]) {
if (x != num) {
addk++;
}
else {
nok++;
}
ans = max(ans, all - nok + addk + Max);
Max = max(Max, nok - addk);
}
}
if (!k) {
ans /= 2;
}
return ans;
}
signed main() {
int ans = solve();
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 98916kb
input:
5 2 2 2 4 4 4
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 13ms
memory: 97820kb
input:
7 1 3 2 3 2 2 2 3
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: 0
Accepted
time: 15ms
memory: 97888kb
input:
7 1 2 3 2 3 2 3 3
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: -100
Wrong Answer
time: 11ms
memory: 98644kb
input:
9 -100 -1 -2 1 2 -1 -2 1 -2 1
output:
5
result:
wrong answer 1st numbers differ - expected: '3', found: '5'