Submission #447667

# Submission time Handle Problem Language Result Execution time Memory
447667 2021-07-27T09:40:11 Z Millad Calvinball championship (CEOI15_teams) C++14
100 / 100
136 ms 556 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 int mod = 1e6 + 7;
const ll inf = 1e18;

int n, dp[maxn][2], ans, num, cnt[maxn];
ll a[maxn];
bool mrk[maxn], mrk2[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];
	for(int i = 1; i <= n; i ++)dp[i][1] = i + 1;
	mrk[1] = 1; num = 1; cnt[0] = 1;
	for(int i = 1; i < n; i ++){
		if(!mrk[a[i]]){
			mrk[a[i]] = 1;
			mrk2[i] = 1;
			num ++;
		}
		cnt[i] = num;
	}
	int t = 0, m = n;
	for(int j = 2; j < n - 1; j ++){
		for(int i = 1; i < m; i ++)dp[i][t] = (1ll * i * dp[i][t ^ 1] + dp[i + 1][t ^ 1]) % mod;
		m --; 
		int ind = n - j - 1, bl = 0;
		if(mrk2[ind])bl = 1;
		ans = (ans + (a[ind] - 1) * dp[cnt[ind] - bl][t] % mod) % mod;
		t ^= 1;
	}
	ans += a[n - 1];
	if(n > 2)ans += (a[n - 2] - 1) * (cnt[n - 3] + 1);
	cout << ans % mod;	
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 440 KB Output is correct
2 Correct 32 ms 332 KB Output is correct
3 Correct 31 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 504 KB Output is correct
2 Correct 129 ms 456 KB Output is correct
3 Correct 121 ms 556 KB Output is correct