# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
530174 | Lawliet | Teams (CEOI11_tea) | C++17 | 256 ms | 104516 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>
using namespace std;
const int MAXN = 1000010;
const int INF = 1000000010;
int n;
int v[MAXN];
int ord[MAXN];
int maxSize[MAXN];
int dp[MAXN], opt[MAXN];
vector<int> indValues[MAXN];
vector<int> transitions[MAXN];
int main()
{
scanf("%d",&n);
for(int i = 1 ; i <= n ; i++)
{
scanf("%d",&v[i]);
indValues[ v[i] ].push_back( i );
}
int cnt = 0;
for(int i = n ; i > 0 ; i--)
while( !indValues[i].empty() )
ord[++cnt] = indValues[i].back(), indValues[i].pop_back();
for(int i = 1 ; i < v[ ord[1] ] ; i++)
dp[i] = -INF;
dp[ v[ ord[1] ] ] = 1;
opt[ v[ ord[1] ] ] = 1;
maxSize[ v[ ord[1] ] ] = v[ ord[1] ];
transitions[ v[ ord[1] ] ].push_back( v[ ord[1] ] );
for(int i = v[ ord[1] ] + 1 ; i <= n ; i++)
{
dp[i] = dp[i - 1];
opt[i] = opt[i - 1];
maxSize[i] = maxSize[i - 1];
if( (i - 1)%maxSize[i - 1] == 0 && (i - 1)/maxSize[i - 1] == dp[i - 1] )
maxSize[i]++;
if( v[ ord[i] ] + i - 1 <= n )
transitions[ v[ ord[i] ] + i - 1 ].push_back( i );
for(int j = 0 ; j < (int)transitions[i].size() ; j++)
{
int last = transitions[i][j];
int newSize = max( maxSize[last - 1] , i - last + 1 );
if( dp[i] < dp[last - 1] + 1 )
dp[i] = dp[last - 1] + 1, maxSize[i] = newSize, opt[i] = last;
else if( dp[i] == dp[last - 1] + 1 && maxSize[i] > newSize )
maxSize[i] = newSize, opt[i] = last;
}
}
printf("%d\n",dp[n]);
int last = n;
for(int i = 1 ; i <= dp[n] ; i++, last = opt[last] - 1)
{
printf("%d ",last - opt[last] + 1);
for(int j = opt[last] ; j <= last ; j++)
printf("%d ",ord[j]);
printf("\n");
}
}
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... |