Submission #244449

# Submission time Handle Problem Language Result Execution time Memory
244449 2020-07-04T06:13:31 Z tqbfjotld Calvinball championship (CEOI15_teams) C++14
100 / 100
677 ms 888 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int mem[10005][2][2];
int memb[2];


int n;
int MOD = 1000007LL;
int arr[10005];
int hbound[100005];

main(){
    scanf("%lld",&n);
    for (int x = 0; x<n; x++){
        scanf("%lld",&arr[x]);
        hbound[x] = x==0?1:max(hbound[x-1],arr[x]);
        //printf("%lld\n",hbound[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<1; 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]);
            }

        }
        if (x==n-1){
                memb[0] = arr[x];
            }
            else{
            memb[0] = mem[x==0?0:hbound[x-1]][0][1]*(arr[x]-1);
            //printf("test %lld\n",mem[x==0?0:hbound[x-1]][0][1]);
            memb[0] %= MOD;
        //printf("bound %lld %lld\n",x,memb[0]);
            memb[0] += memb[1];
            memb[0] %= MOD;
            }
        //printf("bound %lld %lld\n",x,memb[0]);
        for (int h = 1; h<=x+1; h++){
            mem[h][0][1] = mem[h][0][0];
            mem[h][0][0] = 0;
        }
            memb[1] = memb[0];
            memb[0] = 0;
           // printf("memb1 %lld\n",memb[1]);
    }
    printf("%lld",memb[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

teams.cpp:14:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
teams.cpp: In function 'int main()':
teams.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
teams.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&arr[x]);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 7 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 640 KB Output is correct
2 Correct 11 ms 640 KB Output is correct
3 Correct 11 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 655 ms 836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 760 KB Output is correct
2 Correct 171 ms 760 KB Output is correct
3 Correct 172 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 675 ms 888 KB Output is correct
2 Correct 677 ms 888 KB Output is correct
3 Correct 677 ms 888 KB Output is correct