QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#280278 | #7780. Dark LaTeX vs. Light LaTeX | ucup-team045# | WA | 690ms | 296720kb | C++20 | 5.0kb | 2023-12-09 14:53:48 | 2023-12-09 14:53:48 |
Judging History
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 = 1421233;
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: 3ms
memory: 103780kb
input:
abab ab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 103548kb
input:
abab abaaab
output:
29
result:
ok 1 number(s): "29"
Test #3:
score: 0
Accepted
time: 3ms
memory: 101528kb
input:
abcd abcde
output:
10
result:
ok 1 number(s): "10"
Test #4:
score: 0
Accepted
time: 0ms
memory: 103488kb
input:
aaba ba
output:
6
result:
ok 1 number(s): "6"
Test #5:
score: 0
Accepted
time: 4ms
memory: 105776kb
input:
babababaaabbaabababbbaabbbababbaaaaa aaaabbaababbab
output:
1161
result:
ok 1 number(s): "1161"
Test #6:
score: 0
Accepted
time: 690ms
memory: 296720kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
78156256250000
result:
ok 1 number(s): "78156256250000"
Test #7:
score: -100
Wrong Answer
time: 56ms
memory: 166436kb
input:
gzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggzggzgzggzggzgzggzgzggz...
output:
60717407
result:
wrong answer 1st numbers differ - expected: '60716448', found: '60717407'