# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
132677 |
2019-07-19T10:21:10 Z |
Vardanyan |
Teams (CEOI11_tea) |
C++14 |
|
2500 ms |
117556 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000*1000+5;
pair<int,int> a[N];
int dp[5005][5005];
int tsnox[5005][5005];
int main(){
ios_base::sync_with_stdio(false);
int n;
cin>>n;
for(int i = 1;i<=n;i++){
cin>>a[i].first;
// a[i].first = rand()%4+1;
a[i].second = i;
}
sort(a+1,a+1+n);
if(n<=600){
int mx = 0;
for(int i = n;i>=1;i--){
mx = max(mx,a[i].first);
if((n-i+1)>=mx){
dp[i][1] = n-i+1;
tsnox[i][1] = n;
}
}
int anss = 1;
for(int k = 2;k<=n;k++){
for(int i = n;i>=1;i--){
int mx = 0;
/*if(i == 2){
cout<<0<<endl;
}*/
for(int j = i;j<=n;j++){
mx = max(mx,a[j].first);
if(dp[j+1][k-1] && (j-i+1)>=mx){
// dp[i][k] = 1;
if(dp[i][k] == 0 || dp[i][k]>max(dp[j+1][k-1],j-i+1)){
dp[i][k] = max(dp[j+1][k-1],j-i+1);
tsnox[i][k] = j;
}
// break;
}
}
}
if(!dp[1][k]) break;
anss = k;
}
cout<<anss<<endl;
int l = 1;
int k = anss;
while(1){
int r = tsnox[l][k];
cout<<r-l+1<<" ";
for(int i = l;i<=r;i++){
cout<<a[i].second<<" ";
}
cout<<endl;
l = r+1;
if(l>n) break;
k--;
}
return 0;
}
// cout<<dp[2][2]<<endl;
// return 0;
// cout<<anss<<" "<<dp[1][anss]<<endl;
multiset<pair<int,int> > ms;
vector<vector<int> > ans;
vector<int> now;
int lim = n+1;
for(int i = n;i>=1;i--){
if(i>=lim){
now.push_back(a[i].second);
continue;
}
if(now.size()){
ans.push_back(now);
ms.insert({now.size(),ans.size()-1});
}
now.clear();
// lim = i-a[i].first+1;
if(i-a[i].first+1<=0){
// now.push_back(a[i].second);
int id = 0;
/*for(int j = 0;j<ans.size();j++){
if(ans[id].size()>ans[j].size()) id = j;
}*/
pair<int,int> u = *(ms.begin());
ms.erase(ms.find(u));
id = u.second;
ms.insert({u.first+1,u.second});
ans[id].push_back(a[i].second);
continue;
}
// if(now.size()) ans.push_back(now);
// now.clear();
lim = i-a[i].first+1;
now.push_back(a[i].second);
}
if(now.size()) ans.push_back(now);
// if(anss!=ans.size()) assert(0);
cout<<ans.size()<<endl;
int mxx = 0;
long long al = 0;
for(int i = 0;i<ans.size();i++){
mxx = max(mxx,(int)ans[i].size());
cout<<ans[i].size()<<" ";
al+=ans[i].size();
for(int j = 0;j<ans[i].size();j++) cout<<ans[i][j]<<" ";
cout<<endl;
}
// cout<<mxx<<endl;
// cout<<al<<endl;*/
return 0;
}
Compilation message
tea.cpp: In function 'int main()':
tea.cpp:106:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i<ans.size();i++){
~^~~~~~~~~~~
tea.cpp:110:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0;j<ans[i].size();j++) cout<<ans[i][j]<<" ";
~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
508 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
888 KB |
Output is correct |
2 |
Correct |
3 ms |
888 KB |
Output is correct |
3 |
Correct |
3 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
4 ms |
1656 KB |
Output is correct |
3 |
Correct |
3 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
2080 KB |
Output is correct |
2 |
Correct |
27 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
2296 KB |
Output is correct |
2 |
Correct |
35 ms |
2168 KB |
Output is correct |
3 |
Correct |
29 ms |
2084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
15008 KB |
Output is correct |
2 |
Correct |
284 ms |
16148 KB |
Output is correct |
3 |
Correct |
244 ms |
16020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
333 ms |
19540 KB |
Output is correct |
2 |
Execution timed out |
2568 ms |
117556 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
345 ms |
21144 KB |
Output is correct |
2 |
Correct |
257 ms |
23140 KB |
Output is correct |
3 |
Correct |
309 ms |
19192 KB |
Output is correct |
4 |
Correct |
340 ms |
19568 KB |
Output is correct |