QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#568607 | #9313. Make Max | EOC | WA | 0ms | 3508kb | C++14 | 1.2kb | 2024-09-16 17:21:44 | 2024-09-16 17:21:45 |
Judging History
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'