Submission #142687

# Submission time Handle Problem Language Result Execution time Memory
142687 2019-08-10T13:32:11 Z Anai Calvinball championship (CEOI15_teams) C++14
100 / 100
452 ms 760 KB
#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 time Memory Grader output
1 Correct 2 ms 616 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 508 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
3 Correct 9 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 632 KB Output is correct
2 Correct 16 ms 504 KB Output is correct
3 Correct 16 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 446 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 672 KB Output is correct
2 Correct 140 ms 672 KB Output is correct
3 Correct 139 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 451 ms 724 KB Output is correct
2 Correct 447 ms 632 KB Output is correct
3 Correct 452 ms 760 KB Output is correct