QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#507048 | #8521. Pattern Search II | ngpin04 | WA | 6ms | 9880kb | C++14 | 2.3kb | 2024-08-06 09:29:38 | 2024-08-06 09:29:38 |
Judging History
answer
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define bit(n) (1LL << (n))
#define getbit(x, i) (((x) >> (i)) & 1)
#define pii pair<int, int>
#define ALL(x) (x).begin(), (x).end()
#define sz(x) ((int) (x).size())
using namespace std;
const int M = 5e5 + 5;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int oo = 1e9;
const long long ooo = 1e18;
const double pi = acos(-1);
template<typename T1, typename T2> bool mini(T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}
typedef long long ll;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("file.inp", "r",stdin);
#endif
vector<string> str(60);
vector<vector<int>> ind(60);
str[0] = "b";
str[1] = "a";
ind[0].resize(1), ind[1] = ind[0];
ind[0][0] = 0;
ind[1][0] = 1;
int k = 29;
for (int i = 2; i < k; i++) {
str[i] = str[i - 1] + str[i - 2];
ind[i].resize(sz(str[i]));
ind[i][0] = i;
for (int j = 1; j < sz(str[i - 1]); j++) {
ind[i][j] = ind[i - 1][j];
}
for (int j = 0; j < sz(str[i - 2]); j++) {
ind[i][j + sz(str[i - 1])] = ind[i - 2][j];
}
}
string t; cin >> t;
vector<vector<int>> dp(sz(t) + 1, vector<int>(60, 0));
for (int i = 0; i < sz(t); i++) {
dp[i][0] = (t[i] == 'b');
dp[i][1] = (t[i] == 'a');
}
for (int j = 2; j < k; j++) {
for (int i = 0; i < sz(t); i++) {
dp[i][j] = dp[i][j - 1] + dp[i + dp[i][j - 1]][j - 2];
}
}
int ans = oo;
int n = sz(str[k - 1]), m = sz(t);
for (int i = 0; i < n; i++) {
int cur = 0, j = i;
while (cur < m && j < n) {
int mx = ind[k - 1][j];
while (mx > 0 && cur + dp[cur][mx - 1] == m) {
mx--;
}
cur += dp[cur][mx];
// cerr << cur << " " << mx << " " << dp[cur][mx] << "\n";
j += sz(str[mx]);
}
if (cur == m) {
mini(ans, j - i);
}
}
cout << ans << "\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 9736kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 6ms
memory: 9772kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9684kb
input:
b
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 3ms
memory: 9836kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: -100
Wrong Answer
time: 3ms
memory: 9880kb
input:
bb
output:
2
result:
wrong answer 1st numbers differ - expected: '3', found: '2'