Submission #63650

# Submission time Handle Problem Language Result Execution time Memory
63650 2018-08-02T10:41:14 Z khohko Calvinball championship (CEOI15_teams) C++17
80 / 100
1000 ms 932 KB
#include<bits/stdc++.h>
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;}
				if(e){
					f[N][c][e]=c*f[P][c][e]+f[P][c+1][e];
					f[N][c][e]%=MOD;
				}
				else {
					f[N][c][e]=0;
					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];
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 720 KB Output is correct
2 Correct 3 ms 720 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 720 KB Output is correct
2 Correct 2 ms 720 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 720 KB Output is correct
2 Correct 3 ms 720 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 720 KB Output is correct
2 Correct 7 ms 720 KB Output is correct
3 Correct 10 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 748 KB Output is correct
2 Correct 29 ms 748 KB Output is correct
3 Correct 24 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 892 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 481 ms 892 KB Output is correct
2 Correct 572 ms 892 KB Output is correct
3 Correct 530 ms 892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 932 KB Time limit exceeded
2 Halted 0 ms 0 KB -