Submission #211479

# Submission time Handle Problem Language Result Execution time Memory
211479 2020-03-20T13:24:32 Z Andrei_Cotor Teams (CEOI11_tea) C++11
80 / 100
381 ms 32632 KB
#include<iostream>
#include<algorithm>

using namespace std;

int Prv[1000005],Best[1000005],Dp[1000005];
pair<int,int> A[1000005];
int n;

//nu era corecta solutia precedenta deoarece se putea sa fie mai bine sa extind echipa curenta pt a scadea lungimea precedentei
bool check(int lgmax)
{
    Dp[0]=0;
    Best[0]=0;
    for(int i=1; i<=n; i++)
    {
        Best[i]=Best[i-1];
        if(i<A[i].first)
        {
            Dp[i]=-1000000000;
            continue;
        }

        if(Best[i-A[i].first]>=i-lgmax)
        {
            Dp[i]=1+Dp[Best[i-A[i].first]];
            Prv[i]=Best[i-A[i].first];
            Best[i]=i;
        }
        else
            Dp[i]=-1000000000;
    }
    return (Dp[n]!=-1000000000);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>A[i].first;
        A[i].second=i;
    }

    sort(A+1,A+n+1); //pax din echipe o sa fie pe pozitii consecutive

    int lung=0;
    for(int i=19; i>=0; i--)
    {
        if(!check(lung+(1<<i)))
            lung+=(1<<i);
    }

    check(lung+1);
    cout<<Dp[n]<<"\n";

    int poz=n;
    while(poz!=0)
    {
        cout<<poz-Prv[poz]<<" ";
        for(int i=poz; i>Prv[poz]; i--)
            cout<<A[i].second<<" ";
        cout<<"\n";
        poz=Prv[poz];
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2944 KB Output is correct
2 Correct 27 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3192 KB Output is correct
2 Correct 26 ms 2552 KB Output is correct
3 Correct 34 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 245 ms 20984 KB Output is correct
2 Correct 237 ms 22520 KB Output is correct
3 Correct 279 ms 24436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 369 ms 27384 KB Output is correct
2 Correct 338 ms 31888 KB Output is correct
3 Correct 323 ms 29872 KB Output is correct
4 Correct 333 ms 28408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 381 ms 24696 KB Output is correct
2 Correct 287 ms 30712 KB Output is correct
3 Correct 333 ms 30712 KB Output is correct
4 Correct 372 ms 32632 KB Output is correct