QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#225376 | #7521. Find the Gap | PetroTarnavskyi# | WA | 6ms | 33484kb | C++17 | 2.8kb | 2023-10-24 16:15:19 | 2023-10-24 16:15:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
int add(int a, int b, int mod)
{
return a + b < mod ? a + b : a + b - mod;
}
int sub(int a, int b, int mod)
{
return a - b >= 0 ? a - b : a - b + mod;
}
void updAdd(int& x, int val, int mod)
{
x += val;
if (x >= mod)
x -= mod;
}
void updSub(int& x, int val, int mod)
{
x -= val;
if (x < 0)
x += mod;
}
int mult(int a, int b, int mod)
{
return (LL)a * b % mod;
}
const int M = 998'244'353;
const int N = 1 << 20;
struct Pair
{
static constexpr int mod[2] = {1'000'000'007, 1'000'000'009};
int a[2];
Pair(int x = 0)
{
FOR(i, 0, 2)
a[i] = x;
}
Pair operator+(const Pair& p) const
{
Pair res;
FOR(i, 0, 2)
res.a[i] = add(a[i], p.a[i], mod[i]);
return res;
}
Pair operator-(const Pair& p) const
{
Pair res;
FOR(i, 0, 2)
res.a[i] = sub(a[i], p.a[i], mod[i]);
return res;
}
Pair operator*(const Pair& p) const
{
Pair res;
FOR(i, 0, 2)
res.a[i] = mult(a[i], p.a[i], mod[i]);
return res;
}
bool operator==(const Pair& p) const
{
FOR(i, 0, 2)
if (a[i] != p.a[i])
return false;
return true;
}
};
Pair pw[N];
Pair prefHash[2][N];
int f[N];
int dp[N][3], sum[N][3];
void calcHash(const string& s, int j)
{
FOR(i, 0, SZ(s))
prefHash[j][i + 1] = prefHash[j][i] + pw[i] * (s[i] - 'a' + 1);
}
Pair getHash(int j, int l, int r)
{
return (prefHash[j][r] - prefHash[j][l]) * pw[N - 1 - r];
}
int getLCP(const string& s, int i, const string& t, int j)
{
int l = 0, r = min(SZ(s) - i, SZ(t) - j) + 1;
while (r - l > 1)
{
int m = (l + r) / 2;
if (getHash(0, i, i + m) == getHash(1, j, j + m))
l = m;
else
r = m;
}
return l;
}
void calcF(const string& s, const string& t)
{
FOR(i, 0, SZ(s))
{
int len = getLCP(s, i, t, 0);
f[i] = len + 1 + getLCP(s, i + len + 1, t, len + 1);
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
string s, t;
cin >> s >> t;
pw[0] = 1;
FOR(i, 1, N)
pw[i] = pw[i - 1] * 47;
calcHash(s, 0);
calcHash(t, 1);
calcF(s, t);
dp[0][0] = 1;
FOR(i, 0, SZ(s))
{
FOR(j, 0, 3)
updAdd(dp[i][j], sum[i][j], M);
int d[3] = {dp[i][0], add(dp[i][1], dp[i][0], M), add(dp[i][2], add(mult(2, dp[i][1], M), dp[i][0], M), M)};
FOR(j, 0, 3)
{
updAdd(sum[i + 1][j], d[j], M);
updSub(sum[i + f[i]][j], d[j], M);
}
}
cout << dp[SZ(s)][2] << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 33484kb
input:
8 1 1 1 1 1 2 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1 2 2 2
output:
0
result:
wrong answer 1st numbers differ - expected: '1.0000000', found: '0.0000000', error = '1.0000000'