QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#773806#9787. Shrek's Song of the Swampucup-team2112#WA 0ms3664kbC++201.0kb2024-11-23 10:23:582024-11-23 10:24:00

Judging History

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

  • [2024-11-23 10:24:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3664kb
  • [2024-11-23 10:23:58]
  • 提交

answer

#include <bits/stdc++.h>

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int n;
    std::cin >> n;
    std::vector<int> a(n), nxt(n, n + 1);
    for (int &x : a) std::cin >> x;
    std::map<int, int> mp;
    for (int i = n - 1; i >= 0; i -= 1) {
        int x = a[i];
        if (mp.contains(x)) {
            nxt[i] = mp[x];
        }
        mp[x] = i;
    }
    int res = 0;
    int last = int(1e9) + 10;
    std::pair<int, int> mn = {1e9, 1e9};
    for (int i = 0; i < n; i += 1) {
        int x = a[i];
        if (x == last) {
            res += 1;
            continue;
        }
        mn = std::min(mn, {nxt[i], i});
        if (mn.first == i) {
            int cnt = 0;
            for (int j = mn.second + 1; j < mn.first; j += 1) {
                cnt += a[j] == last;
            }
            res = std::max(res - cnt + 2, res);
            mn = {1e9, 1e9};
            continue;
        }
    }
    std::cout << res << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3664kb

input:

9
1 2 3 1 3 1 2 3 2

output:

4

result:

wrong answer 1st numbers differ - expected: '5', found: '4'