답안 #447666

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447666 2021-07-27T09:39:01 Z Millad Calvinball championship (CEOI15_teams) C++14
80 / 100
81 ms 65540 KB
// In the name of god
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define debug(x) cerr << #x << " : " << x << "\n"
#define usefile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef string str;

const int maxn = 1e4 + 5;
const ll mod = 1e6 + 7;
const ll inf = 1e18;

int n;
vector <int> dp[maxn];
int ans = 1, num;
ll a[maxn];
bool mrk[maxn];
int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i ++)cin >> a[i];
	dp[0].resize(n + 1);
	dp[1].resize(n + 1);
	for(int i = 1; i < n; i ++)dp[0][i] = 1;
	for(int i = 1; i < n; i ++)dp[1][i] = i + 1;
	int m = n - 1;
	for(int j = 2; j < n; j ++){
		dp[j].resize(m + 2);
		for(ll i = 1; i < m; i ++)dp[j][i] = (i * dp[j - 1][i] + dp[j - 1][i + 1]) % mod;
		m --;
	}
	mrk[1] = 1; num = 1;
	for(int i = 1; i < n; i ++){
		bool bl = 0;
		if(!mrk[a[i]]){
			mrk[a[i]] = 1;
			num ++; bl = 1;
		}
		if(bl)ans = (ans + ((a[i] - 1ll) * dp[n - i - 1][num - 1] % mod)) % mod;
		else ans = (ans + ((a[i] - 1ll) * dp[n - i - 1][num] % mod)) % mod;
	}
	cout << ans;
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 556 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 1068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2508 KB Output is correct
2 Correct 3 ms 2508 KB Output is correct
3 Correct 3 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 81 ms 65540 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 49604 KB Output is correct
2 Correct 52 ms 49596 KB Output is correct
3 Correct 53 ms 49632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 74 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -