QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#287601 | #7780. Dark LaTeX vs. Light LaTeX | 2018LZY | ML | 0ms | 0kb | C++14 | 2.0kb | 2023-12-20 20:07:47 | 2023-12-20 20:07:48 |
Judging History
answer
#include<bits/stdc++.h>
#define gc getchar()
#define TP template<class o>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define REP(i, a, b) for(int i = b; i >= a; i--)
#define FOR(i, n) rep(i, 1, n)
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define fd(i, a, b) for(int i = a; i >= b; i--)
using namespace std;
TP void qr(o &x) {
char c = gc; x = 0; int f = 1;
while(!isdigit(c)) {if(c == '-') f = -1; c = gc;}
while(isdigit(c)) x = x * 10 + c - '0', c = gc;
x *= f;
}
TP void qw(o x) {
if(x < 0) putchar('-'), x = -x;
if(x / 10) qw(x / 10);
putchar(x % 10 + '0');
}
TP void pr1(o x) {qw(x); putchar(' ');}
TP void pr2(o x) {qw(x); putchar('\n');}
#define ll long long
const int N = 5010, T = N * N;
int n, m;
char s[N], t[N];
int d[N][N];
ll val[N], ans;
int cnt;
map<char, int> tr[T];
void clear() {
while(cnt) val[cnt] = 0, tr[cnt--].clear();
cnt = 1;
}
int mat[N][N];
void calc(char *s, char *t, int n, int m, int v) {
memset(d, 0, sizeof d);
memset(mat, 0, sizeof mat);
REP(i, 1, n) {
rep(j, i + 1, n) {
mat[i][j] = s[i] == s[j] ? 1 + mat[i + 1][j + 1]: 0;
int l = mat[i][j];
d[j - 1][i + 1]++;
d[j - 1][i + l + 1]--;
}
}
FOR(i, n) {
d[i][0] = v;
FOR(j, i) d[i][j] += d[i][j - 1];
}
clear();
FOR(i, n) {
int p = 1;
rep(j, i, n) {
char c = s[j];
if(!tr[p][c]) tr[p][c] = ++cnt, p = cnt;
else p = tr[p][c];
val[p] += d[j][i];
}
}
FOR(i, m) {
int p = 1;
rep(j, i, m) {
char c = t[j];
if(!tr[p][c]) break;
p = tr[p][c];
ans += val[p];
}
}
}
void solve() {
scanf("%s %s", s + 1, t + 1);
n = strlen(s + 1);
m = strlen(t + 1);
calc(s, t, n, m, 0);
calc(t, s, m, n, 1);
pr2(ans);
}
int main() {
int T = 1;
// qr(T);
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
abab ab
output:
8