Submission #457789

# Submission time Handle Problem Language Result Execution time Memory
457789 2021-08-07T11:44:32 Z vanic Calvinball championship (CEOI15_teams) C++14
70 / 100
18 ms 8436 KB
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

const int maxn=1e3+5, 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 Correct 12 ms 4172 KB Output is correct
2 Correct 14 ms 4240 KB Output is correct
3 Correct 13 ms 4248 KB Output is correct
4 Correct 13 ms 4196 KB Output is correct
5 Correct 14 ms 4260 KB Output is correct
6 Correct 14 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4176 KB Output is correct
2 Correct 12 ms 4232 KB Output is correct
3 Correct 11 ms 4264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4172 KB Output is correct
2 Correct 12 ms 4276 KB Output is correct
3 Correct 12 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 4276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4160 KB Output is correct
2 Correct 12 ms 4172 KB Output is correct
3 Correct 15 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4228 KB Output is correct
2 Correct 12 ms 4172 KB Output is correct
3 Correct 12 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4276 KB Output is correct
2 Correct 15 ms 4220 KB Output is correct
3 Correct 12 ms 4260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 8396 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 8436 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 8400 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -