Submission #43832

# Submission time Handle Problem Language Result Execution time Memory
43832 2018-03-24T16:08:15 Z PowerOfNinjaGo Calvinball championship (CEOI15_teams) C++14
0 / 100
1000 ms 1864 KB
//Power Of Ninja Go
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
const int md = 1e6+7;
void add(int &a, int b)
{
    a += b;
    if(a>= md) a -= md;
}
int mul(int a, int b)
{
    return (1LL*a*b)%md;
}
const int maxn = 1e4+5;
int arr[maxn];
int dp[2][maxn];
int k[maxn];
int main()
{
    //#ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif
    int n; scanf("%d", &n);
    while(1)
    {
    for(int i = 1; i<= n; i++) scanf("%d", &arr[i]);
    for(int i = 1; i<= n; i++) k[i] = max(k[i], arr[i-1]);
    for(int i = 1; i<= n; i++) dp[(n+1)%2][i] = 1;
    int ans = 0;
    for(int i = n; i>= 1; i--)
    {
        int f = i%2;
        for(int j = 0; j<= i; j++)
        {
            dp[f][j] = dp[1-f][j+1];
            add(dp[f][j], mul(j, dp[1-f][j]));
            //printf("dp[%d][%d] = %d\n", i, j, dp[f][j]);
        }
        if(k[i]< arr[i])
        {
            add(ans, mul(k[i], dp[1-f][k[i]]));
        }
        else
        {
            add(ans, mul(arr[i]-1, dp[1-f][k[i]]));
        }
    }
    printf("%d\n", ans+1);
}
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:28:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n; scanf("%d", &n);
                           ^
teams.cpp:31:52: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i<= n; i++) scanf("%d", &arr[i]);
                                                    ^
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 1864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 1864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 1864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 1864 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 1864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 1864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 1864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 1864 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1056 ms 1864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1053 ms 1864 KB Time limit exceeded
2 Halted 0 ms 0 KB -