QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#644502 | #7618. Pattern Search | ucup-team4479# | WA | 66ms | 3644kb | C++23 | 2.5kb | 2024-10-16 14:19:06 | 2024-10-16 14:19:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int sbac[30], tbac[30];
void solve() {
string s, t;
cin >> s >> t;
int n = s.length(), m = t.length();
for (int i = 0; i < n; ++i) sbac[s[i] - 'a']++;
for (int i = 0; i < m; ++i) tbac[t[i] - 'a']++;
bool flag = 1;
string one = "", two = "", thr = "";
for (int i = 0; i < 26; ++i) {
char ch = 'a' + i;
if (tbac[i] % 3 == 1) {
flag = 0;
break;
}
}
int border = 0;
int cir = 0;
for (int len = 1; len <= m / 3; ++len) {
if (m % len) continue;
int k = m / len;
bool flag = 1;
for (int i = 0; i < 26; ++i) {
if (tbac[i] % k) {
flag = 0;
break;
}
}
if (flag) {
cir = len;
break;
}
}
if (cir) {
string c = "";
int k = m / cir;
for (int i = 0; i < 26; ++i) {
char ch = 'a' + i;
while (tbac[i] >= k) {
c = c + ch;
tbac[i] -= k;
}
}
t = "";
// cout << c << endl;
for (int i = 0; i < k; ++i)
t = t + c;
border = m - cir;
} else if (!flag) {
two = "";
for (int i = 0; i < 26; ++i) {
char ch = 'a' + i;
if (tbac[i] & 1) one = one + ch;
while (tbac[i] >= 2) {
tbac[i] -= 2;
two = two + ch;
}
}
t = two + one + two;
border = two.length();
} else {
two = thr = "";
for (int i = 0; i < 26; ++i) {
char ch = 'a' + i;
if (tbac[i] % 3 == 2) two = two + ch;
while (tbac[i] >= 3) {
tbac[i] -= 3;
thr = thr + ch;
}
}
t = thr + two + thr + two + thr;
border = thr.length() * 2 + two.length();
}
// cout << t << " " << border << endl;
int now = 0, ans = 0;
for (int i = 0; i < n; ++i) {
if (sbac[t[now] - 'a']) {
sbac[t[now] - 'a']--;
if (now == m - 1) ans++, now = border;
else now++;
} else break;
}
cout << ans << endl;
for (int i = 0; i < 26; ++i) sbac[i] = tbac[i] = 0;
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cout.tie(0);
int T;
cin >> T;
while (T--) solve();
return 0;
}
/*
3
bajkaaaabbbb aaabbb
bajkaaall aal
abca cba
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
2 bajkaaall aal abca cba
output:
2 1
result:
ok 2 number(s): "2 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
16 a a a b b a aa a ab aa ab b ab c aaz az abcde edcba aaaaaaaaaaaabbb aaaaaaaaabb aaaaaazz az aaaaaaaaaz zzzzz gggggggggggggggggggge ggggeeee hyphyphyphyphyphyphyphyphyphyphyphyp eeeeeeeeee hyphyphyphyphyphyphyphyphyphyphyphype eeteeteeteet aaaabbbbbbcccccccc aaabbbbbcccccc
output:
1 0 0 2 0 1 0 1 1 2 2 0 0 0 0 1
result:
ok 16 numbers
Test #3:
score: -100
Wrong Answer
time: 66ms
memory: 3616kb
input:
90522 cyykzyylklyll ylcyllklzk ttusuuudtdtqus uuddu uefyqfkiblyfkyd ffyyqde qfxqecljeqeedea jqdxf prrbfxdxffpbpp ffppd ynjgygygjnjnjg jgynjggn maenpaksmxyya saxkep nrdnbnjipnjowjz djbwojzrpni oputuoufoojupu uoouopo mphmhphpkpkpmhp phmhpppp zwznzpzqyjczzy wczjnpzqy pfxfxxkfffpfx fxffkffxpx hzdhzhhh h...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 2 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 2 3 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 2 1 1 1 1 4 1 2 1 1 1 1 1 3 1 1 3 1 1 1 1 1 1 1 1 1 1 1 3 1 1 4 1 1 1 1 1 1 1 1 1 1 5 1 7 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 ...
result:
wrong answer 429th numbers differ - expected: '4', found: '2'