Submission #457791

# Submission time Handle Problem Language Result Execution time Memory
457791 2021-08-07T11:45:15 Z vanic Calvinball championship (CEOI15_teams) C++14
0 / 100
196 ms 65540 KB
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

const int maxn=1e4+2, mod=1e6+7, Log=20;
const int phi=965495;
int fact[maxn];


int n;
int dp[maxn][maxn];

int gcd(int a, int b){
	if(a>b){
		swap(a, b);
	}
	int c;
	while(a){
		c=b%a;
		b=a;
		a=c;
	}
	return b;
}

inline int sum(int a, int b){
	if(a+b>=mod){
		return a+b-mod;
	}
	if(a+b<0){
		return a+b+mod;
	}
	return a+b;
}

inline int mul(int a, int b){
	return (ll)a*b%mod;
}

inline int pote(int a, int b){
	int sol=1;
	for(int i=0; i<Log; i++){
		if((1<<i)&b){
			sol=mul(sol, a);
		}
		a=mul(a, a);
	}
	return sol;
}

inline int dij(int a, int b){
	return mul(a, pote(b, phi));
}

void precompute(){
	fact[0]=1;
	for(int i=1; i<maxn; i++){
		fact[i]=mul(fact[i-1], i);
	}
	for(int i=0; i<maxn; i++){
		dp[0][i]=1;
	}
	for(int i=1; i<maxn; i++){
		for(int j=0; j<maxn-1; j++){
			dp[i][j]=sum(mul(j, dp[i-1][j]), dp[i-1][j+1]);
		}
	}
}

int a[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	precompute();
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	int sol=1;
	int maksi=0;
	bool p;
	for(int i=0; i<n; i++){
		if(maksi<a[i]){
			maksi=a[i];
			p=1;
		}
		else{
			p=0;
		}
		if(p){
			sol=sum(sol, mul(a[i]-1, dp[n-i-1][maksi-1]));
		}
		else{
			sol=sum(sol, mul(a[i]-1, dp[n-i-1][maksi]));
		}
	}
	cout << sol << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 186 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 183 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 192 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 185 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 184 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 188 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 196 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 191 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 186 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 190 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -