QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#249980#6433. Klee in Solitary ConfinementHe2717970784WA 15ms98916kbC++171.2kb2023-11-12 19:00:112023-11-12 19:00:11

Judging History

你现在查看的是最新测评结果

  • [2023-11-12 19:00:11]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:98916kb
  • [2023-11-12 19:00:11]
  • 提交

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;
}

详细

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'