Submission #1081643

# Submission time Handle Problem Language Result Execution time Memory
1081643 2024-08-30T08:44:15 Z Victor Calvinball championship (CEOI15_teams) C++17
100 / 100
344 ms 1668 KB
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define per(i, a, b) for (ll i = (b) - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) (ll)x.size()
#define pb push_back
#define debug(x) cout<<#x<<" = "<<x<<endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;

const ll INF = 1'000'007;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    ll n;
    cin>>n;
    vll order(n);
    rep(i,0,n) cin>>order[i];

    vector<vll> dp(n+1,vll(2,0)),dp2(n+1,vll(2,0));
    dp[0][1]=1;
    rep(i,0,n) {
        rep(j,0,i+1) {
            dp2[j][0]=(dp2[j][0]+dp[j][0]*j)%INF;
            dp2[j+1][0]=(dp2[j+1][0]+dp[j][0])%INF;

            if(j+1==order[i]) dp2[j+1][1]=(dp2[j+1][1]+dp[j][1])%INF;
            else dp2[j][1]=(dp2[j][1]+dp[j][1])%INF;
            dp2[j][0]=(dp2[j][0]+dp[j][1]*(order[i]-1))%INF;

            dp[j][0]=0;
            dp[j][1]=0;
        }

        dp.swap(dp2);
    }

    ll ans=0;
    rep(i,0,n+1) rep(j,0,2) ans=(ans+dp[i][j])%INF;
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 856 KB Output is correct
2 Correct 79 ms 860 KB Output is correct
3 Correct 79 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 344 ms 1620 KB Output is correct
2 Correct 335 ms 1656 KB Output is correct
3 Correct 335 ms 1668 KB Output is correct