Submission #1116245

# Submission time Handle Problem Language Result Execution time Memory
1116245 2024-11-21T11:33:21 Z vjudge1 Calvinball championship (CEOI15_teams) C++17
10 / 100
595 ms 760 KB
#include <bits/stdc++.h>

using i64 = long long;

#ifdef DEBUG 
    #include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
    #define debug(...) void(23)
#endif

template<typename T>
T power(T a, i64 b) {
    T res = 1;
    while(b) {
        if(b & 1) {
            res *= a;
        }
        a *= a;
        b >>= 1;
    }
    return res;
}
 
constexpr int md = int(1E6) + 7;
struct MInt {
    int val;
    MInt() : val(0) {}
    template<typename T>
    MInt(T v) {
        if(-md <= v && v < md) {
            val = v;
        } else {
            val = v % md;
        }
        if(val < 0) {
            val += md;
        }
    }
    int operator() () { return val; }
    MInt operator+= (MInt rhs) {
        if((val += rhs.val) >= md) {
            val -= md;
        }
        return *this;
    }
    MInt operator-= (MInt rhs) {
        if((val -= rhs.val) < 0) {
            val += md;
        }
        return *this;
    }
    MInt operator*= (MInt rhs) {
        val = (int)(1LL * val * rhs.val % md);
        return *this;
    }
    MInt inv() {
        return power(*this, md - 2);
    }
    MInt operator/= (MInt rhs) {
        return *this *= rhs.inv();
    }
    bool operator== (MInt rhs) {
        return val == rhs.val;
    }
    bool operator!= (MInt rhs) {
        return val != rhs.val;
    }
};
MInt operator+ (MInt lhs, MInt rhs) {
    return lhs += rhs;
}
MInt operator- (MInt lhs, MInt rhs) {
    return lhs -= rhs;
}
MInt operator* (MInt lhs, MInt rhs) {
    return lhs *= rhs;
}
MInt operator/ (MInt lhs, MInt rhs) {
    return lhs /= rhs;
}
std::ostream& operator<< (std::ostream& os, MInt v) {
    return os << v();
}
std::string to_string(MInt x) {
    return to_string(x());
}
 
using Z = MInt;

constexpr int max_N = int(1E4) + 5;

int N, A[max_N];

Z dp[2][2][max_N];

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin >> N;
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
    }

    dp[0][0][0] = 1;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < max_N; ++j) {
            dp[1][0][j] = dp[1][1][j] = 0;
        }

        for (int j = 0; j < max_N; ++j) {
            if (dp[0][0][j] != 0) {
                dp[1][1][1] += dp[0][0][j];
                dp[1][1][std::min(j + 1, A[i] - 1) + 1] -= dp[0][0][j];
                if (j + 1 >= A[i]) {
                    dp[1][0][std::max(j, A[i])] += dp[0][0][j];
                    dp[1][0][std::max(j, A[i]) + 1] -= dp[0][0][j];
                }
            }
            if (dp[0][1][j] != 0) {
                dp[1][1][1] += dp[0][1][j];
                dp[1][1][std::min(j + 1, N) + 1] -= dp[0][1][j];
            }
        }

        for (int i = 0; i <= N; ++i) {
            dp[1][0][i + 1] += dp[1][0][i];
            dp[1][1][i + 1] += dp[1][1][i];
        }
        
        std::swap(dp[0], dp[1]);
    }

    Z ans = 0;
    for (int i = 0; i <= N; ++i) {
        ans += dp[0][0][i] + dp[0][1][i];
    }

    std::cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 760 KB Output is correct
2 Incorrect 1 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 577 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 230 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 595 ms 644 KB Output isn't correct
2 Halted 0 ms 0 KB -