QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#224991 | #7618. Pattern Search | SolitaryDream# | WA | 0ms | 3640kb | C++17 | 1.7kb | 2023-10-23 20:02:38 | 2023-10-23 20:02:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
inline bool Check(vector<int> tmax, vector<int> tcnt) {
static int period[N];
int req = 26;
int mx = 0;
// puts("Solve");
// for (auto x : tmax) printf("%d ", x);
// puts("");
// for (auto x : tcnt) printf("%d ", x);
// puts("");
for (int d = 0; d < 26; ++d) {
if (!tcnt[d]) { req -= 1; continue; }
for (int tm = min(tmax[d], tcnt[d] + 1); tm; --tm) {
int x = tcnt[d] / tm;
mx = max(mx, x);
// printf("valid %d\n", x);
period[x] += 1;
}
}
bool flag = 0;
for (int x = 0; x <= mx; ++x) {
if (period[x] == req) flag = 1;
period[x] = 0;
}
return flag;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int Case;
cin >> Case;
while (Case--) {
string s, t;
cin >> s >> t;
vector<int> scnt(26), tcnt(26);
for (auto c : s) ++scnt[c - 'a'];
for (auto c : t) ++tcnt[c - 'a'];
bool flag = 1;
for (int i = 0; i < 26; ++i) {
if (scnt[i] < tcnt[i]) flag = 0;
}
if (!flag) { cout << "0\n"; continue; }
int ans = 0;
for (int l = 1, r = s.size(); l <= r; ) {
int mid = (l + r) >> 1;
vector<int> tmax(26);
bool flag = 1;
for (int i = 0; i < 26; ++i) {
tmax[i] = (scnt[i] - tcnt[i]) / mid;
}
if (flag && Check(tmax, tcnt)) ans = mid, l = mid + 1; else r = mid - 1;
}
cout << ans + 1 << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
2 bajkaaall aal abca cba
output:
2 1
result:
ok 2 number(s): "2 1"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3640kb
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 1 2 0 0 0 0 1
result:
wrong answer 10th numbers differ - expected: '2', found: '1'