QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#369811 | #2827. Autobiography | PetroTarnavskyi# | WA | 0ms | 3552kb | C++20 | 1.7kb | 2024-03-28 18:11:46 | 2024-03-28 18:11:48 |
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;
VI zFunction(const string& s)
{
int n = SZ(s);
VI z(n);
int l = 0;
int r = 0;
FOR(i, 1, n)
{
z[i] = 0;
if(i <= r)
z[i] = min(r - i + 1, z[i - l]);
while(i + z[i] < n && s[i + z[i]] == s[z[i]])
z[i]++;
if(i + z[i] - 1 > r)
{
r = i + z[i] - 1;
l = i;
}
}
return z;
}
VI prefixFunction(const string& s)
{
int n = SZ(s);
VI p(n);
p[0] = 0;
FOR(i, 1, n)
{
int j = p[i - 1];
while(j != 0 && s[i] != s[j])
j = p[j - 1];
if(s[i] == s[j]) j++;
p[i] = j;
}
return p;
}
const int INF = 1e9;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
string s, t;
while(cin >> s >> t)
{
VI zFunc = zFunction(t + "#" + s);
VI pFunc = prefixFunction(s + "#" + t);
int ans = pFunc.back();
VI dp(SZ(s) + 1, -INF);
FOR(i, 0, SZ(s))
{
int pos = i + SZ(t) + 1;
if(pos < SZ(zFunc) && zFunc[pos] == SZ(t))
{
dp[i] = i;
}
else if(i != 0)
{
dp[i] = dp[pFunc[i - 1]];
}
}
FOR(i, 0, SZ(s))
{
if(i)
cout << " ";
int res = max(ans, dp[i] + SZ(t));
if(res == SZ(s))
res = pFunc[SZ(s) - 1];
cout << res;
//cout << min(SZ(s) - 1, max(ans, dp[i] + SZ(t)));
}
cout << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3552kb
input:
5 4 bbobo 1 3 2 3 3 4 4 5 4 6 bobo 1 2 1 3 1 4 2 3 2 4 3 4 4 0 bobo
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
wrong answer 1st lines differ - expected: '2', found: '0'