Submission #1171193

#TimeUsernameProblemLanguageResultExecution timeMemory
1171193FZ_LaabidiBouquet (EGOI24_bouquet)C++20
0 / 100
3097 ms2624 KiB
#include <bits/stdc++.h>
using namespace std;
vector<int> make_sorted_index(vector<pair<int, int>> const& values) {
    vector<int> index(values.size());
    iota(index.begin(), index.end(), 0);
    stable_sort(index.begin(), index.end(), [&values](int a, int b) { return values[a].first < values[b].first; } );
    return index;
}
int main() {
    int n; cin >> n;
    vector<pair<int, int>> flowers(n+1, {INT_MAX, INT_MAX});
    vector<int> dp(n, 0);
    set<pair<int, int>> vi;
    bool flag =true;
    int v=0;
    for(int i = 0; i < n; i++){
        cin >> flowers[i].first >> flowers[i].second;
        if (flowers[i].second!=0)flag = false;
        vi.insert(flowers[i]);
        v = max(max(flowers[i].first, flowers[i].second), v);
    }
    pair<int, int> vo = *vi.begin();
    if (vi.size()==1 && vo.first==vo.second) {
        int c=0, i=0;
        while (i<n) {
            c++;
            i+=flowers[i].second;
        }
        cout << c << endl;
    }
    else if (n<=1000) {
        for (int i=0; i<n; i++) {
            for (int j=n-1; j>i; j--) {
                if (j-max(flowers[j].first, flowers[i].second)>i) {
                    dp[i]= max(dp[i], dp[j]+1);
                }
            }
            for (int j=0; j<i; j++) {
                if (j+max(flowers[j].second, flowers[i].first)<i) {
                    dp[i]= max(dp[i], dp[j]+1);
                }
            }
        }

        cout << max(1, *max_element(dp.begin(), dp.end()))<< endl;
    }
    else if (flag) {
        vector<int> pref(n+1, 0);
        for (int i=0; i<n; i++) {
            if (i>flowers[i].first)dp[i]= max(dp[i], pref[i-flowers[i].first]+1);
            pref[i+1]= max(pref[i], dp[i]);
        }
        cout << max(1, *max_element(dp.begin(), dp.end()))<< endl;
    }
    else {
        for (int i=0; i<n; i++) {
            for (int j=max(0,i-5); j<i; j++) {
                if (j+max(flowers[j].second, flowers[i].first)<i) {
                    dp[i]= max(dp[i], dp[j]+1);
                }
            }
        }
        cout <<max(1, *max_element(dp.begin(), dp.end()))<< endl;
    }
}
#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...