/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 320.0 KiB
#2 Wrong Answer 2ms 492.0 KiB

Code

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

bool check(vector<int>& A, int start, int diff) {
    int minVal = A[start], maxVal = A[start];
    for (int i = start; i < A.size(); i += diff) {
        minVal = min(minVal, A[i]);
        maxVal = max(maxVal, A[i]);
        if (maxVal - minVal != diff) {
            return false;
        }
    }
    return true;
}

int maxPartitions(vector<int>& A) {
    int n = A.size();
    int maxPartitions = 1;

    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            int diff = n / i;
            if (check(A, 0, diff)) {
                maxPartitions = max(maxPartitions, i);
            }
        }
    }

    return maxPartitions;
}

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

    while (T--) {
        int N;
        cin >> N;

        vector<int> A(N);
        for (int i = 0; i < N; i++) {
            A[i] = i + 1;
        }

        cout << maxPartitions(A) << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1052 Yet Another Array Partition
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-07 02:37:27
Judged At
2024-11-11 03:31:11
Judged By
Score
0
Total Time
2ms
Peak Memory
492.0 KiB