/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 31ms 19.461 MiB
#2 Wrong Answer 35ms 21.293 MiB
#3 Wrong Answer 37ms 21.352 MiB

Code

def max_blocks(T, test_cases):
    results = []
    for case in test_cases:
        N, A = case
        A_sorted = sorted(A)
        max_blocks_found = 1  # At least one block (the entire array)

        # Iterate over possible block sizes
        for k in range(2, N + 1):
            if N % k != 0:
                continue  # Block size must divide N
            num_blocks = N // k
            valid = True
            target_diff = None

            # Check each block
            for i in range(num_blocks):
                start = i * k
                end = start + k
                block = A_sorted[start:end]
                current_diff = block[-1] - block[0]

                if target_diff is None:
                    target_diff = current_diff
                elif current_diff != target_diff:
                    valid = False
                    break

            if valid:
                max_blocks_found = max(max_blocks_found, num_blocks)

        results.append(max_blocks_found)
    return results


# Input reading
T = int(input())
test_cases = []
for _ in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    test_cases.append((N, A))

# Compute results
results = max_blocks(T, test_cases)

# Output results
for res in results:
    print(res)

Information

Submit By
Type
Submission
Problem
P1162 Roy and Maximum Partition
Language
PyPy 3 (Python 3.9.18 PyPy 7.3.15)
Submit At
2025-01-28 11:50:04
Judged At
2025-01-28 11:50:04
Judged By
Score
0
Total Time
37ms
Peak Memory
21.352 MiB