Submission #1330299

#TimeUsernameProblemLanguageResultExecution timeMemory
1330299bradley0927Just Long Neckties 2 (JOI25_ho_t4)C++20
0 / 100
0 ms344 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool check(int k, int n, const vector<int>& A) {
    // ties[len] = how many models have a tie of length 'len'
    vector<int> ties(22, 0);
    ties[1] = k;
    
    bool prev_ignored = false;

    for (int i = 0; i < n; ++i) {
        int x = A[i];
        int best_len = -1;
        
        // Find the largest tie length <= x
        for (int l = x; l >= 1; --l) {
            if (ties[l] > 0) {
                best_len = l;
                break;
            }
        }

        if (best_len != -1) {
            // We can respond, so we do (Greedy)
            ties[best_len]--;
            ties[x]++;
            prev_ignored = false;
        } else {
            // Must ignore
            if (prev_ignored) return false; // Failed: ignored two in a row
            prev_ignored = true;
        }
    }
    return true;
}

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

    int n;
    if (!(cin >> n)) return 0;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) cin >> A[i];

    int low = 1, high = n, ans = n;
    while (low <= high) {
        int mid = low + (high - low) / 2;
        if (check(mid, n, A)) {
            ans = mid;
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...