Submission #447667

#TimeUsernameProblemLanguageResultExecution timeMemory
447667MilladCalvinball championship (CEOI15_teams)C++14
100 / 100
136 ms556 KiB
// 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 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...