QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#568607#9313. Make MaxEOCWA 0ms3508kbC++141.2kb2024-09-16 17:21:442024-09-16 17:21:45

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 17:21:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3508kb
  • [2024-09-16 17:21:44]
  • 提交

answer

#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

// Function to calculate maximum number of operations
int maxOperations(vector<int>& nums) {
    // Map to store the latest position of each number
    unordered_map<int, int> lastPos;
    int ops = 0; // Maximum number of operations
    int lastOpPos = 0; // Position of the last operation

    for (int i = 0; i < nums.size(); ++i) {
        // If the number was seen before and its last position is greater than
        // the last operation position, we can perform an operation
        if (lastPos.count(nums[i]) && lastPos[nums[i]] > lastOpPos) {
            ops++;
            // Update the position of the last operation
            lastOpPos = i;
        }
        // Update the latest position of the current number
        lastPos[nums[i]] = i;
    }

    return ops;
}

int main() {
    int t; // Number of test cases
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> nums(n);
        for (int i = 0; i < n; ++i) {
            cin >> nums[i];
        }
        cout << maxOperations(nums) << '\n';
    }
    return 0;
}

详细

Test #1:

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

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

0
0
3
0

result:

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