#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define setbit(s, i) (s|=(1LL<<(i)))
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
using ll=long long;
using ld=long double;
template <typename T> inline void read(T &x){
char c;
bool nega=0;
while((!isdigit(c=getchar()))&&(c!='-'));
if(c=='-'){
nega=1;
c=getchar();
}
x=c-48;
while(isdigit(c=getchar())) x=x*10+c-48;
if(nega) x=-x;
}
template <typename T> inline void writep(T x){
if(x>9) writep(x/10);
putchar(x%10+48);
}
template <typename T> inline void write(T x){
if(x<0){
putchar('-');
x=-x;
}
writep(x);
}
template <typename T> inline void writeln(T x){
write(x);
putchar('\n');
}
#define taskname "Teams"
#define prev KafuuChino
vector <pair <int, int>> a;
int f[1000001];
int g[1000001];
int x[1000001];
int last[1000001];
int prev[1000001];
int n;
bool check(int length){
int t=n;
while(t){
int nw=t-a[t].first;
while(f[nw]!=g[nw]) nw--;
if(nw<t-length) return 0;
while((prev[nw]!=-1)&&(t-prev[nw]<=length)) nw=prev[nw];
t=nw;
}
return 1;
}
void output(int length){
int t=n;
while(t){
int nw=t-a[t].first;
while(f[nw]!=g[nw]) nw--;
while((prev[nw]!=-1)&&(t-prev[nw]<=length)) nw=prev[nw];
write(t-nw);
FOR(i, nw+1, t){
putchar(' ');
write(a[i].second);
}
putchar('\n');
t=nw;
}
}
void test(int k){
}
int main(){
#ifdef Uiharu
if(fopen(taskname".in", "r"))
freopen(taskname".in", "r", stdin);
#endif // Uiharu
read(n);
FOR(i, 1, n){
read(x[i]);
a.pb(mp(x[i], i));
}
sort(a.begin(), a.end());
a.insert(a.begin(), mp(-1, -1));
FOR(i, 1, n){
if(i>=a[i].first) f[i]=g[i-a[i].first]+1;
else f[i]=-1e9;
g[i]=max(f[i], g[i-1]);
}
writeln(f[n]);
///biggest team is smallest
FOR(i, 0, f[n]) last[i]=-1;
FOR(i, 0, n) if(f[i]>=0){
if(last[f[i]]==-1) prev[i]=-1; else prev[i]=last[f[i]];
last[f[i]]=i;
}
int low=a[n].first, high=n, mid, res=0;
while(low<=high){
mid=(low+high)/2;
if(check(mid)){
res=mid;
high=mid-1;
}
else low=mid+1;
}
output(res);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
3188 KB |
Output is correct |
2 |
Correct |
17 ms |
3060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3636 KB |
Output is correct |
2 |
Correct |
17 ms |
3024 KB |
Output is correct |
3 |
Correct |
23 ms |
3572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
26952 KB |
Output is correct |
2 |
Correct |
180 ms |
25552 KB |
Output is correct |
3 |
Correct |
181 ms |
27300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
249 ms |
36304 KB |
Output is correct |
2 |
Correct |
232 ms |
38480 KB |
Output is correct |
3 |
Correct |
236 ms |
33808 KB |
Output is correct |
4 |
Correct |
220 ms |
31944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
254 ms |
36028 KB |
Output is correct |
2 |
Correct |
179 ms |
34640 KB |
Output is correct |
3 |
Correct |
221 ms |
34644 KB |
Output is correct |
4 |
Correct |
247 ms |
36432 KB |
Output is correct |