QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#315191#7618. Pattern Searchthomas_li#WA 0ms3808kbC++172.0kb2024-01-27 03:21:402024-01-27 03:21:40

Judging History

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

  • [2024-01-27 03:21:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3808kb
  • [2024-01-27 03:21:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
#define FS first
#define SD second
#define ary(k) array<int,k>
template<class A, class B> void cmx(A& x, B y){ x = max<A>(x,y); }
template<class A, class B> void cmn(A& x, B y){ x = min<A>(x,y); }
typedef pair<int,int> pii;
typedef vector<int> vi;

int ceil(int a, int b) {
    return (a + (b-1)) / b;
}

int l[200], l1[200], l2[200], pl[200];

void fun() {
    string slo, wzo;
    cin >> slo >> wzo;
    for (char c = 'a'; c <= 'z'; c++) {
        l[c] = 0;
        pl[c] = 0;
    }
    for (auto c : slo) {
        pl[c]++;
    }
    for (auto c : wzo) {
        l[c]++;
    }
    int res = 1;
    for (char c = 'a'; c <= 'z'; c++) {
        if (l[c] > pl[c])
            res = 0;
    }
//    cerr << "test\n\n";
    for (int x = 1; x <= sz(wzo); x++) {
        int ok = 1;
        for (char c = 'a'; c <= 'z'; c++) {
            l1[c] = ceil(l[c], (x+1));
            l2[c] = l[c] - x * l1[c];
            if (l2[c] < 0) {
                ok = 0;
            }
        }
//        cout << x << " " << ok << "\n";
//        cout << l1['a'] << " " << l1['l'] << "\n";
//        cout << l2['a'] << " " << l2['l'] << "\n";
//        cout << l['a'] << " " << l['l'] << "\n";
        if (!ok)
            continue;
        int cykle = 10000000, reszta = 1;
        for (char c = 'a'; c <= 'z'; c++) {
            if (l1[c] == 0) {
                continue;
            }
            cmn(cykle, pl[c] / l1[c]);
        }
        for (char c = 'a'; c <= 'z'; c++) {
            reszta &= pl[c] - l1[x] * cykle >= l2[c];
        }
//        cout << x << " " << cykle << " " << reszta << "\n\n";
        cmx(res, cykle - x + reszta);
    }
    cout << res << "\n";
}

signed main(){
	cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit);
    int t;
    cin >> t;
    while (t--) fun();
}

详细

Test #1:

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

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

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
1
1
0
1
1
2
2
0
0
0
0
2

result:

wrong answer 5th numbers differ - expected: '0', found: '1'