Submission #93580

# Submission time Handle Problem Language Result Execution time Memory
93580 2019-01-09T21:08:41 Z vamaddur Calvinball championship (CEOI15_teams) C++14
90 / 100
1000 ms 756 KB
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <deque>
#include <string.h>
#include <sstream>
#include <bitset>
#include <math.h>
#include <assert.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
 
#define PI atan2(0, -1)
#define epsilon 1e-9
#define INF 5000000000000000000
#define MOD 1000000007
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
int N, arr [10010], maxi [10010];
long long M = 1000007, dp [2][10010], saves [10010], ret = 1;

int read_int(){
	char r;
	bool start=false,neg=false;
	int ret = 0;
	while(true){
		r=getchar();
		if((r-'0'<0 || r-'0'>9) && r!='-' && !start){
			continue;
		}
		if((r-'0'<0 || r-'0'>9) && r!='-' && start){
			break;
		}
		if(start)ret*=10;
		start=true;
		if(r=='-')neg=true;
		else ret+=r-'0';
	}
	if(!neg)
		return ret;
	else
		return -ret;
}
 
int main(){
    //freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
	//ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
	N = read_int(); fill(dp[0], dp[0]+N+1, 1); saves[0] = 1;
	for(int i = 0; i < N; i++){
			arr[i] = read_int();
			maxi[i+1] = max(maxi[i], arr[i]);
	}
	for(int i = 1; i < N; i++){
			for(int j = 0; j <= N; j++) dp[i%2][j] = (j*dp[(i-1)%2][j]+dp[(i-1)%2][j+1])%M;
			saves[i] = dp[i%2][maxi[N-1-i]];
	}
	for(int i = 0; i < N; i++) ret = (ret+(arr[i]-1)*saves[N-1-i])%M;
	cout << ret << '\n';
	return 0;
}
 
/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 376 KB Output is correct
2 Correct 12 ms 376 KB Output is correct
3 Correct 12 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 995 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 254 ms 640 KB Output is correct
2 Correct 257 ms 504 KB Output is correct
3 Correct 257 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1022 ms 756 KB Time limit exceeded
2 Halted 0 ms 0 KB -