QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#568924#9313. Make MaxyylxWA 0ms3572kbC++141.2kb2024-09-16 19:17:402024-09-16 19:17:41

Judging History

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

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

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;
        int last_pos = n - 1;

        // Start from the last element and try to create the largest uniform subarray
        while (last_pos > 0) {
            int current = last_pos;
            // Find the largest uniform subarray starting from the last element
            while (current > 0 && a[current - 1] == a[last_pos]) {
                current--;
            }

            // If the current subarray isn't the entire array, we can perform an operation
            if (current > 0) {
                operations++;
                // Double the size of the uniform subarray by considering the previous non-uniform part
                last_pos = current - 1;
            } else {
                // If we have reached the beginning of the array, break
                break;
            }
        }

        cout << operations << endl;
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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'