답안 #529152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529152 2022-02-22T10:28:16 Z codr0 Calvinball championship (CEOI15_teams) C++14
10 / 100
821 ms 716 KB
// Code by Parsa Eslami
 
#include <bits/stdc++.h>
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define S second
#define F first
#define pb push_back
#define SZ(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define err(x) cout<<#x<<": "<<x<<'\n';
 
using namespace std;
const int MOD=1e6+7;
const int N=1e4+5;
int dp[2][N];

	int32_t main(){
	ios_base::sync_with_stdio(0); cin.tie(0);	


	int n; cin>>n;
	int ans=0;
	int mx[n+1]={};
	int a[n+1]={};
	FOR(i,1,n){
		cin>>a[i];
		mx[i]=max(mx[i-1],a[i]);
	}
	ans=a[n];
	dp[(n%2)][0]=1;
	FOR(i,1,n){
		dp[(n%2)][i]=(1LL*dp[(n%2)][i-1]*n)%MOD;
	}
	int ind=n-1;
	FORR(j,n-1,1){
		FOR(i,0,n){
			if(i==0) {dp[(j%2)][i]=1; continue;}
			dp[(j%2)][i]=(1LL*dp[(j+1)%2][i-1]+1LL*dp[(j%2)][i-1]*j)%MOD;	
		}
		while(ind>0&&mx[ind-1]==j){
			ans=(1LL*ans+1LL*(a[ind]-1)*dp[j][n-ind])%MOD;
			ind--;
		}
	}
	cout<<ans<<'\n';


	return 0;
	}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Runtime error 1 ms 460 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 452 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 191 ms 508 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 821 ms 700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -