# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
813197 |
2023-08-07T14:12:56 Z |
mrwang |
Teams (CEOI11_tea) |
C++14 |
|
428 ms |
106052 KB |
#include<bits/stdc++.h>
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=1e6+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll dp[maxN];
ll id[maxN],n;
pli b[maxN];
ll a[maxN],par[maxN];
ll get(ll l,bool p)
{
dp[0]=0;
id[0]=0;
for(int i=1;i<=n;i++)
{
dp[i]=-inf;
ll L=i-l;
ll R=i-b[i].fi;
if(R>=0&&id[R]>=L)
{
dp[i]=dp[id[R]]+1;
par[i]=id[R];
}
id[i]=id[i-1];
if(dp[i]>=dp[id[i]]) id[i]=i;
}
if(p)
{
vector<vector<ll>>ans;
ll x=n;
while(x!=0)
{
vector<ll>vd;
vd.pb(x-par[x]);
for(int i=par[x]+1;i<=x;i++)
{
vd.pb(b[i].se);
}
ans.pb(vd);
x=par[x];
}
for(auto zz:ans)
{
for(auto xx:zz)
{
cout << xx<<' ';
}
cout << '\n';
}
}
return dp[n];
}
void solve()
{
cin >> n;
for(int i=1;i<=n;i++) cin >> a[i],b[i]={a[i],i};
sort(b+1,b+n+1);
ll low=0,high=n;
ll x=get(n,0);
while(low<=high)
{
ll mid=low+high>>1;
if(get(mid,0)==x) high=mid-1;
else low=mid+1;
}
cout << x<<'\n';
get(low,1);
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message
tea.cpp: In function 'void solve()':
tea.cpp:69:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
69 | ll mid=low+high>>1;
| ~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
660 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
5180 KB |
Output is correct |
2 |
Correct |
22 ms |
4848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
5664 KB |
Output is correct |
2 |
Correct |
25 ms |
4736 KB |
Output is correct |
3 |
Correct |
29 ms |
5604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
44340 KB |
Output is correct |
2 |
Correct |
200 ms |
43760 KB |
Output is correct |
3 |
Correct |
197 ms |
45720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
60544 KB |
Output is correct |
2 |
Correct |
404 ms |
106052 KB |
Output is correct |
3 |
Correct |
268 ms |
57680 KB |
Output is correct |
4 |
Correct |
249 ms |
53004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
296 ms |
61900 KB |
Output is correct |
2 |
Correct |
211 ms |
61936 KB |
Output is correct |
3 |
Correct |
428 ms |
58076 KB |
Output is correct |
4 |
Correct |
274 ms |
60864 KB |
Output is correct |