QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#755242 | #7780. Dark LaTeX vs. Light LaTeX | Suhy | WA | 250ms | 19416kb | C++11 | 3.1kb | 2024-11-16 16:50:17 | 2024-11-16 16:50:18 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#pragma GCC optimize(3)
using namespace std;
const int maxn = 10004;
const int p1 = 30000037;
const int p2 = 30000091;
const int p3 = 28734753;
const int b1 = 91;
class Hsh
{
public:
static int mp1[33554432], mp2[33554432];
static const int b1 = 31, b2 = 29;
int n, hshv1[10005][5], phsh1[10005], hshv2[10005][5], phsh2[10005];
void Bld(int s[], int N)
{
phsh1[0] = phsh2[0] = 0;
n = N;
for(int i = 1; i <= n; i ++)
{
hshv1[i][0] = s[i];
hshv2[i][0] = s[i];
for(int j = 1; i + j <= n && j <= 4; j ++)
{
hshv1[i][j] = hshv1[i][j - 1] * b1 + s[i + j];
hshv2[i][j] = hshv2[i][j - 1] * b2 + s[i + j];
}
if(i + 4 <= n)
{
phsh1[i] = phsh1[i - 1] ^ hshv1[i][4];
phsh2[i] = phsh2[i - 1] ^ hshv2[i][4];
//cout<<phsh1[i]<<' '<<hshv1[i][4]<<endl;
}
}
}
int Get1(int l, int r)
{
if(r - l <= 4)
return hshv1[l][r - l];
else return phsh1[l - 1] ^ phsh1[r - 4];
}
int Get2(int l, int r)
{
if(r - l <= 4)
return hshv2[l][r - l];
else return phsh2[l - 1] ^ phsh2[r - 4];
}
int GetCnt(int l, int r)
{return min(mp1[Get1(l, r)], mp2[Get2(l, r)]);}
void ModMap(int w)
{
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= i; j ++)
{
mp1[Get1(j, i)] += w;
mp2[Get2(j, i)] += w;
}
}
}
};
int Hsh::mp1[33554432], Hsh::mp2[33554432];
int n, m;
int s[maxn], t[maxn];
ll ans;
Hsh hs, ht;
int f[maxn], cnt[maxn];
//babaa
void wok(int dlt)
{
for(int i = 2, l = 2 + dlt - n + 1, r = dlt; i < n; i ++, l ++)
{
int j = f[i - 1];
while(j > 0 && ((i + dlt > n && (i + dlt - j <= n || j + dlt >= n)) || s[j + 1 + dlt] != s[i + dlt]))
j = f[j];
if(s[j + 1 + dlt] == s[i + dlt])
j ++;
f[i] = j;
cnt[i] = 0;
if(j != 0) cnt[i] ++;
cnt[i] += cnt[j];
if(cnt[i] && l > 1 && r - l + 1 <= m)
ans += cnt[i] * hs.GetCnt(l, r);
}
}
void work(int w)
{
ht.ModMap(1);
for(int i = 1; i <= n; i ++)
s[i + n] = s[i];
for(int i = 1; i < n; i ++)
wok(i);
if(w) ht.ModMap(-1);
}
signed main()
{
char c = getchar();
while('a' <= c && c <= 'z')
s[++ n] = c - 'a' + 1, c = getchar();
while(!('a' <= c && c <= 'z'))
c = getchar();
while('a' <= c && c <= 'z')
t[++ m] = c - 'a' + 1, c = getchar();
hs.Bld(s, n);
ht.Bld(t, m);
work(1);
//cout<<"-----"<<endl;
swap(n, m);
for(int i = 1; i <= max(n, m); i ++)
swap(s[i], t[i]);
swap(hs, ht);
work(0);
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= i; j ++)
{
ans += hs.GetCnt(j, i);
}
}
cout<<ans<<endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7060kb
input:
abab ab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 19416kb
input:
abab abaaab
output:
29
result:
ok 1 number(s): "29"
Test #3:
score: 0
Accepted
time: 0ms
memory: 11212kb
input:
abcd abcde
output:
10
result:
ok 1 number(s): "10"
Test #4:
score: 0
Accepted
time: 2ms
memory: 7108kb
input:
aaba ba
output:
6
result:
ok 1 number(s): "6"
Test #5:
score: 0
Accepted
time: 0ms
memory: 17448kb
input:
babababaaabbaabababbbaabbbababbaaaaa aaaabbaababbab
output:
1161
result:
ok 1 number(s): "1161"
Test #6:
score: -100
Wrong Answer
time: 250ms
memory: 11292kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
2700855698091952
result:
wrong answer 1st numbers differ - expected: '78156256250000', found: '2700855698091952'