Submission #221945

# Submission time Handle Problem Language Result Execution time Memory
221945 2020-04-11T14:44:23 Z MKopchev Calvinball championship (CEOI15_teams) C++14
100 / 100
281 ms 776 KB
#include<bits/stdc++.h>
using namespace std;

const int nmax=1e4+42,mod=1e6+7;

int n,inp[nmax];

bool in[nmax];

pair<int/*coeff*/,int/*k*/> noted[nmax];

int dp[nmax];

long long help[nmax];

int main()
{
    scanf("%i",&n);

    for(int i=1;i<=n;i++)
        scanf("%i",&inp[i]);

    int diff=0;
    for(int i=1;i<=n;i++)
    {
        noted[i+1]={inp[i]-1,diff};

        if(in[inp[i]]==0)diff++;
        in[inp[i]]=1;
    }

    //for(int i=1;i<=n+1;i++)cout<<i<<" -> "<<noted[i].first<<" "<<noted[i].second<<endl;

    for(int i=2;i<=n+1;i++)
    {
        dp[noted[i].second]=(dp[noted[i].second]+noted[i].first)%mod;

        if(i==n+1)
        {
            int output=1;
            for(int k=1;k<=n;k++)
                output=(output+dp[k])%mod;
            printf("%i\n",output);
            return 0;
        }

        for(int k=1;k<=i;k++)help[k]=0;

        for(int k=1;k<=i;k++)
        {
            help[k]=(help[k]+1LL*k*dp[k])%mod;
            help[k+1]=(help[k+1]+dp[k])%mod;
        }

        for(int k=1;k<=i;k++)dp[k]=help[k];

        //cout<<"i= "<<i<<" -> ";for(int k=1;k<=i;k++)cout<<dp[k]<<" ";cout<<endl;
    }
    return 0;
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
teams.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&inp[i]);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 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 5 ms 384 KB Output is correct
3 Correct 5 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 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 267 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 384 KB Output is correct
2 Correct 69 ms 512 KB Output is correct
3 Correct 71 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 269 ms 512 KB Output is correct
2 Correct 281 ms 776 KB Output is correct
3 Correct 271 ms 632 KB Output is correct