Submission #8238154


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

string s, t;
void check_Inf(string s, string t){
	//1 char
	set<char> set_s, set_t;
	for(auto c:s) set_s.insert(c);
	for(auto c:t) set_t.insert(c);
	if ((int) set_s.size() == 1 && (int)set_t.size() == 1 
		&& *set_s.begin() == *set_t.begin()) {
		cout << -1 << endl;
		exit(0);
	}
	if (s.length() < t.length()) swap(s, t);
	string tmp = t;
	while(t.length() < s.length()) t += tmp;
	if (t == s) {
		cout << -1 << endl;
		exit(0);
	}

}
int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> s >> t; check_Inf(s, t);
	string tmp_s = s;
	while(s.length() < t.length()) s += tmp_s;
	int n = s.length(), m = t.length();
	string t_s = t + '_' + s + s;
	//z-function
	int len = t_s.length();
	vector<int> z(len, 0);
	z[0] = 0;
	int x = 0, y = 0;
	for(int i=1; i<len; i++){
		z[i] = max(0, min(z[i-x], y-i+1));
		while(i+z[i] < len && t_s[i+z[i]] == t_s[z[i]]) {
			x = i, y = i+z[i], z[i]++;
		}
	}

	vector<int> cnt(len+5, 0);
	int ans = 0;
	for(int i=m+1; i<len; i++){
		if (z[i] == m) {
			cnt[i] = 1 + cnt[i-m];
			ans = max(ans, cnt[i]);
		}
	}
	cout << ans << endl;

	return 0;
}

Submission Info

Submission Time
Task F - Strings of Eternity
User hd7
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1478 Byte
Status WA
Exec Time 55 ms
Memory 24992 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 58
WA × 12
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49, b50, b51, b52, b53, b54, b55, b56, b57, b58, b59, b60, b61, b62, b63, b64, b65, b66, b67, b68, b69, b70
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 1 ms 256 KB
b09 AC 1 ms 256 KB
b10 AC 1 ms 256 KB
b11 AC 1 ms 256 KB
b12 AC 7 ms 2204 KB
b13 AC 7 ms 2204 KB
b14 AC 7 ms 2204 KB
b15 AC 4 ms 1308 KB
b16 AC 4 ms 1308 KB
b17 AC 26 ms 15856 KB
b18 AC 22 ms 14960 KB
b19 AC 20 ms 10052 KB
b20 AC 24 ms 15856 KB
b21 AC 34 ms 24992 KB
b22 AC 31 ms 24736 KB
b23 WA 36 ms 24992 KB
b24 AC 20 ms 10052 KB
b25 WA 26 ms 15856 KB
b26 AC 17 ms 10052 KB
b27 AC 34 ms 24864 KB
b28 WA 36 ms 24992 KB
b29 WA 40 ms 24736 KB
b30 AC 40 ms 24736 KB
b31 AC 40 ms 24736 KB
b32 AC 45 ms 14960 KB
b33 WA 46 ms 14960 KB
b34 AC 48 ms 15856 KB
b35 AC 55 ms 24736 KB
b36 AC 37 ms 13028 KB
b37 AC 27 ms 15856 KB
b38 WA 27 ms 15856 KB
b39 AC 37 ms 24736 KB
b40 AC 28 ms 15856 KB
b41 WA 27 ms 15856 KB
b42 AC 39 ms 24736 KB
b43 WA 39 ms 24736 KB
b44 AC 28 ms 15856 KB
b45 AC 39 ms 24736 KB
b46 AC 40 ms 24736 KB
b47 WA 30 ms 15856 KB
b48 AC 24 ms 13028 KB
b49 AC 30 ms 15856 KB
b50 AC 29 ms 14960 KB
b51 WA 41 ms 24736 KB
b52 AC 30 ms 15856 KB
b53 AC 41 ms 24736 KB
b54 WA 30 ms 15856 KB
b55 WA 31 ms 15856 KB
b56 AC 20 ms 10052 KB
b57 AC 26 ms 10056 KB
b58 AC 5 ms 2536 KB
b59 AC 1 ms 384 KB
b60 AC 7 ms 3132 KB
b61 AC 3 ms 1152 KB
b62 AC 5 ms 2296 KB
b63 AC 16 ms 10052 KB
b64 AC 36 ms 15856 KB
b65 AC 23 ms 15856 KB
b66 AC 43 ms 24736 KB
b67 AC 46 ms 24736 KB
b68 AC 34 ms 15856 KB
b69 AC 28 ms 15856 KB
b70 AC 38 ms 24736 KB