Submission #982656

# Submission time Handle Problem Language Result Execution time Memory
982656 2024-05-14T15:17:50 Z vjudge1 Teams (CEOI11_tea) C++17
100 / 100
531 ms 106120 KB
#include <bits/stdc++.h>
using namespace std;
const int N=200005;
int main() {
    int n;
    cin >> n;
    vector<int> a[n + 1];
    vector<int> v(n + 1);
    for(int i = 1;i <= n; i++){
        cin >> v[i];
        a[v[i]].push_back(i);
    }
    sort(v.begin(), v.end());
    vector<int> dp(n + 1,-N);
    vector<int> mx(n + 1);
    function<int(int)> check = [&](int lim){
        dp.assign(n + 1,-N);
        dp[0] = 0;
        for(int i = 1;i <= n; i++){
            if(i >= v[i] && i - mx[i - v[i]] <= lim) dp[i] = dp[mx[i - v[i]]] + 1;
            mx[i] = (dp[mx[i - 1]] > dp[i] ? mx[i - 1] : i);
        }
        return dp[n];
    };
    int mx1 = check(n);
    int l = 0,r = n;
    while(r - l > 1){
        int mid = l + r >>1;
        if(check(mid) == mx1){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    check(r);
    vector<vector<int>> ans;
    int p = n;
    while(p > 0){
        ans.push_back(vector<int>());
        int t = mx[p - v[p]];
        while(p > t){
            ans.back().push_back(a[v[p]].back());
            a[v[p]].pop_back();
            p--;
        }
    }
    cout << mx1 << "\n";
    for(auto &i : ans){
        cout << i.size() << ' ';
        for(int j:i){
            cout << j << ' ';
        }
        cout << "\n";
    }
    return 0;
}

Compilation message

tea.cpp: In function 'int main()':
tea.cpp:28:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |         int mid = l + r >>1;
      |                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 4944 KB Output is correct
2 Correct 33 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 5464 KB Output is correct
2 Correct 27 ms 4820 KB Output is correct
3 Correct 37 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 326 ms 43752 KB Output is correct
2 Correct 268 ms 42572 KB Output is correct
3 Correct 339 ms 43872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 449 ms 58244 KB Output is correct
2 Correct 453 ms 106120 KB Output is correct
3 Correct 362 ms 56688 KB Output is correct
4 Correct 425 ms 52136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 467 ms 59204 KB Output is correct
2 Correct 455 ms 58300 KB Output is correct
3 Correct 385 ms 56136 KB Output is correct
4 Correct 531 ms 59868 KB Output is correct