답안 #62528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62528 2018-07-29T00:15:58 Z MatheusLealV Calvinball championship (CEOI15_teams) C++17
80 / 100
1000 ms 1388 KB
#include <bits/stdc++.h>
#define N 10001
using namespace std;
typedef long long ll;

ll n, k, v[N], tot, used[N], mod = 1000007;

ll dp[N][N], pref[N];

int solve(int i, int k)
{
	if(i > n) return 1;

	if(dp[i][k] != -1) return dp[i][k];

	ll A = (((ll)solve(i + 1, k) * (ll)k) % mod + solve(i + 1, k + 1) % mod)%mod;

	return dp[i][k] = A;
}

inline ll pos()
{
	set<int> add;

	for(int i = 1; i <= n; i++)
	{
		pref[i] = add.size();

		add.insert(v[i]);
	}

	for(int i = n + 1; i >= 1; i--)
	{
		for(ll k = n + 1; k >= 1; k--)
		{
			if(i > n) dp[i%2][k] = 1;

			else
			{
				dp[i%2][k] = ( k * dp[(i + 1)%2][k] + dp[(i + 1)%2][k + 1])%mod;
			}
		}

		if(i <= n) tot = (tot + (ll)dp[(i + 1)%2][ pref[i] ]*((ll)v[i] - 1LL) )%mod; 
	}

	return (tot + 1)%mod;
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n;

	for(int i = 1; i <= n; i++) cin>>v[i];

	cout<<pos()<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 3 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 688 KB Output is correct
2 Correct 3 ms 688 KB Output is correct
3 Correct 4 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 688 KB Output is correct
2 Correct 5 ms 688 KB Output is correct
3 Correct 6 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 760 KB Output is correct
2 Correct 18 ms 760 KB Output is correct
3 Correct 21 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 1388 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 361 ms 1388 KB Output is correct
2 Correct 355 ms 1388 KB Output is correct
3 Correct 361 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1093 ms 1388 KB Time limit exceeded
2 Halted 0 ms 0 KB -