Submission #131083

#TimeUsernameProblemLanguageResultExecution timeMemory
131083arthurconmyCalvinball championship (CEOI15_teams)C++14
70 / 100
74 ms65540 KiB
/* Arthur Conmy / arthurconmy */ #include <iostream> #include <fstream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <map> #include <queue> #include <bitset> #include <random> #include <stack> #include <deque> #include <chrono> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<bool> vb; typedef pair<int,int> pii; #define REP(i, a, b) for (ll i = ll(a); i <= ll(b); i++) #define REPb(j, d, c) for (ll j = ll(d); j >= ll(c); j--) #define ff first #define ss second #define pb push_back #define len(x) int((x).size()) #define endl "\n" const ll MAXN=5001; const ll p=1000007; ll A[MAXN]; ll sz[MAXN][MAXN]; ll pos[MAXN][MAXN]; int main() // LL OR INT?? { #ifdef ARTHUR_LOCAL ifstream cin("input.txt"); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin>>n; if(n==1) { cout << 1 << endl; return 0; } ll thing_max=1; REP(i,1,n) { ll a; cin>>a; A[i]=a; thing_max=max(thing_max,a); } sz[1][1]=ll(1); pos[1][1]=ll(1); bool just_ones=1; ll cur_max=1; REP(i,2,n) { sz[i][1]=1; if(just_ones&&A[i]==1) pos[i][1]=0; else { just_ones=0; pos[i][1]=1; } // int j=1; // cout << i << " " << j << " " << pos[i][j] << endl; REP(j,2,i-1) { sz[i][j]=sz[i-1][j-1]+j*sz[i-1][j]; sz[i][j]%=p; pos[i][j]=pos[i-1][j-1] +j*pos[i-1][j] +ll(j==cur_max)*(A[i]-1); pos[i][j]%=p; // cout << i << " " << j << " " << pos[i][j] << endl; } // cout << i << " " << i << " " << pos[i][i] << endl; cur_max=max(cur_max,A[i]); } ll ans=0; REP(j,1,n) { ans+=pos[n][j]; ans%=p; } ans++; ans%=p; cout << ans << endl; }
#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...