QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#644479#7615. Sequence Foldingucup-team4479#RE 0ms0kbC++232.3kb2024-10-16 14:10:222024-10-16 14:10:23

Judging History

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

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

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;
        } if (tbac[i] % 3 == 2)
            two = two + ch;
        while (tbac[i] >= 3) {
            tbac[i] -= 3;
            thr = thr + ch;
        }
    }
    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 = "";
        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 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;
}
/*
1
bajkaaaabbbb aaaabbbb
*/

詳細信息

Test #1:

score: 0
Runtime Error

input:

8 3
1 5 8

output:

0

result: