QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687749#6433. Klee in Solitary ConfinementLightFeatherWA 8ms5868kbC++202.5kb2024-10-29 21:00:022024-10-29 21:00:03

Judging History

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

  • [2024-10-29 21:00:03]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:5868kb
  • [2024-10-29 21:00:02]
  • 提交

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 = {3 * N + 1, 0};
            for(auto it : v[a[i] + k]){
                if(t.first == 3 * 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;
                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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 5668kb

input:

5 2
2 2 4 4 4

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 8ms
memory: 5612kb

input:

7 1
3 2 3 2 2 2 3

output:

6

result:

ok 1 number(s): "6"

Test #3:

score: 0
Accepted
time: 8ms
memory: 5868kb

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: 5616kb

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: 8ms
memory: 5696kb

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'