QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644576#7615. Sequence Foldingucup-team4479#RE 0ms0kbC++231.5kb2024-10-16 14:40:042024-10-16 14:40:04

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 14:40:04]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-16 14:40:04]
  • 提交

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']++;
    int border = 0;
    for (int k = m; k >= 2; --k) {
        string p = "", q = "";
        bool flag = 1;
        for (int i = 0; i < 26; ++i) {
            if (!tbac[i]) continue;
            char ch = 'a' + i;
            if (tbac[i] % k == 0) p = p;
            else if (tbac[i] % k == k - 1) q = q + ch;
            else {
                flag = 0;
                break;
            }
            for (int j = 1; j <= tbac[i] / k; ++j) p = p + ch;
        }
        if (!flag) continue;
        t = p;
        for (int i = 2; i <= k; ++i)
            t = t + q + p;
        border = m - p.length() - q.length();
        break;
    }
    // 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
bajkaaall aal
abca cba
bajkaaaaaaaaabbbb aaaaaaaabbb
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

8 3
1 5 8

output:

1

result: