답안 #81796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81796 2018-10-26T16:32:20 Z Just_Solve_The_Problem Calvinball championship (CEOI15_teams) C++11
100 / 100
822 ms 924 KB
#include <stdio.h>

using namespace std;

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

int mod = (int)1e6 + 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] = add(mult(dp[(i & 1) ^ 1][j], j), dp[(i & 1) ^ 1][j + 1]);
		}
		ans = add(ans, mult(dp[i & 1][asd[i - 1]], a[i] - 1));
	}
	printf("%d", 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: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]);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 392 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 500 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 500 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 636 KB Output is correct
2 Correct 10 ms 640 KB Output is correct
3 Correct 10 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 775 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 760 KB Output is correct
2 Correct 209 ms 760 KB Output is correct
3 Correct 202 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 816 ms 760 KB Output is correct
2 Correct 822 ms 788 KB Output is correct
3 Correct 814 ms 924 KB Output is correct