Submission #81790

# Submission time Handle Problem Language Result Execution time Memory
81790 2018-10-26T16:19:12 Z Just_Solve_The_Problem Calvinball championship (CEOI15_teams) C++11
20 / 100
1000 ms 1012 KB
#include <bits/stdc++.h>

using namespace std;

const int N = (int)1e4 + 7;

int mod = (int)1e9 + 7;
int a[N];
int dp[2][N];

int add(int a, int b) {
	return (a + b) % mod;
}

int mult(long long a, long long b) {
	return (a * b) % mod;
}

int n, mx;
int asd[N];

main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		asd[i] = asd[i - 1];
		if (a[i] > mx) {
			mx = a[i];
			asd[i]++;
		}
	}
	int ans = 1;
	for (int i = 1; i <= n; i++) dp[n & 1][i] = 1;
	ans = add(ans, mult(dp[n & 1][asd[n - 1]], a[n] - 1));
	for (int i = n - 1; i >= 1; i--) {
		for (int j = 0; j <= i; j++) {
			dp[i & 1][j] = 0;
			dp[i & 1][j] = add(dp[i & 1][j], dp[i & 1 ^ 1][j + 1]);
			dp[i & 1][j] = add(dp[i & 1][j], mult(dp[i & 1 ^ 1][j], j));
		}
		ans = add(ans, mult(dp[i & 1][asd[i - 1]], a[i] - 1));
	}
	cout << ans;
}

Compilation message

teams.cpp:22:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
teams.cpp: In function 'int main()':
teams.cpp:38:42: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    dp[i & 1][j] = add(dp[i & 1][j], dp[i & 1 ^ 1][j + 1]);
                                        ~~^~~
teams.cpp:39:47: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    dp[i & 1][j] = add(dp[i & 1][j], mult(dp[i & 1 ^ 1][j], j));
                                             ~~^~~
teams.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
teams.cpp:25:8: 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 2 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 2 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 648 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 920 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 255 ms 920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 1012 KB Time limit exceeded
2 Halted 0 ms 0 KB -