Submission #83543

# Submission time Handle Problem Language Result Execution time Memory
83543 2018-11-08T21:18:46 Z nikolapesic2802 Calvinball championship (CEOI15_teams) C++14
0 / 100
1000 ms 1484 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);
    }
    for(int i=0;i<N;i++){
        dp[0][i]=1;
        if(trazi.count({0,i}))
               resenja[{0,i}]=dp[0][i];
    }
    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]);
            if(trazi.count({n,i}))
               resenja[{n,i}]=dp[n%2][i];
        }
    }
    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 Execution timed out 1081 ms 504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 508 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 508 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 508 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 508 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 788 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 1484 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 1484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 1484 KB Time limit exceeded
2 Halted 0 ms 0 KB -