QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#752795 | #7780. Dark LaTeX vs. Light LaTeX | yspm | TL | 0ms | 3828kb | C++20 | 2.4kb | 2024-11-16 09:48:58 | 2024-11-16 09:48:58 |
Judging History
answer
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx;
#define For(i,x,y,...) for(int i=x,##__VA_ARGS__;i<=(y);++i)
#define rFor(i,x,y,...) for(int i=x,##__VA_ARGS__;i>=(y);--i)
#define Rep(i,x,y,...) for(int i=x,##__VA_ARGS__;i<(y);++i)
#define pb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mkp make_pair
#define mem(a,x,n) memset(a,x,sizeof(*a)*(n+2))
typedef long long LL; typedef vector<int> Vi; typedef pair<int,int> Pii;
auto ckmax=[](auto &x,auto y) { return x<y ? x=y,true : false; };
auto ckmin=[](auto &x,auto y) { return y<x ? x=y,true : false; };
sfmt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r) { return uniform_int_distribution<>(l,r)(mt); }
const int N = 5e3+5;
int n,m;
char s[N],t[N];
LL ans;
struct Hash {
static const LL M = (1ll<<61)-1, B;
static vector<LL> pw;
vector<LL> h;
LL add(LL x,LL y) { return x+y<M ? x+y : x+y-M; }
LL mul(LL x,LL y) { __int128 z = (__int128)x*y; return add(z>>61,z&M); }
Hash(char s[]):h(strlen(s+1)+1) {
while( sz(pw) < sz(h) ) pw.pb(mul(pw.back(),B));
h[0] = 0; Rep(i,1,sz(h)) h[i] = add(mul(h[i-1],B),s[i]);
}
LL operator () (int l,int r) { return add(h[r],M-mul(h[l-1],pw[r-l+1])); }
};
const LL Hash::B = uniform_int_distribution<LL>(M/2,M-1)(mt);
vector<LL> Hash::pw = {1};
struct Ft {
int t[N*2];
void clr() { mem(t,0,n*2); }
void add(int i,int x) { for(;i;i-=i&-i)t[i]+=x; }
int sum(int i) { int res=0; for(;i<=2*n;i+=i&-i)res+=t[i]; return res; }
} ft;
void slv(bool op) {
n = strlen(s+1), m = strlen(t+1);
vector<Vi> f(n+2,Vi(n+2,0));
rFor(r,n,1) rFor(l,r,1) if( s[l] == s[r] ) f[l][r] = 1 + f[l+1][r+1];
// For(i,1,n) { For(j,i,n) cerr<<f[i][j]<<" "; cerr<<'\n'; }
Hash hs(s), ht(t);
map<LL,int> cnt;
rFor(r,n,1) {
ft.clr();
For(l,1,r) {
cnt[hs(l,r)] += ft.sum(l) + op;
// cerr<<l<<","<<r<<": "<<ft.sum(l) + op<<'\n';
ft.add(f[l][r+1]+l,1);
}
}
For(l,1,m) For(r,l,m) {
auto it = cnt.find(ht(l,r));
if( it != cnt.end() ) ans += it->se;
}
}
void MAIN() {
scanf("%s%s",s+1,t+1);
slv(0), swap(s,t), slv(1);
cout<<ans<<'\n';
} signed main() {
#ifdef FS
freopen("in","r",stdin); //freopen("out","w",stdout);
#endif
ios::sync_with_stdio(0);cin.tie(0);
int lft=1; while( lft-- ) {
MAIN();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
abab ab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
abab abaaab
output:
29
result:
ok 1 number(s): "29"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
abcd abcde
output:
10
result:
ok 1 number(s): "10"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
aaba ba
output:
6
result:
ok 1 number(s): "6"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
babababaaabbaabababbbaabbbababbaaaaa aaaabbaababbab
output:
1161
result:
ok 1 number(s): "1161"
Test #6:
score: -100
Time Limit Exceeded
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...