답안 #63652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63652 2018-08-02T10:42:16 Z khohko Calvinball championship (CEOI15_teams) C++17
100 / 100
698 ms 1164 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define ARRS ((ll)(2e6+500))
#define MAX ((ll)(1e6+100))
#define MOD ((ll)1e6+7)
#define mi(a,b) a=min((a),(b))

ll n,m,k,p,l,r,q;
ll a[20000];
ll f[2][10005][2];



int main(){
	#ifdef KHOKHO
			freopen("in.in","r",stdin);
			freopen("out.out","w",stdout);
	#endif
	cin>>n;
	for(int i=0; i<n; i++)cin>>a[i];
	ll N=0,P=1;
	for(ll i=n; i>=0; i--){
		for(ll c=n; c>=0; c--){
			for(ll e=0; e<2; e++){
				if(i==n){f[N][c][e]=1;continue;}
				f[N][c][e]=0;
				if(e)
					f[N][c][e]=c*f[P][c][e]+f[P][c+1][e];
				else {
					if(a[i]==c+1){
						f[N][c][e]+=c*f[P][c][1];
						f[N][c][e]+=f[P][c+1][0];
					}
					else {
						f[N][c][e]+=(a[i]-1)*f[P][c][1];
						f[N][c][e]+=f[P][c][0];
					}
				}
				f[N][c][e]%=MOD;
			}
		}
		swap(N,P);
	}
	cout<<f[P][0][0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 520 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 2 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 644 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 3 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 644 KB Output is correct
2 Correct 3 ms 644 KB Output is correct
3 Correct 3 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 644 KB Output is correct
2 Correct 5 ms 644 KB Output is correct
3 Correct 5 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 644 KB Output is correct
2 Correct 10 ms 644 KB Output is correct
3 Correct 11 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 665 ms 1000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 1000 KB Output is correct
2 Correct 168 ms 1000 KB Output is correct
3 Correct 126 ms 1000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 492 ms 1004 KB Output is correct
2 Correct 698 ms 1132 KB Output is correct
3 Correct 608 ms 1164 KB Output is correct