QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#302386 | #7780. Dark LaTeX vs. Light LaTeX | zzuqy | WA | 1ms | 5988kb | C++14 | 3.2kb | 2024-01-10 20:17:25 | 2024-01-10 20:17:27 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <deque>
#include <unordered_map>
#include <map>
#define P 31525197391593473ll
#define ll long long
#define l(p) t[p].l
#define sum(p) t[p].sum
#define cnt(p) t[p].cnt
#define r(p) t[p].r
#define mod 998244353
#define sc(A) scanf("%d",&A)
#define rep(A,B,C) for(int C=A;C<=B;++C)
#define fep(A,B,C) for(int C=A;C>=B;--C)
#define put(x) printf("%d\n",x)
#define db double
using namespace std;
const int MAXN = 5010,N=10000007;
int n, m, q, x, maxx = 62, top;
char a[MAXN], b[MAXN];
int nex[MAXN];
int w[MAXN];
int c1[MAXN][MAXN];
int c2[MAXN][MAXN];
struct wy
{
int lin[N],nex[MAXN*MAXN],e[MAXN*MAXN];
ll ver[MAXN*MAXN];
int len=0;
inline void add(ll y)
{
int x=y%N;
ver[++len]=y;
nex[len]=lin[x];
lin[x]=len;
e[len]=1;
}
int find(ll y,int w)
{
int x=y%N;
for(int i=lin[x];i;i=nex[i])
{
int tn=ver[i];
if(tn==y){e[i]+=w;return e[i];}
}
return 0;
}
}H,H1;
signed main() {
//freopen("1.in", "r", stdin);
//freopen("1.out", "w", stdout);
scanf("%s", a + 1);
scanf("%s", b + 1);
int n = strlen(a + 1);
int m = strlen(b + 1);
rep(1, n, i) {
int base1 = 29;
int base2 = 114514;
unsigned ll s2 = 0;
ll s1 = 0;
rep(i, n, j) {
s1 = ((ll)s1 * base1 + a[j]) % P;
//s2=s2*base2+a[j];
if(H.find(s1,1)==0)H.add(s1);
//++H[make_pair(s2,s1)];
}
}
ll ans = 0;
rep(1, m, i) {
int base1 = 29;
int base2 = 114514;
unsigned ll s2 = 0;
ll s1 = 0;
rep(i, m, j) {
s1 = ((ll)s1 * base1 + b[j]) % P;
//s2=s2*base2+b[j];
c2[i][j]=H.find(s1,0);
ans +=c2[i][j];
if(H1.find(s1,1)==0)H1.add(s1);
//ans+=H[make_pair(s2,s1)];
//c2[i][j]=H[make_pair(s2,s1)];
//++H1[make_pair(s2,s1)];
}
}
rep(1, n, i) {
int base1 = 29;
int base2 = 114514;
unsigned ll s2 = 0;
ll s1 = 0;
rep(i, n, j) {
s1 = ((ll)s1 * base1 + a[j]) % P;
//s2=s2*base2+a[j];
//c1[i][j]=H1[make_pair(s2,s1)];
c1[i][j] = H1.find(s1,0);
}
}
rep(2, n-1, j) {
int now = j;
w[j + 1] = 1;
w[j] = 0;
nex[j + 1] = j;
nex[j]=j;
rep(j + 2, min(2 * j, n), i) {
while (now != j && a[i] != a[now + 1])
now = nex[now];
if (a[i] == a[now + 1])
++now;
nex[i] = now;
w[i] = w[now] + 1;
}
now = j;
rep(1, j - 1, i) {
while (now != j && a[i] != a[now + 1])
now = nex[now];
if (a[i] == a[now + 1])
++now;
ans += (ll)w[now] * c1[i + 1][j];
if (now == n)
now = nex[now];
}
}
memset(nex, 0, sizeof(nex));
rep(2, m-1, j) {
int now = j;
w[j + 1] = 1;
w[j] = 0;
nex[j + 1] = j;
nex[j]=j;
rep(j + 2, min(2 * j, m), i) {
while (now != j && b[i] != b[now + 1])
now = nex[now];
if (b[i] == b[now + 1])
++now;
nex[i] = now;
w[i] = w[now] + 1;
}
now = j;
rep(1, j - 1, i) {
while (now != j && b[i] != b[now + 1])
now = nex[now];
if (b[i] == b[now + 1])
++now;
ans += (ll)w[now] * c2[i + 1][j];
if (now == m)
now = nex[now];
}
}
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3964kb
input:
abab ab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 1ms
memory: 4012kb
input:
abab abaaab
output:
29
result:
ok 1 number(s): "29"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
abcd abcde
output:
10
result:
ok 1 number(s): "10"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
aaba ba
output:
6
result:
ok 1 number(s): "6"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 5988kb
input:
babababaaabbaabababbbaabbbababbaaaaa aaaabbaababbab
output:
1135
result:
wrong answer 1st numbers differ - expected: '1161', found: '1135'