QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#586599#5051. Namomo SubsequencehcywoiWA 963ms277896kbC++234.3kb2024-09-24 14:26:032024-09-24 14:26:04

Judging History

你现在查看的是最新测评结果

  • [2024-09-24 14:26:04]
  • 评测
  • 测评结果:WA
  • 用时:963ms
  • 内存:277896kb
  • [2024-09-24 14:26:03]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

template<class T>
T qmi(T a, i64 b) {
    T res = 1;
    for (; b; b /= 2, a *= a) {
        if (b % 2) {
            res *= a;
        }
    }
    return res;
}

i64 mul(i64 a, i64 b, i64 p) {
    i64 res = a * b - i64(1.L * a * b / p) * p;
    res %= p;
    if (res < 0) {
        res += p;
    }
    return res;
}

template<int P>
struct modint {
    int x;
    constexpr modint() : x{} {}
    constexpr modint(i64 x) : x{norm(x % getmod())} {}

    static int mod;
    constexpr static int getmod() {
        if (P > 0) {
            return P;
        } else {
            return mod;
        }
    }
    constexpr static void setmod(int m) {
        mod = m;
    }
    constexpr int norm(int x) const {
        if (x < 0) {
            x += getmod();
        }
        if (x >= getmod()) {
            x -= getmod();
        }
        return x;
    }
    constexpr int val() const {
        return x;
    }
    explicit constexpr operator int() const {
        return x;
    }
    constexpr modint operator-() const {
        modint res;
        res.x = norm(getmod() - x);
        return res;
    }
    constexpr modint inv() const {
        assert(x != 0);
        return qmi(*this, getmod() - 2);
    }
    constexpr modint &operator*= (modint v) & {
        x = 1LL * x * v.x % getmod();
        return *this;
    }
    constexpr modint &operator+= (modint v) & {
        x = norm(x + v.x);
        return *this;
    }
    constexpr modint &operator-= (modint v) & {
        x = norm(x - v.x);
        return *this;
    }
    constexpr modint &operator/= (modint v) & {
        return *this *= v.inv();
    }
    friend constexpr modint operator- (modint a, modint b) {
        modint res = a;
        res -= b;
        return res;
    }
    friend constexpr modint operator+ (modint a, modint b) {
        modint res = a;
        res += b;
        return res;
    }
    friend constexpr modint operator* (modint a, modint b) {
        modint res = a;
        res *= b;
        return res;
    }
    friend constexpr modint operator/ (modint a, modint b) {
        modint res = a;
        res /= b;
        return res;
    }
    friend constexpr std::istream &operator>> (std::istream& is, modint& a) {
        i64 v;
        is >> v;
        a = modint(v);
        return is;
    }
    friend constexpr std::ostream &operator<< (std::ostream& os, const modint& a) {
        return os << a.val();
    }
    friend constexpr bool operator== (modint a, modint b) {
        return a.val() == b.val();
    }
    friend constexpr bool operator!= (modint a, modint b) {
        return a.val() != b.val();
    }
};

constexpr int P = 998244353;
using mint = modint<P>;

constexpr int B = 62;

int get(char c) {
    if (c >= 'A' && c <= 'Z') {
        return c - 'A';
    }
    if (c >= 'a' && c <= 'z') {
        return c - 'a' + 26;
    }
    return c - '0' + 52;
}

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

    std::string s;
    std::cin >> s;
    int n = s.size();

    std::vector<int> cnt(B);
    std::vector f(n, std::vector<mint>(B));
    std::vector s0(B, std::vector<mint>(B));
    std::vector s1(B, std::vector<mint>(B));
    for (int i = n - 1; i >= 0; i -- ) {
        int x = get(s[i]);
        for (int j = 0; j < B; j ++ ) {
            f[i][j] += s0[x][j];
        }
        for (int j = 0; j < B; j ++ ) {
            s0[j][x] += s1[j][x];
        }
        for (int j = 0; j < B; j ++ ) {
            s1[x][j] += cnt[j];
        }
        cnt[x] ++ ;
    }

    mint ans = 0;
    std::vector<int> sum(B);
    for (int i = 0; i < n; i ++ ) {
        int x = get(s[i]);

        mint c = 1LL * i * (i - 1) / 2;
        for (int j = 0; j < B; j ++ ) {
            c -= 1LL * sum[j] * (sum[j] - 1) / 2;
        }

        for (int j = 0; j < B; j ++ ) {
            if (x == j) {
                continue;
            }
            mint nc = c;
            nc -= sum[j] * (i - 1);
            nc += sum[j] * (sum[j] - 1);
            nc -= sum[x] * (i - 1);
            nc += sum[x] * (sum[x] - 1);
            nc += sum[j] * sum[x];
            ans += nc * f[i][j];
        }

        sum[x] ++ ;
    }

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

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3580kb

input:

wohaha

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

momomo

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

gshfd1jkhaRaadfglkjerVcvuy0gf

output:

73

result:

ok 1 number(s): "73"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

retiredMiFaFa0v0

output:

33

result:

ok 1 number(s): "33"

Test #5:

score: -100
Wrong Answer
time: 963ms
memory: 277896kb

input:

bcdccccacccabdbdaddcabddbaccaaaaaabaccbbbcbbddabcbccabacdacbcbabccbcbddcdcbcaaadddddccdbabaabcbbcaaadadacdaadbdccbddddabcbaaddbcadadcbcbaaccacabdababaabdccadaddacdcacdaabbadadaddbbcccbcddaccaadbbcaaccccdcacbdbdddbaccaacbcaccaaabccdadddbaabdbcaaccacdcdcbcdddacbcacdbbbdccdddccccabdbacddacbaacbbcaccdcd...

output:

438109674

result:

wrong answer 1st numbers differ - expected: '587599316', found: '438109674'