QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#226311#7618. Pattern Searchucup-team1001WA 0ms3856kbC++202.1kb2023-10-25 20:04:042023-10-25 20:04:04

Judging History

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

  • [2023-10-25 20:04:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2023-10-25 20:04:04]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using ll = long long;
#define int ll
#define endl "\n"
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
#define pii pair<int,int>
#define ary(i) array<ll,(i)>
#define all(x) x.begin(),x.end()
const int maxn = 2e5 + 7;
const int inf = numeric_limits<int>::max();
const int inf2 = 0x3f3f3f3f3f3f3f3;
const int inff = numeric_limits<int>::min();
const int mod = 1e9 + 7;


void solve() {

    string s1, s2;
    cin >> s1 >> s2;

    vector<int> ns1(26, 0), ns2(26, 0);
    for (auto i: s1) {
        ns1[i - 'a']++;
    }
    for (auto i: s2) {
        ns2[i - 'a']++;
    }
    int mins = inf;
    for (int i = 0; i < 26; i++) {
//        如果存在
        if (ns2[i]) {
//            不能完成
            if (ns2[i] > ns1[i]) {
                cout << 0 << endl;
                return;
            }
//            只有一种字符
            if (ns2[i] == s2.length()) {
                cout << ns1[i] - ns2[i] + 1 << endl;
                return;
            }
//            最小分块数目
            mins = min(ns2[i], mins);
        }
    }
//    计算用于补的情况
    for (int i = 0; i < 26; i++) {
        ns1[i] -= ns2[i];
    }
    int ans = 0;
    for (int i = 1; i <= mins + 1; i++) {
        int minf = inf;
        for (int j = 0; j < 26; j++) {
//            某一个字符串存在
            if (ns2[j]) {
//                上取整 求每一块的数目
                int er = (ns2[j] + i - 1) / i;
//                超过一块补不起
                if (er * i - ns2[j] > er) {
                    ans = 0;
                    break;
                }
                minf = min(minf, ns1[j] / er);
            }
        }
        cerr << minf << " ";
        ans = max(ans, minf + 1);
    }
    cout << ans << endl;
    cerr << endl;

}

#undef int


int main() {
//    IOS
    int n;
    cin >> n;
//    n = 1;
    while (n--) {
        solve();
    }

}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3856kb

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: 3560kb

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
2

result:

wrong answer 16th numbers differ - expected: '1', found: '2'