Submission #1053614

# Submission time Handle Problem Language Result Execution time Memory
1053614 2024-08-11T14:21:44 Z VMaksimoski008 Calvinball championship (CEOI15_teams) C++17
100 / 100
415 ms 856 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int mod = 1e6 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;

int dp[2][10005][2];

signed main() {
    int n;
    cin >> n;

    vector<int> v(n+1);
    for(int i=1; i<=n; i++) cin >> v[i];

    dp[0][1][0] = 1;
    for(int a=1; a<n; a++) {
        for(int b=1; b<=a; b++) {
            for(int c=0; c<2; c++) {
                if(c) {
                    dp[1][b][1] = (dp[1][b][1] + b * dp[0][b][1]) % mod;
                    dp[1][b+1][1] = (dp[1][b+1][1] + dp[0][b][1]) % mod;
                    continue;
                }

                int mx = min(b+1, v[a+1]);
                if(v[a+1] <= b) dp[1][b][0] = (dp[1][b][0] + dp[0][b][0]) % mod;
                if(v[a+1] == b + 1) dp[1][b+1][0] = (dp[1][b+1][0] + dp[0][b][0]) % mod;

                if(v[a+1] <= b) dp[1][b][1] = (dp[1][b][1] + (v[a+1] - 1) * dp[0][b][0]) % mod;
                if(v[a+1] == b + 1) dp[1][b][1] = (dp[1][b][1] + b * dp[0][b][0]) % mod;

                if(v[a+1] > b + 1) {
                    dp[1][b][1] = (dp[1][b][1] + b * dp[0][b][0]) % mod;
                    dp[1][b+1][1] = (dp[1][b+1][1] + dp[0][b][0]) % mod;
                }
            }
        }

        for(int b=1; b<=n; b++) {
            for(int c=0; c<2; c++) {
                dp[0][b][c] = dp[1][b][c];
                dp[1][b][c] = 0;
            }
        }
    }

    long long ans = 0;
    for(int i=1; i<=n; i++) ans = (ans + dp[0][i][1]) % mod;
    cout << (ans + 1) % mod << '\n';
    return 0;
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:28:21: warning: unused variable 'mx' [-Wunused-variable]
   28 |                 int mx = min(b+1, v[a+1]);
      |                     ^~
# 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
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 0 ms 348 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 344 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 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 6 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 604 KB Output is correct
2 Correct 92 ms 604 KB Output is correct
3 Correct 107 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 373 ms 604 KB Output is correct
2 Correct 415 ms 840 KB Output is correct
3 Correct 404 ms 856 KB Output is correct