Submission #906002

#TimeUsernameProblemLanguageResultExecution timeMemory
906002GrandTiger1729Teams (CEOI11_tea)C++17
100 / 100
2359 ms127816 KiB
#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 (stderr)

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 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...