Submission #851039

# Submission time Handle Problem Language Result Execution time Memory
851039 2023-09-18T10:01:51 Z Nhoksocqt1 Calvinball championship (CEOI15_teams) C++17
30 / 100
346 ms 848 KB
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXN = 10004;
const int MOD = 1000007;

ll dp[2][MAXN][2], dp2[2][MAXN];
int a[MAXN], pref[MAXN], nArr;

ll powermod(ll a, int exponent) {
    ll res(1);
    while(exponent > 0) {
        if(exponent & 1)
            res = res * a % MOD;

        a = a * a % MOD;
        exponent >>= 1;
    }

    return res;
}

void process() {
    cin >> nArr;
    for (int i = 1; i <= nArr; ++i) {
        cin >> a[i];
        pref[i] = max(pref[i - 1], a[i]);
    }

    dp[1][1][0] = dp2[1][1] = 1;
    for (int i = 2; i <= nArr; ++i) {
        int cur(i & 1), pre(!cur);
        for (int j = 1; j <= pref[i - 1]; ++j) {
            for (int smaller = 0; smaller < 2; ++smaller) {
                if(!dp[pre][j][smaller])
                    continue;

                if(!smaller) {
                    dp[cur][j][1] = (dp[cur][j][1] + dp[pre][j][smaller] * min(j, a[i] - 1)) % MOD;
                    dp[cur][j][0] = (dp[cur][j][0] + dp[pre][j][smaller] * (j >= a[i])) % MOD;
                } else {
                    dp[cur][j][smaller] = (dp[cur][j][smaller] + dp[pre][j][smaller] * j) % MOD;
                }

                if((smaller || j + 1 <= a[i]) && (dp[cur][j + 1][smaller | (j + 1 < a[i])] += dp[pre][j][smaller]) >= MOD)
                    dp[cur][j + 1][smaller | (j + 1 < a[i])] -= MOD;

                dp[pre][j][smaller] = 0;
            }
        }

        for (int j = 1; j <= min(i - 1, pref[nArr] - 1); ++j) {
            if(!dp2[pre][j])
                continue;

            dp2[cur][j] = (dp2[cur][j] + dp2[pre][j] * j) % MOD;
            if((dp2[cur][j + 1] += dp2[pre][j]) >= MOD)
                dp2[cur][j + 1] -= MOD;

            dp2[pre][j] = 0;
        }
    }

    ll res = dp[nArr & 1][pref[nArr]][0] + dp[nArr & 1][pref[nArr]][1];
    for (int j = 1; j < pref[nArr]; ++j)
        res += dp2[nArr & 1][j];

    cout << res % MOD << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    process();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 346 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -