제출 #117643

#제출 시각아이디문제언어결과실행 시간메모리
117643JohnTitorTeams (CEOI11_tea)C++11
100 / 100
254 ms38480 KiB
#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);
}
#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...