Submission #131105

# Submission time Handle Problem Language Result Execution time Memory
131105 2019-07-16T13:13:22 Z arthurconmy Calvinball championship (CEOI15_teams) C++14
70 / 100
72 ms 65540 KB
/* Arthur Conmy / arthurconmy */
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
#include <chrono>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<int,int> pii;
#define REP(i, a, b) for (ll i = ll(a); i <= ll(b); i++)
#define REPb(j, d, c) for (ll j = ll(d); j >= ll(c); j--)
#define ff first
#define ss second
#define pb push_back
#define len(x) int((x).size())
#define endl "\n"
 
const ll MAXN=10001;
const ll p=1000007;
ll A[MAXN];
ll sz[MAXN][MAXN];
ll pos[MAXN][MAXN];
 
int main() // LL OR INT??
{
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif
 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 
	ll n;
	cin>>n;
 
	if(n==1)
	{
		cout << 1 << endl;
		return 0;
	}
 
	ll thing_max=1;
 
	REP(i,1,n)
	{
		ll a;
		cin>>a;
		A[i]=a;
		thing_max=max(thing_max,a);
	}
 
	sz[1][1]=ll(1);
	pos[1][1]=ll(1);
 
	bool just_ones=1;
	ll cur_max=1;
 
	REP(i,2,n)
	{
		sz[i][1]=1;
		if(just_ones&&A[i]==1) pos[i][1]=0;
		else
		{
			just_ones=0;
			pos[i][1]=1;
		}
 
		// int j=1;
		// cout << i << " " << j << " " << pos[i][j] << endl;
 
		REP(j,2,i-1)
		{
			sz[i][j]=sz[i-1][j-1]+j*sz[i-1][j];
			sz[i][j]%=p;
 
			pos[i][j]=pos[i-1][j-1]
					 +j*pos[i-1][j]
					 +ll(j==cur_max)*(A[i]-1);
 
			pos[i][j]%=p;
		
			// cout << i << " " << j << " " << pos[i][j] << endl;
		}
 
		// cout << i << " " << i << " " << pos[i][i] << endl; 
      	pos[i][i]=0;
        sz[i][i]=1;
	
		cur_max=max(cur_max,A[i]);
	}
 
	ll ans=0;
 
	REP(j,1,n)
	{
		ans+=pos[n][j];
		ans%=p;
	}
 
	ans++;
	ans%=p;
 
	cout << ans << endl;
}
# 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
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 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 504 KB Output is correct
2 Correct 2 ms 548 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6392 KB Output is correct
2 Correct 7 ms 6520 KB Output is correct
3 Correct 7 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16516 KB Output is correct
2 Correct 16 ms 16504 KB Output is correct
3 Correct 16 ms 16504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 72 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 68 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 70 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -