답안 #656369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
656369 2022-11-07T05:11:38 Z Sohsoh84 Calvinball championship (CEOI15_teams) C++17
100 / 100
164 ms 600 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e4 + 10;
const ll MOD = 1000007;

int n, A[MAXN], mx[MAXN];
ll S[2][MAXN], ans;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	S[1][0] = 1;
	for (int i = 1; i <= n; i++) {
		cin >> A[i];
		S[1][i] = i + 1;
		mx[i] = max(mx[i - 1], A[i]);
	}

	ans = A[n];
	int ind = 1;
	for (int i = n - 1; i > 0; i--) {
		ind = ind ^ 1;
		for (int i = 0; i < MAXN - 1; i++)
			S[ind][i] = (S[ind ^ 1][i] * i + S[ind ^ 1][i + 1]) % MOD;
	
		ans = (ans + S[ind ^ 1][mx[i - 1]] * (A[i] - 1)) % MOD;
	}

	cout << ans << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 456 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 596 KB Output is correct
2 Correct 10 ms 468 KB Output is correct
3 Correct 9 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 468 KB Output is correct
2 Correct 17 ms 504 KB Output is correct
3 Correct 17 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 528 KB Output is correct
2 Correct 81 ms 528 KB Output is correct
3 Correct 79 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 572 KB Output is correct
2 Correct 155 ms 572 KB Output is correct
3 Correct 158 ms 600 KB Output is correct