Submission #873337

# Submission time Handle Problem Language Result Execution time Memory
873337 2023-11-14T21:05:30 Z bobbilyking Calvinball championship (CEOI15_teams) C++17
70 / 100
12 ms 16732 KB
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;

#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = (l); i < r; ++i)

#define NN 1010
#define M 1000007 // 998244353

ll dp[NN][NN];

int main(){
//    freopen("a.in", "r", stdin);
//    freopen("a.out", "w", stdout);

    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(20);
    
    fill(dp[0], dp[0]+NN, 1ll);
    F(i, 1, NN) F(l, 1, NN-1) {
        dp[i][l] = (l * dp[i-1][l] + dp[i-1][l+1])%M; 
    }

    ll mx = 1;
    ll answer = 1;
    G(n) for (ll left = n-1; left >= 0; --left) {
        G(x)
        if (x <= mx) {
            // max didn't change, so normal
            answer = (answer + (x-1) * dp[left][mx])%M;
        } else {
            // max changes at the last second; 
            assert(mx + 1 == x);
            answer = (answer + mx * dp[left][mx])%M;
        }
        mx = max(mx, x);

        
    }
    cout << answer << '\n';

    
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8540 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8400 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8600 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8440 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 16660 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 16732 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 16732 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -