Submission #906002

# Submission time Handle Problem Language Result Execution time Memory
906002 2024-01-13T09:08:42 Z GrandTiger1729 Teams (CEOI11_tea) C++17
100 / 100
2359 ms 127816 KB
#include <bits/stdc++.h>
using namespace std;

inline pair<bool, vector<vector<int>>> solve(int t, const 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, const 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 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 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 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2216 KB Output is correct
2 Correct 22 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 2468 KB Output is correct
2 Correct 31 ms 2484 KB Output is correct
3 Correct 25 ms 2416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 228 ms 17636 KB Output is correct
2 Correct 261 ms 20380 KB Output is correct
3 Correct 217 ms 17684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 23220 KB Output is correct
2 Correct 2359 ms 127816 KB Output is correct
3 Correct 347 ms 29376 KB Output is correct
4 Correct 279 ms 26316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 306 ms 23112 KB Output is correct
2 Correct 247 ms 23200 KB Output is correct
3 Correct 368 ms 23980 KB Output is correct
4 Correct 288 ms 24772 KB Output is correct