QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#568920 | #9313. Make Max | yylx | WA | 1ms | 3580kb | C++14 | 1.1kb | 2024-09-16 19:15:18 | 2024-09-16 19:15:18 |
Judging History
answer
#include <iostream>
#include <vector>
using namespace std;
int main() {
int t;
cin >> t; // Number of test cases
while (t--) {
int n;
cin >> n; // Length of the array
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i]; // Array elements
}
int operations = 0;
// We start from the last element and count operations needed to make the array uniform
int max_element = a[n - 1];
int i = n - 2;
while (i >= 0) {
if (a[i] != max_element) {
// Perform one operation
operations++;
// Change all elements before current i to max_element
max_element = a[i];
// Skip to the part where values are different from the current max
while (i >= 0 && a[i] == max_element) {
i--;
}
} else {
i--;
}
}
cout << operations << endl;
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3580kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 1 2
result:
wrong answer 3rd numbers differ - expected: '3', found: '1'