Submission #224006

# Submission time Handle Problem Language Result Execution time Memory
224006 2020-04-17T03:37:54 Z kshitij_sodani Calvinball championship (CEOI15_teams) C++17
70 / 100
774 ms 576 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
int mod=1000007;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int it[n];
	for(int i=0;i<n;i++){
		cin>>it[i];
	}
	int pre[n];
	pre[0]=it[0];
	for(int i=1;i<n;i++){
		pre[i]=max(pre[i-1],it[i]);
	}
	int dp[n];
	for(int i=0;i<n;i++){
		dp[i]=1;
	}
	int tot=0;
	for(int i=n-1;i>=0;i--){
		int 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(int 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(int j=0;j<n;j++){
			dp[j]=dp2[j];
		}
	/*	cout<<tot<<endl;
		for(int j=0;j<n;j++){
			cout<<dp[j]<<" ";
		}
		cout<<endl;*/
		
	}
	cout<<tot<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 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 5 ms 404 KB Output is correct
3 Correct 5 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 384 KB Output is correct
3 Correct 12 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 756 ms 576 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 193 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 774 ms 568 KB Output isn't correct
2 Halted 0 ms 0 KB -