Submission #6581827


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;
		S += S;
		int max = S.length() / T.length();
		int ok = 0, ng = max+1;
		while(ng - ok > 1){
			int mid = (ok + ng) / 2;
			String t = "";
			for(int i = 0; i < mid; i++) t += T;
			if(S.contains(t)) ok = mid;
			else ng = mid;
		}
		out.println(ok);		
	}
	
	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 5048 Byte
Status WA
Exec Time 2110 ms
Memory 349076 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 43
WA × 9
TLE × 18
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 71 ms 19028 KB
a02 AC 67 ms 21332 KB
a03 AC 71 ms 21076 KB
b04 AC 68 ms 21204 KB
b05 AC 71 ms 20948 KB
b06 AC 69 ms 17364 KB
b07 AC 70 ms 19284 KB
b08 AC 70 ms 18644 KB
b09 AC 69 ms 21076 KB
b10 AC 70 ms 18644 KB
b11 AC 69 ms 17620 KB
b12 AC 179 ms 26776 KB
b13 AC 184 ms 27672 KB
b14 AC 179 ms 26776 KB
b15 AC 148 ms 23152 KB
b16 AC 148 ms 22128 KB
b17 AC 1923 ms 41624 KB
b18 TLE 2105 ms 34584 KB
b19 TLE 2106 ms 342028 KB
b20 TLE 2105 ms 37912 KB
b21 TLE 2105 ms 40216 KB
b22 AC 194 ms 39320 KB
b23 WA 174 ms 39960 KB
b24 TLE 2110 ms 344468 KB
b25 TLE 2108 ms 35608 KB
b26 TLE 2110 ms 343184 KB
b27 TLE 2105 ms 38296 KB
b28 WA 175 ms 41624 KB
b29 WA 169 ms 39704 KB
b30 AC 170 ms 44056 KB
b31 TLE 2104 ms 39448 KB
b32 AC 168 ms 35224 KB
b33 WA 172 ms 40088 KB
b34 AC 171 ms 40600 KB
b35 AC 174 ms 40856 KB
b36 AC 175 ms 46104 KB
b37 TLE 2105 ms 34192 KB
b38 TLE 2108 ms 36120 KB
b39 AC 987 ms 43672 KB
b40 AC 289 ms 40600 KB
b41 TLE 2105 ms 37272 KB
b42 TLE 2108 ms 44056 KB
b43 WA 173 ms 39448 KB
b44 TLE 2108 ms 34712 KB
b45 AC 169 ms 41368 KB
b46 TLE 2105 ms 38808 KB
b47 WA 172 ms 41496 KB
b48 TLE 2108 ms 41752 KB
b49 AC 315 ms 41496 KB
b50 TLE 2103 ms 33304 KB
b51 WA 178 ms 40984 KB
b52 AC 390 ms 43416 KB
b53 AC 168 ms 42136 KB
b54 WA 184 ms 41624 KB
b55 WA 163 ms 44044 KB
b56 TLE 2110 ms 349076 KB
b57 AC 1750 ms 348296 KB
b58 AC 299 ms 43476 KB
b59 AC 84 ms 17492 KB
b60 AC 121 ms 22836 KB
b61 AC 97 ms 18260 KB
b62 AC 99 ms 23124 KB
b63 AC 496 ms 345880 KB
b64 AC 189 ms 39832 KB
b65 AC 291 ms 44696 KB
b66 AC 167 ms 41624 KB
b67 AC 170 ms 38552 KB
b68 AC 1366 ms 41496 KB
b69 AC 767 ms 45464 KB
b70 AC 1091 ms 40088 KB