# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1111675 | khoaha123 | Teams (CEOI11_tea) | C++17 | 392 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define endl '\n'
#define ii pair<int,int>
#define task "DIVTEAM"
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;
const int dx[2] = {1,0};
const int dy[2] = {0,1};
int n,a[N];
vector<int> b[N];
vector<vector<int>> ans;
int dp[N],pos[N];
int check(int T){
dp[0] = 0;
for (int i = 1; i <= n; ++i){
if (i >= a[i] && i - pos[i - a[i]] <= T) dp[i] = dp[pos[i - a[i]]] + 1;
pos[i] = (dp[pos[i-1]] > dp[i] ? pos[i-1] : i);
}
return dp[n];
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
freopen(task".OUT","w",stdout);
}
cin >> n;
for (int i = 1; i <= n; ++i){
cin >> a[i];
b[a[i]].push_back(i);
}
sort(a+1,a+1+n);
int result = check(n);
int l = 0,r = n;
while (r - l > 1){
int mid = (l + r) >> 1;
if (check(mid) == result) r = mid;
else l = mid;
}
check(r);
int u = n;
while (u){
int t = pos[u -a[u]];
vector<int> x;
while (u > t){
x.push_back(b[a[u]].back());
b[a[u]].pop_back();
u--;
}
ans.push_back(x);
}
cout << ans.size() << endl;
for (auto f : ans){
cout << f.size() << ' ';
for (auto g : f) cout << g << ' ';
cout << endl;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |