# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244443 | tqbfjotld | Calvinball championship (CEOI15_teams) | C++14 | 1096 ms | 760 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mem[10005][2][2];
int n;
int MOD = 1000007LL;
int arr[10005];
main(){
scanf("%lld",&n);
for (int x = 0; x<n; x++){
scanf("%lld",&arr[x]);
}
memset(mem,-1,sizeof(mem));
for (int x = n-1; x>=0; x--){
for (int high = 1; high<=x+1; high++){
for (int bound = 0; bound<2; bound++){
if (x == n-1){
mem[high][bound][0] = bound?arr[x]:high+1;
//printf("pos %lld high %lld bound %lld: %lld\n",x,high,bound,mem[high][bound][0]);
continue;
}
if (bound){
mem[high][bound][0] = mem[max(high,arr[x]-1)][0][1]*(arr[x]-1);
mem[high][bound][0] %= MOD;
mem[high][bound][0] += mem[max(high,arr[x])][1][1];
mem[high][bound][0] %= MOD;
}
else{
mem[high][bound][0] = high*mem[high][0][1];
mem[high][bound][0]%=MOD;
mem[high][bound][0] += mem[high+1][0][1];
mem[high][bound][0] %= MOD;
}
//printf("pos %lld high %lld bound %lld: %lld\n",x,high,bound,mem[high][bound][0]);
}
}
for (int h = 1; h<=x+1; h++){
mem[h][0][1] = mem[h][0][0];
mem[h][1][1] = mem[h][1][0];
mem[h][0][0] = 0;
mem[h][1][0] = 0;
}
}
printf("%lld",mem[1][1][1]);
}
/*
1 1 1 1
1 1 1 2
1 1 2 1
1 1 2 2
1 1 2 3
1 2 1 1
1 2 1 2
1 2 1 3
1 2 2 1
1 2 2 2
1 2 2 3
1 2 3 1
1 2 3 2
1 2 3 3
1 2 3 4
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |