Submission #906001

# Submission time Handle Problem Language Result Execution time Memory
906001 2024-01-13T09:07:29 Z GrandTiger1729 Teams (CEOI11_tea) C++17
90 / 100
2500 ms 134240 KB
#include <bits/stdc++.h>
using namespace std;

pair<bool, vector<vector<int>>> solve(int t, vector<pair<int, int>> a)
{
    int n = a.size();
    vector<vector<int>> ans;
    ans.emplace_back();
    for (int i = 0; i < a[0].first; i++)
    {
        ans.back().push_back(a[i].second);
    }
    if (ans.back().size() > t)
    {
        return make_pair(false, ans);
    }
    int ll = 0;
    int l = a[0].first;
    for (int i = l; i < n; i++)
    {
        if (i - l >= a[l].first)
        {
            ans.emplace_back();
            while (l < i)
            {
                ans.back().push_back(a[l++].second);
            }
        }
        else if (i + a[i].first < l + a[l].first)
        {
            while (l < i && ll < ans.size())
            {
                while (ll < ans.size() && ans[ll].size() == t)
                {
                    ll++;
                }
                if (ll == ans.size())
                {
                    break;
                }
                ans[ll].push_back(a[l++].second);
            }
        }
    }
    if (l < n && n - l >= a[l].first)
    {
        ans.emplace_back();
        while (l < n)
        {
            ans.back().push_back(a[l++].second);
        }
    }
    else
    {
        while (l < n && ll < ans.size())
        {
            while (ll < ans.size() && ans[ll].size() == t)
            {
                ll++;
            }
            if (ll == ans.size())
            {
                break;
            }
            ans[ll].push_back(a[l++].second);
        }
        if (l < n)
        {
            return make_pair(false, ans);
        }
    }
    return make_pair(true, ans);
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        a[i] = make_pair(x, i);
    }
    sort(a.begin(), a.end(), greater<>());
    int l = 0, r = n;
    int t = solve(n, a).second.size();
    while (l < r - 1)
    {
        int mid = (l + r) / 2;
        auto res = solve(mid, a);
        (res.first && res.second.size() == t ? r : l) = mid;
    }
    auto ans = solve(r, a).second;
    cout << ans.size() << '\n';
    for (auto &res : ans)
    {
        cout << res.size() << ' ';
        for (int &i : res)
        {
            cout << i + 1 << ' ';
        }
        cout << '\n';
    }
    return 0;
}

Compilation message

tea.cpp: In function 'std::pair<bool, std::vector<std::vector<int> > > solve(int, std::vector<std::pair<int, int> >)':
tea.cpp:13:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   13 |     if (ans.back().size() > t)
      |         ~~~~~~~~~~~~~~~~~~^~~
tea.cpp:31:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |             while (l < i && ll < ans.size())
      |                             ~~~^~~~~~~~~~~~
tea.cpp:33:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |                 while (ll < ans.size() && ans[ll].size() == t)
      |                        ~~~^~~~~~~~~~~~
tea.cpp:33:58: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |                 while (ll < ans.size() && ans[ll].size() == t)
      |                                           ~~~~~~~~~~~~~~~^~~~
tea.cpp:37:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |                 if (ll == ans.size())
      |                     ~~~^~~~~~~~~~~~~
tea.cpp:55:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         while (l < n && ll < ans.size())
      |                         ~~~^~~~~~~~~~~~
tea.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             while (ll < ans.size() && ans[ll].size() == t)
      |                    ~~~^~~~~~~~~~~~
tea.cpp:57:54: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |             while (ll < ans.size() && ans[ll].size() == t)
      |                                       ~~~~~~~~~~~~~~~^~~~
tea.cpp:61:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             if (ll == ans.size())
      |                 ~~~^~~~~~~~~~~~~
tea.cpp: In function 'int main()':
tea.cpp:94:41: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   94 |         (res.first && res.second.size() == t ? r : l) = mid;
      |                       ~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 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
3 Correct 3 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 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2828 KB Output is correct
2 Correct 23 ms 3120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3156 KB Output is correct
2 Correct 29 ms 3232 KB Output is correct
3 Correct 30 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 261 ms 23476 KB Output is correct
2 Correct 286 ms 28592 KB Output is correct
3 Correct 259 ms 27944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 335 ms 30988 KB Output is correct
2 Execution timed out 2512 ms 134240 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 374 ms 31176 KB Output is correct
2 Correct 318 ms 39260 KB Output is correct
3 Correct 405 ms 35524 KB Output is correct
4 Correct 350 ms 38256 KB Output is correct