QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#461129 | #4275. Escape Sequences | propane | WA | 1ms | 4088kb | C++20 | 2.3kb | 2024-07-02 16:14:41 | 2024-07-02 16:14:41 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;
vector<int> z_algorithm(const string &s){
int n = s.size();
vector<int> a(n);
a[0] = n;
for(int i = 1, l = 0, r = 0; i < n; i++){
if (i <= r) a[i] = min(a[i - l], r - i + 1);
while(i + a[i] < n && s[i + a[i]] == s[a[i]]) ++a[i];
if (i + a[i] - 1 > r) l = i, r = i + a[i] - 1;
}
return a;
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
string s, t;
cin >> s >> t;
if (t == string(t.size(), 'a')){
int ans = 1e9;
{
int cnt = 0;
int len = 0;
while(len < t.size()){
cnt += 1;
len = len * 2 + 1;
}
ans = min(ans, cnt);
}
for(int i = 0; i < s.size(); i++){
if (s[i] == 'b') continue;
int j = i;
while(j + 1 < s.size() and s[j + 1] == 'a') j++;
int len = j - i + 1;
int cnt = 0;
while(len < t.size()){
len = len * 2 + (j + 1 != s.size());
cnt += 1;
}
ans = min(ans, cnt);
i = j;
}
cout << ans << '\n';
return 0;
}
for(int i = 0; i < 19; i++){
vector<int> bad(1 << i);
for(int j = 0; j < t.size(); j++){
if (t[j] == 'b'){
bad[j % (1 << i)] = 1;
}
}
vector<int> v;
for(int j = 0; j < 1 << i; j++){
if (bad[j]){
v.push_back(j);
}
}
if (v.size() > 1) continue;
int st = v[0];
string str;
for(int j = st; j < t.size(); j += (1 << i)){
str += t[j];
}
auto z = z_algorithm(str + " " + s);
for(int j = str.size() + 1; j < z.size(); j++){
if (z[j] >= str.size()){
if (j + 1 != z.size() or st + 1 == (1 << i)){
cout << i << '\n';
return 0;
}
}
}
}
cout << -1 << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3536kb
input:
b ab
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
ababa bab
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 4088kb
input:
a b
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
abbb baa
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
abaabb abaab
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3548kb
input:
aaab aaba
output:
1
result:
wrong answer 1st numbers differ - expected: '-1', found: '1'