Submission #491663

#TimeUsernameProblemLanguageResultExecution timeMemory
491663Bench0310Teams (CEOI11_tea)C++17
100 / 100
476 ms21032 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<array<int,2>> a(n+1,{0,0}); for(int i=1;i<=n;i++) { cin >> a[i][0]; a[i][1]=i; } sort(a.begin(),a.end()); vector<int> p(n+1,0); auto go=[&](int lim)->int { vector<int> dp(n+1,-1); dp[0]=0; vector<int> prv(n+1,0); int mx=0; for(int i=1;i<=n;i++) { prv[i]=prv[i-1]; if(a[i][0]>i) continue; int j=prv[i-a[i][0]]; if(i-lim<=j&&((i<n&&dp[j]+1>=mx)||i==n)) { dp[i]=dp[j]+1; mx=dp[i]; prv[i]=i; p[i]=j; } } return dp[n]; }; int cnt=go(n); int l=0,r=n; while(l<r-1) { int m=(l+r)/2; if(go(m)==cnt) r=m; else l=m; } cout << cnt << "\n"; go(r); int idx=n; while(idx>=1) { cout << idx-p[idx] << " "; for(int i=p[idx]+1;i<=idx;i++) cout << a[i][1] << " \n"[i==idx]; idx=p[idx]; } return 0; }
#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...