Submission #6580933


Source Code Expand

Copy
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	void printlnYN(boolean b){out.println((b ? "YES" : "NO"));}

	//System.out.println();はつかわない!!
	void solve() throws Exception{
		String S = in.nextStr(), T = in.nextStr();
		
		boolean[] isAll = new boolean[2];
		Arrays.fill(isAll, true);
		for(int i = 0; i < S.length()-1; i++){
			if(S.charAt(i) != S.charAt(i+1)){
				isAll[0] = false;
				break;
			}
		}
		for(int i = 0; i < T.length()-1; i++){
			if(T.charAt(i) != T.charAt(i+1)){
				isAll[1] = false;
				break;
			}
		}
		
		if((isAll[0] && isAll[1] && S.charAt(0) == T.charAt(0))){
			out.println("-1");
			return;
		}
		
		if(S.length() <= T.length()){
			String s1 = new String(S), t1 = new String(T);
			while(s1.length() < t1.length()) s1 += s1;
			if(t1.equals(s1)){
				out.println("-1");
				return;
			}
		}
		
		int ans = 0;
		boolean isOk = false;
		int index = 0;
		int len = 0, cnt = 0;
		while(S.length() < T.length()) S += S;
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i < S.length(); i++){
			if(S.charAt(i) == T.charAt(index)){
				index++;
				if(index == T.length()){
					cnt++;
					index = 0;
				}
			}else{
				ans = Math.max(ans, cnt);
				cnt = 0;
				index = 0;
			}
		}
		out.println(ans);
	}
	
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		solve();
		out.flush();
	}
	
	class FastScanner {
		Reader input;

		FastScanner() {this(System.in);}
		FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));}
		
		int nextInt() {return (int) nextLong();}

		long nextLong() {
			try {
				int sign = 1;
				int b = input.read();
				while ((b < '0' || '9' < b) && b != '-' && b != '+') {
					b = input.read();
				}
				if (b == '-') {
					sign = -1;
					b = input.read();
				} else if (b == '+') {
					b = input.read();
				}
				long ret = b - '0';
				while (true) {
					b = input.read();
					if (b < '0' || '9' < b) return ret * sign;
					ret *= 10;
					ret += b - '0';
				}
			} catch (IOException e) {
				e.printStackTrace();
				return -1;
			}
		}

		double nextDouble() {
			try {
				double sign = 1;
				int b = input.read();
				while ((b < '0' || '9' < b) && b != '-' && b != '+') {
					b = input.read();
				}
				if (b == '-') {
					sign = -1;
					b = input.read();
				} else if (b == '+') {
					b = input.read();
				}
				double ret = b - '0';
				while (true) {
					b = input.read();
					if (b < '0' || '9' < b) break;
					ret *= 10;
					ret += b - '0';
				}
				if (b != '.') return sign * ret;
				double div = 1;
				b = input.read();
				while ('0' <= b && b <= '9') {
					ret *= 10;
					ret += b - '0';
					div *= 10;
					b = input.read();
				}
				return sign * ret / div;
			} catch (IOException e) {
				e.printStackTrace();
				return Double.NaN;
			}
		}

		char nextChar() {
			try {
				int b = input.read();
				while (Character.isWhitespace(b)) {
					b = input.read();
				}
				return (char) b;
			} catch (IOException e) {
				e.printStackTrace();
				return 0;
			}
		}

		String nextStr() {
			try {
				StringBuilder sb = new StringBuilder();
				int b = input.read();
				while (Character.isWhitespace(b)) {
					b = input.read();
				}
				while (b != -1 && !Character.isWhitespace(b)) {
					sb.append((char) b);
					b = input.read();
				}
				return sb.toString();
			} catch (IOException e) {
				e.printStackTrace();
				return "";
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}
 
		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}
 
		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}
 
		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}
 
		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}
 
		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}
 
		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}
	}
}
/* end Main */

Submission Info

Submission Time
Task F - Strings of Eternity
User Oland
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 5137 Byte
Status WA
Exec Time 212 ms
Memory 44952 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 2
WA × 1
AC × 29
WA × 41
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 WA 68 ms 19284 KB
a02 AC 70 ms 22484 KB
a03 AC 69 ms 17364 KB
b04 AC 67 ms 18644 KB
b05 AC 69 ms 16212 KB
b06 AC 68 ms 19412 KB
b07 WA 70 ms 19028 KB
b08 AC 69 ms 20564 KB
b09 AC 68 ms 17876 KB
b10 WA 70 ms 20692 KB
b11 WA 68 ms 20820 KB
b12 AC 178 ms 29720 KB
b13 AC 178 ms 31256 KB
b14 AC 177 ms 29584 KB
b15 AC 147 ms 23736 KB
b16 AC 147 ms 22896 KB
b17 WA 184 ms 26136 KB
b18 AC 195 ms 29720 KB
b19 WA 167 ms 25712 KB
b20 WA 203 ms 26392 KB
b21 AC 212 ms 39832 KB
b22 AC 206 ms 42008 KB
b23 WA 190 ms 44952 KB
b24 WA 147 ms 22328 KB
b25 WA 171 ms 26520 KB
b26 WA 170 ms 22328 KB
b27 AC 193 ms 39320 KB
b28 WA 189 ms 43920 KB
b29 WA 188 ms 38936 KB
b30 AC 188 ms 40472 KB
b31 AC 190 ms 40472 KB
b32 AC 171 ms 29592 KB
b33 WA 172 ms 26648 KB
b34 WA 175 ms 27032 KB
b35 AC 183 ms 38552 KB
b36 WA 165 ms 24856 KB
b37 WA 173 ms 27288 KB
b38 WA 171 ms 25100 KB
b39 WA 181 ms 42264 KB
b40 WA 171 ms 28312 KB
b41 WA 189 ms 27660 KB
b42 WA 195 ms 42008 KB
b43 WA 187 ms 41488 KB
b44 WA 172 ms 27032 KB
b45 AC 191 ms 41240 KB
b46 AC 184 ms 43924 KB
b47 WA 174 ms 27800 KB
b48 WA 167 ms 25112 KB
b49 WA 174 ms 30744 KB
b50 AC 172 ms 27672 KB
b51 WA 188 ms 40472 KB
b52 WA 173 ms 29080 KB
b53 AC 189 ms 38936 KB
b54 WA 173 ms 29464 KB
b55 WA 172 ms 26508 KB
b56 WA 153 ms 25272 KB
b57 WA 152 ms 23920 KB
b58 WA 117 ms 23252 KB
b59 AC 84 ms 19156 KB
b60 AC 126 ms 26332 KB
b61 WA 86 ms 20564 KB
b62 AC 99 ms 23124 KB
b63 WA 154 ms 22840 KB
b64 WA 176 ms 29848 KB
b65 WA 175 ms 29592 KB
b66 WA 182 ms 40216 KB
b67 AC 191 ms 43928 KB
b68 WA 187 ms 26136 KB
b69 WA 173 ms 26136 KB
b70 AC 185 ms 39064 KB