QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#443681 | #8521. Pattern Search II | ucup-team896# | WA | 40ms | 16816kb | C++20 | 1.5kb | 2024-06-15 16:17:25 | 2024-06-15 16:17:26 |
Judging History
answer
#pragma GCC optimize("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
const int maxn = 450010;
string s, t;
int n, m, a[maxn], b[maxn], to[maxn][2];
vector<pii> val;
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
s = "a"s, t = "b"s;
while (SZ(t) < 450000) {
string p = s + t;
t = s, s = p;
}
t.resize(450000);
cin >> s;
if (t.find(s) != t.npos) return cout << SZ(s) << '\n', 0;
n = SZ(s), m = SZ(t);
rep (i, 1, n) a[i] = s[i - 1] - 'a';
rep (i, 1, m) b[i] = t[i - 1] - 'a';
to[m + 1][0] = to[m + 1][1] = m + 1;
per (i, m, 1) {
to[i][0] = to[i + 1][0], to[i][1] = to[i + 1][1];
if (i != m) to[i][b[i + 1]] = i + 1;
}
rep (i, 1, m - n + 1) if (a[1] == b[i]) {
int pos = i;
rep (j, 1, min(n, 300)) pos = to[pos][a[j]];
val.emplace_back(pos - i, i);
}
sort(ALL(val));
int ans = 1e9;
for (auto [len, i] : val) {
if (clock() / CLOCKS_PER_SEC > 3.8) break;
int pos = i;
rep (j, 1, n) pos = to[pos][a[j]];
chkmn(ans, pos - i + 1);
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 40ms
memory: 16816kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5684kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5772kb
input:
b
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5844kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: -100
Wrong Answer
time: 23ms
memory: 12808kb
input:
bb
output:
4
result:
wrong answer 1st numbers differ - expected: '3', found: '4'