Submission #34361

# Submission time Handle Problem Language Result Execution time Memory
34361 2017-11-10T16:49:35 Z mohammad_kilani Calvinball championship (CEOI15_teams) C++14
100 / 100
636 ms 2172 KB
#include <bits/stdc++.h>
using namespace std;
#define mod 1000007
#define oo 2000000000
const int N = 10010;
int arr[N],dp[2][N],mxl[N],n;

int main() {
	//freopen("in.txt","r",stdin);
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&arr[i]);
	for(int i=0;i<=n+5;i++) dp[(n & 1)][i] = 1;
	mxl[0] = 0;
	for(int i=1;i<n;i++) mxl[i] = max(mxl[i-1],arr[i-1]);
	int ans = 1 , mx = 0 ;
	for(int i=n-1;i>=0;i--){
		int mx = mxl[i];
		for(int j=1;j<arr[i];j++){
			mx = max(mx,j);
			ans+= dp[(i+1) & 1][mx];
			if(ans >= mod) ans-=mod;
		}
		for(int j=1;j<=i+1;j++){
			dp[i&1][j] = (long long)dp[(i+1)&1][j] * j % mod;
			dp[i&1][j] += dp[(i+1)&1][j+1];
			if(dp[i&1][j] >= mod) dp[i&1][j] -=mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:15:16: warning: unused variable 'mx' [-Wunused-variable]
  int ans = 1 , mx = 0 ;
                ^
teams.cpp:10:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
teams.cpp:11:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) scanf("%d",&arr[i]);
                                          ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2172 KB Output is correct
2 Correct 0 ms 2172 KB Output is correct
3 Correct 0 ms 2172 KB Output is correct
4 Correct 0 ms 2172 KB Output is correct
5 Correct 0 ms 2172 KB Output is correct
6 Correct 0 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2172 KB Output is correct
2 Correct 0 ms 2172 KB Output is correct
3 Correct 0 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2172 KB Output is correct
2 Correct 0 ms 2172 KB Output is correct
3 Correct 0 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2172 KB Output is correct
2 Correct 0 ms 2172 KB Output is correct
3 Correct 0 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2172 KB Output is correct
2 Correct 0 ms 2172 KB Output is correct
3 Correct 0 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2172 KB Output is correct
2 Correct 3 ms 2172 KB Output is correct
3 Correct 6 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 629 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 2172 KB Output is correct
2 Correct 139 ms 2172 KB Output is correct
3 Correct 156 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 573 ms 2172 KB Output is correct
2 Correct 566 ms 2172 KB Output is correct
3 Correct 636 ms 2172 KB Output is correct