/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 532.0 KiB
#2 Wrong Answer 1ms 532.0 KiB

Code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

// Function to check if it's possible to divide the array into 'block_count' blocks
// where the difference between the maximum and minimum element in each block is the same
bool isValidBlockDivision(const vector<int>& arr, int N, int block_size) {
    // We need to divide the array into `block_count` blocks
    int block_count = N / block_size;
    
    // Traverse through the array in blocks of size 'block_size'
    for (int i = 0; i < block_count; ++i) {
        int start = i * block_size;
        int end = start + block_size - 1;
        
        // Find the minimum and maximum element in the current block
        int min_elem = arr[start];
        int max_elem = arr[start];
        for (int j = start + 1; j <= end; ++j) {
            min_elem = min(min_elem, arr[j]);
            max_elem = max(max_elem, arr[j]);
        }
        
        // Check if the difference between max and min is the same for all blocks
        if (max_elem - min_elem != arr[end] - arr[start]) {
            return false;
        }
    }
    
    return true;
}

int main() {
    int T;
    cin >> T;

    while (T--) {
        int N;
        cin >> N;
        vector<int> arr(N);
        
        for (int i = 0; i < N; ++i) {
            cin >> arr[i];
        }

        // Sort the array first to simplify checking the block condition
        sort(arr.begin(), arr.end());
        
        int max_blocks = 0;

        // Try all possible block sizes that divide N
        for (int block_size = 2; block_size <= N; ++block_size) {
            if (N % block_size == 0) {
                if (isValidBlockDivision(arr, N, block_size)) {
                    max_blocks = max(max_blocks, N / block_size);
                }
            }
        }

        // Output the maximum number of blocks
        cout << max_blocks << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1162 Roy and Maximum Partition
Contest
Brain Booster #8
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 15:06:45
Judged At
2025-02-17 15:06:45
Judged By
Score
0
Total Time
1ms
Peak Memory
532.0 KiB