Submission #224007

# Submission time Handle Problem Language Result Execution time Memory
224007 2020-04-17T03:38:47 Z kshitij_sodani Calvinball championship (CEOI15_teams) C++17
100 / 100
788 ms 760 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long llo;
llo mod=1000007;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	llo n;
	cin>>n;
	llo it[n];
	for(llo i=0;i<n;i++){
		cin>>it[i];
	}
	llo pre[n];
	pre[0]=it[0];
	for(llo i=1;i<n;i++){
		pre[i]=max(pre[i-1],it[i]);
	}
	llo dp[n];
	for(llo i=0;i<n;i++){
		dp[i]=1;
	}
	llo tot=0;
	for(llo i=n-1;i>=0;i--){
		llo dp2[n];
		if(it[i]<pre[i]){
			tot+=(dp[pre[i]-1]*(pre[i]-it[i]));
		}
		if(i>0 and pre[i-1]<n){
			if(it[i]!=pre[i-1]+1){
				tot+=dp[pre[i-1]];
			}
		}	
		tot%=mod;
		if(i==0){
			tot=(dp[0]-tot+mod)%mod;
		}
		for(llo j=0;j<n;j++){
			if(i==n-1){
				if(j==n-1){
					dp2[j]=n;
				}
				else{
					dp2[j]=j+2;
				}
			}
			else{
				dp2[j]=(dp[j]*(j+1));
				if(j<n-1){
					dp2[j]+=dp[j+1];
				}
				dp2[j]%=mod;
			}
		}
		for(llo j=0;j<n;j++){
			dp[j]=dp2[j];
		}
	/*	cout<<tot<<endl;
		for(llo j=0;j<n;j++){
			cout<<dp[j]<<" ";
		}
		cout<<endl;*/
		
	}
	cout<<tot<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 384 KB Output is correct
2 Correct 12 ms 512 KB Output is correct
3 Correct 12 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 760 ms 688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 512 KB Output is correct
2 Correct 195 ms 552 KB Output is correct
3 Correct 194 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 788 ms 760 KB Output is correct
2 Correct 779 ms 760 KB Output is correct
3 Correct 779 ms 760 KB Output is correct