Submission #83545

# Submission time Handle Problem Language Result Execution time Memory
83545 2018-11-08T21:23:11 Z nikolapesic2802 Calvinball championship (CEOI15_teams) C++14
100 / 100
684 ms 1964 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; ///find_by_order(),order_of_key()

const int N=1e4;
const int mod=1e6+7;
//int dp[N][N]; /// dp[x][y] Number of ways to choose x numbers if the max so far is y
int dp[2][N];
int pref[N];
int add(int a,int b){
    a+=b;
    if(a>mod)
        a-=mod;
    return a;
}
int sub(int a,int b)
{
    a-=b;
    if(a<0)
        a+=mod;
    return a;
}
int get(int l,int r)
{
    if(l==0)
        return pref[r];
    return sub(pref[r],pref[l-1]);
}
map<pair<int,int>,int> resenja;
set<pair<int,int> > trazi;
int main()
{
    int n;
    scanf("%i",&n);
    /*vector<int> a(n);
    for(int i=0;i<n;i++)
        scanf("%i",&a[i]);*/
    int res=0;
    int tr=0;
    vector<int> arr(n);
    for(int i=0;i<n;i++)
        scanf("%i",&arr[i]);
    for(int i=0;i<n;i++){
        int a=arr[i];
        trazi.insert({n-i-1,tr-2});
        tr=max(tr,a+1);
    }
    trazi.insert({N,N});
    set<pair<int,int> >::iterator it=trazi.begin();
    for(int i=0;i<N;i++){
        dp[0][i]=1;
    }
    while((*it).first<=0)
    {
        resenja[{(*it).first,(*it).second}]=dp[(*it).first][(*it).second];
        it++;
    }
    for(int n=1;n<N;n++)
    {
        pref[0]=dp[(n-1)%2][0];
        for(int i=1;i<N;i++)
        {
            pref[i]=add(pref[i-1],dp[(n-1)%2][i]);
        }
        for(int i=0;i<N-1;i++)
        {
            dp[n%2][i]=add(((ll)dp[(n-1)%2][i]*(i+1))%mod,dp[(n-1)%2][i+1]);
        }
        while((*it).first<=n)
        {
            resenja[{(*it).first,(*it).second}]=dp[((*it).first)%2][(*it).second];
            it++;
        }
    }
    tr=0;
    for(int i=0;i<n;i++){
        int a=arr[i];
       // printf("%i %i:%i\n",n-i-1,tr-2,resenja[{n-i-1,tr-2}]);
        res=add(res,((ll)(a-1)*resenja[{n-i-1,tr-2}])%mod);
        tr=max(tr,a+1);
    }
    res++;
    printf("%i\n",res);

    return 0;
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
teams.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&arr[i]);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 645 ms 472 KB Output is correct
2 Correct 644 ms 552 KB Output is correct
3 Correct 652 ms 564 KB Output is correct
4 Correct 651 ms 580 KB Output is correct
5 Correct 643 ms 584 KB Output is correct
6 Correct 673 ms 584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 659 ms 624 KB Output is correct
2 Correct 646 ms 660 KB Output is correct
3 Correct 646 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 659 ms 660 KB Output is correct
2 Correct 678 ms 660 KB Output is correct
3 Correct 675 ms 668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 677 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 645 ms 728 KB Output is correct
2 Correct 680 ms 736 KB Output is correct
3 Correct 664 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 663 ms 860 KB Output is correct
2 Correct 658 ms 860 KB Output is correct
3 Correct 684 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 652 ms 860 KB Output is correct
2 Correct 657 ms 860 KB Output is correct
3 Correct 639 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 660 ms 1788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 652 ms 1788 KB Output is correct
2 Correct 667 ms 1788 KB Output is correct
3 Correct 658 ms 1788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 652 ms 1828 KB Output is correct
2 Correct 657 ms 1884 KB Output is correct
3 Correct 664 ms 1964 KB Output is correct