Submission #539056

#TimeUsernameProblemLanguageResultExecution timeMemory
539056alextodoranCalvinball championship (CEOI15_teams)C++17
100 / 100
244 ms544 KiB
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N_MAX = 10000; const int MOD = (int) 1e6 + 7; int N; int A[N_MAX + 2]; int first[N_MAX + 2]; int teamsPref[N_MAX + 2]; int dp[2][N_MAX + 2]; int main () { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; teamsPref[i] = teamsPref[i - 1]; if (first[A[i]] == 0) { first[A[i]] = i; teamsPref[i]++; } } int answer = 0; fill(dp[1] + 1, dp[1] + N + 1, 1); for (int i = N; i >= 1; i--) { for (int k = 0; k < i; k++) { // dp[i][k] = number of assignments of i..N, when there are already k teams opened dp[0][k] = ((ll) dp[1][k] * k + dp[1][k + 1]) % MOD; } // Try any possible value of B[i]<A[i] and count the assignments for the rest for (int x = 1; x < A[i]; x++) { answer += dp[1][teamsPref[i - 1] + (i < first[x])]; if (answer >= MOD) { answer -= MOD; } } swap(dp[0], dp[1]); } answer++; cout << answer << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...