Submission #444501

# Submission time Handle Problem Language Result Execution time Memory
444501 2021-07-14T07:49:55 Z prvocislo Calvinball championship (CEOI15_teams) C++17
100 / 100
756 ms 568 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int maxn = 1e4+5, mod = 1e6 + 7;
//const int maxn = 5, mod = 1e6 + 7;
inline void upd(int &a, const int &b)
{
    a += b;
    if (a >= mod) a-= mod;
}
inline int mul(const int &a, const int &b)
{
    return (1ll * a * b) % (ll)(mod);
}
inline int add(const int &a, const int &b)
{
    int c = a + b;
    if (c >= mod) c -= mod;
    return c;
}
int dp[2][maxn][2]; 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); 
    int n; cin >> n;
    dp[0][0][1] = 1;
    for (int i = 0, x; i < n; i++)
    {
        cin >> x;
        int nw = ((i+1)&1), pv = (i&1);
        memset(dp[nw], 0, sizeof(dp[nw]));
        for (int t = 0; t <= i; t++) for (int fw = 0; fw < 2; fw++) if (dp[pv][t][fw])
        {
            int join = t;
            if (fw) 
            {
                join = min(join, x-1);
                if (t >= x) upd(dp[nw][t][fw], dp[pv][t][fw]); // patrim do timu x
            }
            upd(dp[nw][t][0], mul(dp[pv][t][fw], join));
            if (!fw || x >= t+1)
            {
                upd(dp[nw][t+1][fw&(x == t+1)], dp[pv][t][fw]);
            }
        }
    }
    int ans = 0;
    for (int t = 0; t <= n; t++) for (int fw = 0; fw < 2; fw++) upd(ans, dp[n&1][t][fw]);
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 568 KB Output is correct
2 Correct 4 ms 460 KB Output is correct
3 Correct 4 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 480 KB Output is correct
2 Correct 11 ms 468 KB Output is correct
3 Correct 11 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 735 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 460 KB Output is correct
2 Correct 201 ms 476 KB Output is correct
3 Correct 197 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 756 ms 460 KB Output is correct
2 Correct 746 ms 480 KB Output is correct
3 Correct 748 ms 500 KB Output is correct