QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575189#1882. Drunkardsliaojiqing2012Compile Error//Python33.1kb2024-09-19 11:11:132024-09-19 11:11:18

Judging History

This is the latest submission verdict.

  • [2024-09-19 11:11:18]
  • Judged
  • [2024-09-19 11:11:13]
  • Submitted

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<stdint.h>
using namespace std;
using LL = long long;
template<const int T>
struct ModInt {
    const static int mod = T;
    int x;
    ModInt(int x = 0) : x(x % mod) {}
    ModInt(long long x) : x(int(x % mod)) {} 
    int val() { return x; }
    ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
    ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
    ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
    ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
    bool operator == (const ModInt &a) const { return x == a.x; };
    bool operator != (const ModInt &a) const { return x != a.x; };
    void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
    void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
    void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
    void operator /= (const ModInt &a) { *this = *this / a; }
    friend ModInt operator + (int y, const ModInt &a){ int x0 = y + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
    friend ModInt operator - (int y, const ModInt &a){ int x0 = y - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
    friend ModInt operator * (int y, const ModInt &a){ return ModInt(1LL * y * a.x % mod);}
    friend ModInt operator / (int y, const ModInt &a){ return ModInt(y) / a;}
    friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
    friend istream &operator>>(istream &is, ModInt &t){return is >> t.x;}

    ModInt pow(int64_t n) const {
        ModInt res(1), mul(x);
        while(n){
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }
    
    ModInt inv() const {
        int a = x, b = mod, u = 1, v = 0;
        while (b) {
            int t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        if (u < 0) u += mod;
        return u;
    }
    
};
using mint = ModInt<998244353>;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n, k;
    cin >> n >> k;
    mint p = mint(k) / 100;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    vector<mint> dp(2 * n + 1);
    dp[n] = 1;
    for(int i = n; i >= 1; i--){
        vector<mint> ndp(2 * n + 1);
        if (a[n-i+1] == 1){
            for(int j = 0; j <= 2 * n; j++){
                ndp[j] += dp[j] * p;
                if (j - 1 >= 0) ndp[j] += (1 - p) * dp[j - 1];
            }
        }
        else{
            for(int j = 0; j <= 2 * n; j++){
                ndp[j] += dp[j] * p;
                if (j + 1 <= 2 * n) ndp[j] += (1 - p) * dp[j + 1];
            }
        }
        dp.swap(ndp);
        dp[n] = 1;
    }
    
    mint ans = 0;
    for(int i = 0; i <= 2 * n; i++) ans += dp[i];
    cout << ans / (2 * n + 1) << '\n';

}

Details

  File "answer.code", line 16
    ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
                                                              ^
SyntaxError: invalid decimal literal