/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Wrong Answer 2ms 532.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Wrong Answer 43ms 612.0 KiB

Code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool v(vector<int>& a, int p) {
    int n = a.size();
    int np = n / p;

    for (int i = 0; i < np; ++i) {
        int s = i * p;
        int e = s + p - 1;
        int mi = *min_element(a.begin() + s, a.begin() + e + 1);
        int ma = *max_element(a.begin() + s, a.begin() + e + 1);

        if ((ma - mi) != (a[p - 1] - a[0])) {
            return false;
        }
    }

    return true;
}

int m(vector<int>& a, int n) {
    int l = 2, h = n / 2, ans = 1;

    while (l <= h) {
        int m = l + (h - l) / 2;
        if (v(a, m)) {
            ans = m;
            l = m + 1;
        } else {
            h = m - 1;
        }
    }

    return ans;
}

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;
        }

        int mx = m(a, n);

        cout << mx << 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 15:19:00
Judged At
2024-11-11 03:34:44
Judged By
Score
10
Total Time
43ms
Peak Memory
612.0 KiB