Submission #142687

#TimeUsernameProblemLanguageResultExecution timeMemory
142687AnaiCalvinball championship (CEOI15_teams)C++14
100 / 100
452 ms760 KiB
#include <bits/stdc++.h> using namespace std; template<long long MOD> class Num { private: long long expow(long long base, long long e) const { long long ans = 1; for (; e > 0; e/= 2) { if (e % 2) ans = ans * base % MOD; base = base * base % MOD; } return ans; } public: long long val; Num(long long _val) { val = _val % MOD; val = val < 0 ? val + MOD : val; } Num() : val(0) { } inline Num operator + (const Num &arg) const { Num res; res.val = val + arg.val; res.val = res.val >= MOD ? res.val - MOD : res.val; return res; } inline Num operator - (const Num &arg) const { Num res; res.val = val - arg.val; res.val = res.val < 0 ? res.val + MOD : res.val; return res; } inline Num operator - () const { Num res; res.val = MOD - res.val; res.val = res.val == MOD ? 0 : res.val; return res; } inline Num operator ^ (const int &arg) const { return Num(expow(val, arg)); } inline Num operator * (const Num &arg) const { return Num(val * arg.val); } inline Num operator / (const Num &arg) const { return Num(val * expow(arg.val, MOD - 2)); } inline void operator += (const Num &arg) { (*this) = (*this) + arg; } inline void operator -= (const Num &arg) { (*this) = (*this) - arg; } inline void operator *= (const Num &arg) { (*this) = (*this) * arg; } inline void operator /= (const Num &arg) { (*this) = (*this) / arg; } inline void operator ^= (const long long &arg) { val = expow(val, arg); } }; template<long long MOD> ostream &operator << (ostream &fo, const Num<MOD> &c) { fo << c.val; return fo; } template<long long MOD> istream &operator >> (istream &fi, Num<MOD> &c) { fi >> c.val; c = Num<MOD>(c.val); return fi; } const int MOD = 1e6 + 7, N = 10005; Num<MOD> stirling[2][N], pwr2[N]; vector<int> v, pmax; Num<MOD> ant; int n; int main() { #ifdef HOME freopen("teams.in", "r", stdin); freopen("teams.out", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); pmax.reserve(N); int mx = 0; pwr2[0] = 1; for (int i = 1; i < N; ++i) pwr2[i] = pwr2[i - 1] * 2; cin >> n; v.resize(n); pmax.push_back(0); for (auto &i: v) { cin >> i; mx = max(mx, i); pmax.push_back(mx); } for (int i = 1; i <= n; ++i) stirling[0][i] = 1; for (int i = 1; i <= n; ++i) { ant+= stirling[0][pmax[n - i]] * (v[n - i] - 1); for (int j = 1; j <= n; ++j) stirling[1][j] = stirling[0][j] * j + stirling[0][j + 1]; swap(stirling[0], stirling[1]); } cout << ant + 1 << endl; 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...