QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#317189#7618. Pattern Searchkaruna#WA 0ms3604kbC++20965b2024-01-28 17:34:102024-01-28 17:34:11

Judging History

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

  • [2024-01-28 17:34:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3604kb
  • [2024-01-28 17:34:10]
  • 提交

answer

#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	int t;
	cin >> t;

	while (t--) {
		string S, T;
		cin >> S >> T;

		int m = T.size();
		vector<int> F(m);
		for (int i = 1, p = 0; i < m; i++) {
			while (p && T[p] != T[i]) p = F[p - 1];
			if (T[p] == T[i]) F[i] = ++p;
		}

		vector<int> cnt(26);
		for (char c : S) cnt[c - 'a']++;

		bool flag = true;
		for (char c : T) {
			if (cnt[c - 'a'] == 0) {
				flag = false;
				break;
			}
			cnt[c - 'a']--;
		}

		if (!flag) {
			cout << 0 << '\n';
		}
		else {
			vector<int> d(26);
			for (int i = 0; i < m - F[m - 1]; i++) {
				d[T[i] - 'a']++;
			}

			int ans = 1e9;
			for (int i = 0; i < 26; i++) {
				if (d[i]) ans = min(ans, cnt[i] / d[i]);
			}
			cout << ans + 1 << '\n';
		}
	}
}

详细

Test #1:

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

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

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'