QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#280279#7780. Dark LaTeX vs. Light LaTeXucup-team045#WA 695ms297300kbC++205.0kb2023-12-09 14:54:102023-12-09 14:54:11

Judging History

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

  • [2024-11-25 20:53:52]
  • hack成功,自动添加数据
  • (/hack/1258)
  • [2023-12-09 14:54:11]
  • 评测
  • 测评结果:WA
  • 用时:695ms
  • 内存:297300kb
  • [2023-12-09 14:54:10]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<random>
#include<unordered_map>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const int maxn = 5005;
// uniform_int_distribution<ULL> dist(100, 1004535809 - 1);
const int base = 141431;

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<1004535809>;

int lcp[maxn][maxn];
int c1[maxn][maxn], c2[maxn][maxn];

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<chrono>
using namespace __gnu_pbds;

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);

    string s, t;
    cin >> s >> t;
    const int n = s.size(), m = t.size();
    s = " " + s;
    t = " " + t;
    {
        for(int i = n; i >= 1; i--){
            for(int j = n; j >= 1; j--){
                if (s[i] == s[j]){
                    lcp[i][j] = lcp[i + 1][j + 1] + 1;
                    if (j > i){
                        c1[j - 1][i + 1] += 1;
                        c1[j - 1][min(j - 1, i + lcp[i][j]) + 1] -= 1;
                    }
                }
            }
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= i; j++){
                c1[i][j] += c1[i][j - 1];
            }
        }
    }
    {
        memset(lcp, 0, sizeof lcp);
        for(int i = m; i >= 1; i--){
            for(int j = m; j >= 1; j--){
                if (t[i] == t[j]){
                    lcp[i][j] = lcp[i + 1][j + 1] + 1;
                    if (j > i){
                        c2[j - 1][i + 1] += 1;
                        c2[j - 1][min(j - 1, i + lcp[i][j]) + 1] -= 1;
                    }
                }
            }
        }
        for(int i = 1; i <= m; i++){
            for(int j = 1; j <= i; j++){
                c2[i][j] += c2[i][j - 1];
            }
        }
    }

    LL ans = 0;
    {
        gp_hash_table<int, LL> mp;
        for(int i = 1; i <= n; i++){
            mint h = 0;
            for(int j = i; j <= n; j++){
                h = h * base + int(s[j]);
                mp[h.val()] += c1[j][i] + 1;
            }
        }
        for(int i = 1; i <= m; i++){
            mint h = 0;
            for(int j = i; j <= m; j++){
                h = h * base + int(t[j]);
                if (mp.find(h.val()) != mp.end()){
                    ans += mp[h.val()];
                }
            }
        }
    }
    {
        gp_hash_table<int, LL> mp;
        for(int i = 1; i <= m; i++){
            mint h = 0;
            for(int j = i; j <= m; j++){
                h = h * base + int(t[j]);
                mp[h.val()] += c2[j][i];
            }
        }
        for(int i = 1; i <= n; i++){
            mint h = 0;
            for(int j = i; j <= n; j++){
                h = h * base + int(s[j]);
                if (mp.find(h.val()) != mp.end()){
                    ans += mp[h.val()];
                }
            }
        }
    }
    cout << ans << '\n';

}

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 103564kb

input:

abab
ab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 7ms
memory: 103580kb

input:

abab
abaaab

output:

29

result:

ok 1 number(s): "29"

Test #3:

score: 0
Accepted
time: 8ms
memory: 101784kb

input:

abcd
abcde

output:

10

result:

ok 1 number(s): "10"

Test #4:

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

input:

aaba
ba

output:

6

result:

ok 1 number(s): "6"

Test #5:

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

input:

babababaaabbaabababbbaabbbababbaaaaa
aaaabbaababbab

output:

1161

result:

ok 1 number(s): "1161"

Test #6:

score: 0
Accepted
time: 695ms
memory: 297300kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

78156256250000

result:

ok 1 number(s): "78156256250000"

Test #7:

score: -100
Wrong Answer
time: 56ms
memory: 167388kb

input:

gzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggz...

output:

60733598

result:

wrong answer 1st numbers differ - expected: '60716448', found: '60733598'