QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#568920#9313. Make MaxyylxWA 1ms3580kbC++141.1kb2024-09-16 19:15:182024-09-16 19:15:18

Judging History

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

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

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'