QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#695389 | #6443. Windblume Festival | nageing | WA | 0ms | 3676kb | C++20 | 1.6kb | 2024-10-31 19:56:31 | 2024-10-31 19:56:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int N = 2E5 + 10, mod = 1E9 + 7;
bool chmax(int &a, int b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
bool chmin(int &a, int b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
void printv(vector<int> a) {
for (int i : a) {
cout << i << ' ';
}
cout << '\n';
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
vector<vector<int>> b;
unordered_map<int, int> mp, cnt;
int m = 0;
int ans = 1;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
if (mp.count(a[i])) {
b[mp[a[i]]].push_back(1);
if (!mp.count(a[i] - k)) {
mp[a[i] - k] = m ++;
b.push_back({-1});
} else {
b[mp[a[i] - k]].push_back(-1);
}
} else {
mp[a[i]] = m ++;
b.push_back({1});
if (!mp.count(a[i] - k)) {
mp[a[i] - k] = m ++;
b.push_back({-1});
} else {
b[mp[a[i] - k]].push_back(-1);
}
}
cnt[a[i]] ++;
chmax(ans, cnt[a[i]]);
}
if (k == 0) {
cout << ans << '\n';
return;
}
for (int i = 0; i < m; i ++) {
int q = b[i].size();
vector<int> s(q + 1);
int sum = 0;
for (int j = 0; j < q; j ++) {
s[j + 1] = s[j] + b[i][j];
if (b[i][j] == -1) sum ++;
}
int Min = 0;
for (int i = 1; i <= q; i ++) {
chmax(ans, sum + s[i] - Min);
chmin(Min, s[i]);
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
//cin >> t;
while (t --) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3676kb
input:
5 4 1 -3 2 -4 11 91 66 73 71 32 83 72 79 84 33 93 12 91 66 73 71 32 83 72 79 84 33 33 93 13 91 66 73 71 32 83 72 79 84 33 33 33 93 1 0
output:
2
result:
wrong answer 1st numbers differ - expected: '10', found: '2'