/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 764.0 KiB
#2 Accepted 5ms 532.0 KiB
#3 Accepted 7ms 532.0 KiB
#4 Accepted 8ms 532.0 KiB
#5 Accepted 5ms 532.0 KiB
#6 Accepted 4ms 532.0 KiB
#7 Accepted 8ms 320.0 KiB
#8 Accepted 21ms 532.0 KiB
#9 Accepted 12ms 532.0 KiB
#10 Accepted 72ms 532.0 KiB
#11 Accepted 34ms 552.0 KiB
#12 Accepted 7ms 572.0 KiB
#13 Time Exceeded ≥4096ms ≥532.0 KiB
#14 Time Exceeded ≥4100ms ≥368.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

        int maxBlock = 1;
        for (int len = 2; len <= N; ++len) {
            if (N % len != 0) continue;
            int blockCount = N / len;
            bool possible = false;
            
            // Try all combinations of dividing into blocks of size len
            vector<int> temp = A;
            sort(temp.begin(), temp.end());
            do {
                bool ok = true;
                int diff = -1;
                for (int i = 0; i < N; i += len) {
                    int mx = *max_element(temp.begin() + i, temp.begin() + i + len);
                    int mn = *min_element(temp.begin() + i, temp.begin() + i + len);
                    if (diff == -1)
                        diff = mx - mn;
                    else if (mx - mn != diff) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    possible = true;
                    break;
                }
            } while (next_permutation(temp.begin(), temp.end()));

            if (possible) maxBlock = max(maxBlock, blockCount);
        }
        cout << maxBlock << '\n';
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1162 G. Roy and Maximum Partition
Language
C++17 (G++ 13.2.0)
Submit At
2025-08-03 13:41:35
Judged At
2025-08-03 13:41:35
Judged By
Score
50
Total Time
≥4100ms
Peak Memory
≥764.0 KiB