Submission #24689

# Submission time Handle Problem Language Result Execution time Memory
24689 2017-06-11T20:26:20 Z Bruteforceman Calvinball championship (CEOI15_teams) C++11
100 / 100
486 ms 2332 KB
#include "bits/stdc++.h"
using namespace std;
long long dp[2][10005];
const int mod = 1000007;

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	int *a; 
	int *maxn;
	a = new int [n + 5];
	maxn = new int [n + 5];
	maxn[0] = 0;
	a[0] = 0;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		maxn[i] = max(maxn[i - 1], a[i]);
	}
	int ans = a[n];
	for(int i = 0; i <= n; i++) {
		dp[0][i] = 1;
	}
	int ro = 1;
	for(int i = 1; i < n; i++) {
		for(int j = 1; j <= n; j++) {
			dp[ro][j] = dp[ro ^ 1][j] * j + dp[ro ^ 1][j + 1]; 
			dp[ro][j] %= mod;
		}
		int idx = n - i;
		for(int j = 1; j < a[idx]; j++) {
			ans += dp[ro][max(maxn[idx - 1], j)];
			ans %= mod;
		}
		ro ^= 1;
	}
	printf("%d\n", ans);
	return 0;	
}

Compilation message

teams.cpp: In function 'int main(int, const char**)':
teams.cpp:9:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
teams.cpp:17:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
                     ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2176 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 0 ms 2176 KB Output is correct
4 Correct 0 ms 2176 KB Output is correct
5 Correct 0 ms 2176 KB Output is correct
6 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2176 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2176 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2176 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2176 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2176 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 3 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 466 ms 2328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 2176 KB Output is correct
2 Correct 53 ms 2176 KB Output is correct
3 Correct 113 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 2332 KB Output is correct
2 Correct 219 ms 2332 KB Output is correct
3 Correct 486 ms 2332 KB Output is correct