Submission #475442

# Submission time Handle Problem Language Result Execution time Memory
475442 2021-09-22T12:41:56 Z MohamedAhmed04 Calvinball championship (CEOI15_teams) C++14
100 / 100
361 ms 496 KB
#include <bits/stdc++.h>

using namespace std ;

const int mod = 1000007 ;

int Add(int x , int y)
{
	int z = x + y ;
	if(z >= mod)
		z -= mod ;
	return z ;
}

int Mul(int x , int y)
{
	return (1ll * x * y) % mod ;
}

const int MAX = 1e4 + 10 ;

int arr[MAX] ;
int n ;

int dp[2][MAX] , val[MAX] ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	for(int i = 1 ; i <= n ; ++i)
		cin>>arr[i] ;
	val[0] = 1 ; 
	for(int i = 1 ; i <= n ; ++i)
		val[i] = max(val[i-1] , arr[i]) ;
	for(int j = 1 ; j <= n ; ++j)
		dp[(n+1)&1][j] = 1 ;
	int ans = 0 ;
	for(int i = n ; i >= 1 ; --i)
	{
		int now = (i&1) ;
		int nxt = !now ;
		for(int j = 1 ; j <= n ; ++j)
			dp[now][j] = Add(Mul(j , dp[nxt][j]) , dp[nxt][j+1]) ;
		ans = Add(ans , Mul(arr[i]-1 , dp[nxt][val[i-1]])) ;
	}
	ans = Add(ans , 1) ;
	return cout<<ans<<"\n" , 0 ;
}		
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 332 KB Output is correct
2 Correct 5 ms 332 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 322 ms 496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 404 KB Output is correct
2 Correct 87 ms 404 KB Output is correct
3 Correct 150 ms 412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 361 ms 476 KB Output is correct
2 Correct 351 ms 460 KB Output is correct
3 Correct 332 ms 496 KB Output is correct