/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Wrong Answer 1ms 532.0 KiB
#3 Accepted 2ms 500.0 KiB
#4 Wrong Answer 2ms 536.0 KiB

Code

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

bool check_partition(int n, int length) {
    if (n % length != 0) {
        return false;
    }
    for (int i = 0; i < n; i += length) {
        int max_element = i + length;
        int min_element = i + 1;
        for (int j = i + 1; j < i + length; ++j) {
            if (max_element < n && max_element < j + 1) {
                max_element = j + 1;
            }
            if (min_element < n && min_element > j + 1) {
                min_element = j + 1;
            }
        }
        if (abs(max_element - min_element) != 1) {
            return false;
        }
    }
    return true;
}

int max_partition(int n) {
    int max_partition = 1;
    for (int length = 2; length <= sqrt(n); ++length) {
        if (check_partition(n, length)) {
            max_partition = n / length;
        }
    }
    return max_partition;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        cout << max_partition(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:24:21
Judged At
2024-11-11 03:32:15
Judged By
Score
10
Total Time
2ms
Peak Memory
536.0 KiB