/ SeriousOJ /

Record Detail

Memory Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 2ms 448.0 KiB
#3 Accepted 2ms 328.0 KiB
#4 Accepted 5ms 532.0 KiB
#5 Memory Exceeded ≥1141ms ≥256.016 MiB
#6 Memory Exceeded ≥1159ms ≥256.016 MiB

Code

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

int part(int n) {
    vector<int> dif(n - 1);
    
    for (int i = 0; i < n - 1; ++i) {
        dif[i] = abs((i + 2) - (i + 1));
    }
    
    for (int length = 2; length <= n / 2; ++length) {
        if (n % length != 0) {
            continue;
        }
        
        bool is_possible = true;
        for (int i = 0; i < n - 1; i += length) {
            int max_diff = *max_element(dif.begin() + i, dif.begin() + i + length - 1);
            int min_diff = *min_element(dif.begin() + i, dif.begin() + i + length - 1);
            if (max_diff != min_diff) {
                is_possible = false;
                break;
            }
        }
        if (is_possible) {
            return n / length;
        }
    }
    return 1;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        cout << part(n) << endl;
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1052 Yet Another Array Partition
Contest
Brain Booster #3
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 17:15:00
Judged At
2024-11-11 03:32:24
Judged By
Score
25
Total Time
≥1159ms
Peak Memory
≥256.016 MiB