QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184937 | #6433. Klee in Solitary Confinement | 2197181078 | WA | 0ms | 3800kb | C++14 | 3.6kb | 2023-09-21 14:29:50 | 2023-09-21 14:29:52 |
Judging History
answer
/**
* @Author KAZE_mae
* @Website https://cloudfall.top/
* @Url
* @DateTime
*/
// #include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using Ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template <typename T>
using pair2 = pair<T, T>;
using PII = pair<int, int>;
using PLI = pair<ll, int>;
using PLL = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
#define endl '\n'
#define debug(x) cout << #x << " = " << (x) << endl
#define abs(a) ((a) >= 0 ? (a) : -(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mem(a, b) memset(a, b, sizeof(a))
// #define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lowbit(x) ((x) & (-x))
const int N = 1000005; // 1e6 + 5
const int INF = 0x3f3f3f3f;
const long long LNF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-7;
const double PI = acos(-1.0);
const int MOD = 998244353;
// #define int long long
long long qmi(long long m, long long k, long long p = 2e18) {
int res = 1 % p, t = m;
while (k) {
if (k&1) res = res * t % p;
t = t * t % p, k >>= 1;
}
return res;
}
inline long long gcd(long long a, long long b) {
return b ? gcd(b, a % b) : a;
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
if (!b) { x = 1; y = 0; return a; }
int d = exgcd(b, a % b, y, x);
y -= (a/b) * x;
return d;
}
void solve() {
int n, k, mx = 0, cnt = 1;
cin>> n >> k;
vector<int> a(n);
map<int, int> mp, sum, ct;
for(int i = 0; i < n; ++ i) {
cin>> a[i];
sum[a[i]] ++;
if(i != 0) if(a[i] == a[i - 1]) ++ cnt;
else {
mp[a[i - 1]] = max(cnt, mp[a[i - 1]]);
cnt = 1;
}
}
mp[a[n - 1]] = max(cnt, mp[a[n - 1]]);
if(k != 0) {
for(auto i : mp) {
mx = max(i.second + sum[i.first + k], mx);
mx = max(sum[i.first], mx);
}
cnt = 1;
for(int i = 0; i < n; ++ i) {
if(i != 0)if(a[i] != a[i - 1]) {
mx = max({mx,
(sum[a[i - 1]] - ct[a[i - 1]] + cnt) + ct[a[i - 1] - k],
ct[a[i - 1]] + (sum[a[i - 1] - k] - ct[a[i - 1] - k])});
// cout<< i << " " << cnt <<endl;
cnt = 1;
}else ++ cnt;
ct[a[i]] ++;
}
mx = max({mx, (sum[a[n - 1]] - ct[a[n - 1]] + cnt) + ct[a[n - 1] - k], ct[a[n - 1]] + (sum[a[n - 1] - k] - ct[a[n - 1] - k])});
}else for(auto i : mp) mx = max(sum[i.first], mx);
cout<< mx <<endl;
}
signed main() {
std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
// int _ = 1; cin>> _; while(_ --)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
5 2 2 2 4 4 4
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
7 1 3 2 3 2 2 2 3
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
7 1 2 3 2 3 2 3 3
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
9 -100 -1 -2 1 2 -1 -2 1 -2 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3800kb
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:
37
result:
ok 1 number(s): "37"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
200 -454379 -385892 454379 -1000000 373644 -665078 -1000000 -1000000 454379 0 1000000 373644 -1000000 1000000 -385892 -1000000 373644 0 -665078 0 -665078 -1000000 -665078 -385892 -665078 -385892 454379 -665078 -385892 -1000000 454379 1000000 -385892 373644 454379 -1000000 -385892 -1000000 -385892 -1...
output:
40
result:
ok 1 number(s): "40"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
200 0 451272 -1000000 677452 677452 0 18908 451272 677452 -233144 677452 451272 18908 -1000000 18908 -1000000 0 451272 0 -233144 677452 1000000 451272 1000000 18908 -1000000 0 -233144 451272 1000000 18908 677452 0 677452 0 677452 1000000 -233144 18908 451272 -1000000 -233144 18908 1000000 0 0 -23314...
output:
35
result:
ok 1 number(s): "35"
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3796kb
input:
200 -705945 -586687 198791 0 198791 0 705945 198791 -1000000 705945 705945 1000000 705945 0 -1000000 699023 0 705945 -586687 -1000000 198791 -1000000 1000000 198791 -1000000 198791 705945 -1000000 1000000 1000000 198791 198791 -1000000 699023 0 0 699023 -586687 705945 -586687 705945 699023 0 705945 ...
output:
33
result:
wrong answer 1st numbers differ - expected: '34', found: '33'