exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
βŒ€
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
βŒ€
difficulty
int64
-1
3.5k
βŒ€
prob_desc_output_spec
stringlengths
17
1.47k
βŒ€
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
47f65e0138f3749b872b126c6975cfd8
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.util.Scanner; public class C { public static void main(String[] args) { Scanner jin = new Scanner(System.in); long num = Long.parseLong(jin.nextLine()); jin.close(); if (num < 3) System.out.println(-1); else { if (num % 2 == 0) { long num1 = ((num * num) / 4) + 1; long num2 = num1 - 2; System.out.println(num1 + " " + num2); } else { long num1 = (num * num + 1) / 2; long num2 = (num * num - 1) / 2; System.out.println(num1 + " " + num2); } } } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
ec6d4543fe4f50cee3fbfaa3ece82f81
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
//package adruill; import java.util.Scanner; public class Main{ public static void main(String[] agrs){ Scanner in = new Scanner(System.in); while(in.hasNext()){ long n = in.nextLong(); if(n == 1 || n == 2) System.out.print(-1); else{ if(n % 2 == 1) System.out.print(n * n / 2 + " " + (n * n / 2 + 1)); else{ if(n % 4 == 0) System.out.print(3 * n / 4 + " " + 5 * n / 4); else{ n /= 2; System.out.print(2 * (n * n / 2) + " " + 2 * (n * n / 2 + 1)); } } } System.out.println(); } in.close(); } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
30a543b6d2f4aaaf3aa061550a9b97e7
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); long b = in.nextLong(); if(b==1||b==2){ System.out.println("-1"); return; } if(b%2!=0){ long e = b*b; System.out.println((e/2)+" "+((e/2)+1)); return; }else{ long e = b/2; e = e*e; System.out.println((e-1)+" "+(e+1)); return; } } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
d64951af043a0462f981f74d571ef15d
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.util.*; import java.io.*; /** * @author Bill * */ public class CF707C { public static void main(String[] args) throws IOException{ BufferedReader fin = new BufferedReader(new InputStreamReader(System.in)); long N = 0; StringTokenizer st = new StringTokenizer(fin.readLine()); N = Long.parseLong(st.nextToken()); long OS1 = 0, OS2 = 0; if(N <= 2){ System.out.println(-1); }else{ if(N % (long) 2 == 0){ OS1 = N * N / 4 - 1; OS2 = N * N / 4 + 1; }else{ OS1 = N * N / 2; OS2 = N * N / 2 + 1; } System.out.println(OS1 + " " + OS2); } } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
b3d77626156b5a1740aa62d1c8caa688
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CSep10 { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); long num = Integer.parseInt(in.readLine()); long op = num; if(num<=2) System.out.println(-1); else{ if(num%2!=0){ long aux = (num*num)/2; System.out.println(aux + " "+(aux+1)); }else{ int primes[] = eratostenes(num); long multi = 1; long last = 0; for (int i = 0; i < primes.length; i++) { if(primes[i]==0){ while(num%i==0){ num/=i; multi*=i; last = i; } } } if(num > 1){ last = num; long aux = (last*last)/2; System.out.println(aux*multi+" "+(aux+1)*multi); } else if(last==2){ multi/=4; System.out.println(op-multi + " " +(op+multi) ); }else{ multi/=last; long aux = (last*last)/2; System.out.println(aux*multi+" "+(aux+1)*multi); } } } } static int[] eratostenes(long n){ int[] primes = new int[50000]; primes[0]=primes[1] = 1; for (int i = 2; i*i<=n; i++) { if(primes[i]==0){ for (int j = i*i; j < primes.length; j+=i) { primes[j] = 1; } } } return primes; } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
a5b8c227c29f8975ecbafccf543673c7
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.File; import java.io.FileNotFoundException; import java.util.StringTokenizer; import java.io.Writer; import java.math.BigInteger; import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author zodiacLeo */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); FastPrinter out = new FastPrinter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { private BigInteger MAX = BigInteger.valueOf(((long) 1e18)); public void solve(int testNumber, FastScanner in, FastPrinter out) { long s = in.nextLong(); if (s == 1) { out.println(-1); return; } if (s % 2 != 0) { BigInteger a = BigInteger.valueOf(s); BigInteger b = a.multiply(a).subtract(BigInteger.ONE); b = b.divide(BigInteger.valueOf(2)); BigInteger c = b.add(BigInteger.ONE); BigInteger A = a.multiply(a); BigInteger B = b.multiply(b); BigInteger C = c.multiply(c); if (A.add(B).compareTo(C) != 0 || b.compareTo(MAX) > 0 || c.compareTo(MAX) > 0 || b.compareTo(BigInteger.ZERO) <= 0 || c.compareTo(BigInteger.ZERO) <= 0) { out.println(-1); return; } out.println(b + " " + c); } else { BigInteger a = BigInteger.valueOf(s); BigInteger b = a.divide(BigInteger.valueOf(2)); b = b.multiply(b); b = b.subtract(BigInteger.ONE); BigInteger c = b.add(BigInteger.valueOf(2)); BigInteger A = a.multiply(a); BigInteger B = b.multiply(b); BigInteger C = c.multiply(c); if (A.add(B).compareTo(C) != 0 || b.compareTo(MAX) > 0 || c.compareTo(MAX) > 0 || b.compareTo(BigInteger.ZERO) <= 0 || c.compareTo(BigInteger.ZERO) <= 0) { out.println(-1); return; } out.println(b + " " + c); } } } static class FastScanner { public BufferedReader br; public StringTokenizer st; public FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public String next() { while (st == null || !st.hasMoreElements()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } } static class FastPrinter extends PrintWriter { public FastPrinter(OutputStream out) { super(out); } public FastPrinter(Writer out) { super(out); } } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
1378a8f74c2a457c6525c98afce16eb5
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.File; import java.io.FileNotFoundException; import java.util.StringTokenizer; import java.io.Writer; import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author zodiacLeo */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); FastPrinter out = new FastPrinter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, FastScanner in, FastPrinter out) { long n = in.nextLong(); if (n == 1 || n == 2) { out.println(-1); return; } if (n == 3) { out.println("4 5"); return; } else if (n % 2 != 0) { long b = n * n - 1; b /= 2; long c = b + 1; out.println(b + " " + c); } else { long b = n * n; b /= 4; b -= 1; long c = b + 2; out.println(b + " " + c); } } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public String next() { while (st == null || !st.hasMoreElements()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } } static class FastPrinter extends PrintWriter { public FastPrinter(OutputStream out) { super(out); } public FastPrinter(Writer out) { super(out); } } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
002e38a64cbae98610c24a6051f7ab34
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().run(); } long a; long c; long b; private void run() { init(); if (a == 1 || a == 2) { System.out.println(-1); } else { if (a % 4 == 0) { b = 3 * (a / 4); c = 5 * (a / 4); }else if (a % 2 == 0){ b = (a * a / 8) * 2; c = (a * a / 8 + 1) * 2; } else { c = a * a / 2; b = a * a / 2 + 1; } System.out.println(c + " " + b); } } private void init() { Scanner scanner = new Scanner(System.in); a = scanner.nextLong(); } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
870068e0b6da4d8e682977c2e3ef81a8
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); long n = s.nextLong(); long a = 0, b = 0; if (n % 2 == 1) { a = (n*n-1)/2; b = a+1; if (a <= 0 || b <= 0) { System.out.println(-1); } else { System.out.println(a + " " + b); } } else { long sum=n/2; a = (sum*sum)-1; a = (sum*sum)+1; b = a-2; if (a <= 0 || b <= 0) { System.out.println(-1); } else { System.out.println(b + " " + a); } } } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
982bfffa9b1a693ad59b916153f98c6c
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); if (n==2 || n==1) System.out.println(-1); else if (n%2==0) { long k = n*n/4+1; long m = k-2; System.out.println(m+" "+k); } else { long k = (n*n+1)/2; long m = k-1; System.out.println(m+" "+k); } sc.close(); } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
8e82b01628969eacbcc8d71417b04808
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class TaskC { static ArrayList<Long>al; static int n, m, ans; static int[]arr; static int[] row = new int[9]; public static void backtrack(int col) { if(col==9) { ans++; System.out.println(Arrays.toString(row)); return; } for(int i = 1; i <= 8;i++) if(valid(col,i)) { row[col] = i; backtrack(col+1); } } public static boolean valid(int col, int tryRow) { for(int i = 1; i < col; i++) if(row[i]==tryRow || Math.abs(tryRow-row[i])== Math.abs(col-i)) return false; return true; } public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int n = sc.nextInt(); if(n < 3 ) { pw.println(-1); }else { if (n % 2 == 1) { long a = ((1l*n * n) - 1)/2; long b = ((1l*n * n) + 1)/2; pw.println((long)a + " " + (long) b); }else{ long a = 1l*(1l*n / 2)*1l*(1l*n / 2) - 1; long b = 1l*(1l*n / 2)*1l*(1l*n / 2) + 1; pw.println((long) a + " " + (long) b); } } pw.close(); } private static long gcd(long a, long b) { if( b == 0) return a; return gcd(b , a%b); } static long lcm(int a, int b) { return (a*b)/gcd(a, b); } private static int dis(int xa , int ya , int xb , int yb) { return (xa-xb)*(xa - xb) + (ya- yb)*(ya-yb); } static class Pair implements Comparable<Pair> { double x,y; public Pair(double x, double y) { this.x = x; this.y = y; } public int compareTo(Pair o) { /* if (x == o.x) return y - o.y; return x - o.x;*/ return 0; } public double dis(Pair a){ return (a.x - x)*(a.x - x) + (a.y-y)*(a.y-y); } public String toString() { return x+" "+ y; } public boolean overlap(Pair a) { if((this.x >= a.x && this.x <= a.y) || (a.x >= this.x && a.x <= this.y)) return true; return false; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public boolean check() { if (!st.hasMoreTokens()) return false; return true; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(e); } } public double nextDouble() { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() { try { return br.ready(); } catch (IOException e) { throw new RuntimeException(e); } } } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
b1e3b5f20e04159cffb24bdbbbd4670d
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.io.*; import java.lang.*; import java.util.*; public class kod{ public void solve(){ long n; Scanner in = new Scanner( System.in ); n = in.nextLong(); long t=1; while( n%2==0 ){ t *= 2; n /= 2; } if( n==1 ){ if( t<=2 ){ System.out.println(-1); return; } System.out.println(3*t/4+" "+5*t/4); return; } System.out.println( n*n/2*t+" "+(n*n/2+1)*t ); } static public void main(String args[])throws Exception{ new kod().solve(); } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
62c2917b7c97ecde0bb2fc8e6235c96f
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
/* * Remember a 7.0 student can know more than a 10.0 student. * Grades don't determine intelligence, they test obedience. * I Never Give Up. */ import java.util.*; import java.util.Map.Entry; import java.io.*; import java.text.*; import static java.lang.System.out; import static java.util.Arrays.*; import static java.lang.Math.*; public class ContestMain { private static Reader in=new Reader(); private static StringBuilder ans=new StringBuilder(); private static long MOD=1000000000+9;//10^9+9 private static final int N=100000+7; //10^5 // private static final int LIM=26; // private static final double PI=3.1415; // private static ArrayList<Integer> v[]=new ArrayList[N]; // private static int color[]=new int[N]; // private static boolean mark[]=new boolean[N]; // private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); // private static void dfs(int node){mark[node]=true;for(int x:v[node]){if(!mark[x]){dfs(x);}}} private static long powmod(long x,long n){ if(n==0||x==0)return 1; else if(n%2==0)return(powmod((x*x)%MOD,n/2)); else return (x*(powmod((x*x)%MOD,(n-1)/2)))%MOD; } // private static void shuffle(long [] arr) { // for (int i = arr.length - 1; i >= 2; i--) { // int x = new Random().nextInt(i - 1); // long temp = arr[x]; // arr[x] = arr[i]; // arr[i] = temp; // } // } // private static long gcd(long a, long b){ // if(b==0)return a; // return gcd(b,a%b); // } // private static boolean check(int x,int y){ // if((x>=0&&x<n)&&(y>=0&&y<m)&&mat[x][y]!='X'&&!visited[x][y])return true; // return false; // } // static class Node{ // int x,y,c; // Node(int x,int y,int c){ // this.x=x; // this.y=y; // this.c=c; // } // } public static void main(String[] args) throws IOException{ long x=in.nextLong(),a,b,c; long cnt=0; if(x==1||x==2){out.println(-1);return;} if(x%2!=0){ a=x; b=(x*x-1)/2; c=b+1; } else{ while(x%2==0){ x/=2; cnt++; } if(x==1){ cnt-=2; a=4; b=3; c=5; } else{ a=x; b=(x*x-1)/2; c=b+1; } a=(long) ((long)pow(2,cnt)*a); b=(long) ((long)pow(2,cnt)*b); c=(long) ((long)pow(2,cnt)*c); } out.print(b+" "+c); } static class Pair<T> implements Comparable<Pair>{ int l; int r; Pair(){ l=0; r=0; } Pair(int k,int v){ l=k; r=v; } @Override public int compareTo(Pair o) { if(o.l!=l)return (int) (l-o.l); else return (r-o.r); } } static class Reader{ BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
f252b594dbbcaeb9c3c13202c901390e
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.util.*; public class PythagoeanTriples { public static void main(String[] args) { Scanner input = new Scanner(System.in); long a = input.nextInt(); if(a < 3) { System.out.println(-1); } else if(a % 2 == 1) { long c = ((a*a) + 1)/2; long b = ((a*a))/2; System.out.println(b + " " + c); } else { long c = (a*a)/4 + 1; long b = c - 2; System.out.println(b + " " + c); } } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
df02e452976cc7603f54e3de470c8cb3
train_001.jsonl
1471698300
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.SortedSet; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; /** * # * @author pttrung */ public class C_Round_368_Div2 { public static long MOD = 1000000007; public static void main(String[] args) throws FileNotFoundException { // PrintWriter out = new PrintWriter(new FileOutputStream(new File( // "output.txt"))); PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(); long n = in.nextInt(); if (n <= 2) { out.println(-1); } else { long v = n * n; if (n % 2 != 0) { out.println(v / 2 + " " + (v - (v / 2))); } else { v /= 4L; out.println((v - 1L) + " " + (v + 1L)); } } out.close(); } public static int[] KMP(String val) { int i = 0; int j = -1; int[] result = new int[val.length() + 1]; result[0] = -1; while (i < val.length()) { while (j >= 0 && val.charAt(j) != val.charAt(i)) { j = result[j]; } j++; i++; result[i] = j; } return result; } public static boolean nextPer(int[] data) { int i = data.length - 1; while (i > 0 && data[i] < data[i - 1]) { i--; } if (i == 0) { return false; } int j = data.length - 1; while (data[j] < data[i - 1]) { j--; } int temp = data[i - 1]; data[i - 1] = data[j]; data[j] = temp; Arrays.sort(data, i, data.length); return true; } public static int digit(long n) { int result = 0; while (n > 0) { n /= 10; result++; } return result; } public static double dist(long a, long b, long x, long y) { double val = (b - a) * (b - a) + (x - y) * (x - y); val = Math.sqrt(val); double other = x * x + a * a; other = Math.sqrt(other); return val + other; } public static class Point implements Comparable<Point> { int x, y; public Point(int start, int end) { this.x = start; this.y = end; } @Override public int hashCode() { int hash = 5; hash = 47 * hash + this.x; hash = 47 * hash + this.y; return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Point other = (Point) obj; if (this.x != other.x) { return false; } if (this.y != other.y) { return false; } return true; } @Override public int compareTo(Point o) { return Integer.compare(x, o.x); } } public static class FT { long[] data; FT(int n) { data = new long[n]; } public void update(int index, long value) { while (index < data.length) { data[index] += value; index += (index & (-index)); } } public long get(int index) { long result = 0; while (index > 0) { result += data[index]; index -= (index & (-index)); } return result; } } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } public static long pow(long a, long b, long MOD) { if (b == 0) { return 1; } if (b == 1) { return a; } long val = pow(a, b / 2, MOD); if (b % 2 == 0) { return val * val % MOD; } else { return val * (val * a % MOD) % MOD; } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() throws FileNotFoundException { // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true)); br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { st = null; try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(); } } public boolean endLine() { try { String next = br.readLine(); while (next != null && next.trim().isEmpty()) { next = br.readLine(); } if (next == null) { return true; } st = new StringTokenizer(next); return st.hasMoreTokens(); } catch (Exception e) { throw new RuntimeException(); } } } }
Java
["3", "6", "1", "17", "67"]
1 second
["4 5", "8 10", "-1", "144 145", "2244 2245"]
NoteIllustration for the first sample.
Java 8
standard input
[ "number theory", "math" ]
df92643983d6866cfe406f2b36bec17f
The only line of the input contains single integer n (1 ≀ n ≀ 109)Β β€” the length of some side of a right triangle.
1,500
Print two integers m and k (1 ≀ m, k ≀ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.
standard output
PASSED
72cd914fdc3f722929d51aedc74b56b8
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; import java.util.Map.Entry; import javax.swing.text.InternationalFormatter; import java.math.*; public class temp1 { public static PrintWriter out; static int[] a; static int[] b; static StringBuilder sb = new StringBuilder(); static int ans = 0; public static void main(String[] args) throws IOException { Reader scn = new Reader(); int t = scn.nextInt(); z: while (t-- != 0) { int n = scn.nextInt(); int[] a = scn.nextIntArray(n); int[] b = scn.nextIntArray(n); boolean f = false; int d = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { if (a[i] != b[i]) { if (!f) { if (d != Integer.MAX_VALUE) { System.out.println("NO"); continue z; } f = true; d = b[i] - a[i]; } else { if (d != b[i] - a[i]) { System.out.println("NO"); continue z; } } } else f = false; } if (d < 0) System.out.println("NO"); else System.out.println("YES"); } } // _________________________TEMPLATE_____________________________________________________________ // private static int gcd(int a, int b) { // if(a== 0) // return b; // // return gcd(b%a,a); // } // static class comp implements Comparator<pair> { // // @Override // public int compare(pair o1, pair o2) { // return o2.b - o1.b; // } // // } static class pair implements Comparable<pair> { int u; int v; pair(int a, int b) { u = a < b ? a : b; v = a == u ? b : a; } @Override public int compareTo(pair o) { return (int) (this.v - o.u); } } public static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[100000 + 1]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } public int[] nextIntArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } public int[][] nextInt2DArray(int m, int n) throws IOException { int[][] arr = new int[m][n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) arr[i][j] = nextInt(); } return arr; } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
e0e07730e46ce606f1cb47e351f99563
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; public class P600A { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for(int i=0; i<t; i++) { int n = Integer.parseInt(br.readLine()); String[] line = br.readLine().split(" "); int[] a = new int[n]; for(int j=0; j<n; j++) { a[j] = Integer.parseInt(line[j]); } line = br.readLine().split(" "); int[] b = new int[n]; for(int j=0; j<n; j++) { b[j] = Integer.parseInt(line[j]); } int[] diff = new int[n]; for(int j=0; j<n; j++) { diff[j] = b[j] - a[j]; } boolean isImpossible = false; int pushVal = -1; boolean startedPushing = false; boolean noMorePushing = false; for(int j=0; j<n; j++) { if(diff[j] < 0) isImpossible = true; else if(diff[j] > 0) { if(!startedPushing && !noMorePushing) { startedPushing = true; pushVal = diff[j]; } else { if(pushVal != diff[j] || noMorePushing) isImpossible = true; } } else { if (startedPushing) { startedPushing = false; noMorePushing = true; } } } if(isImpossible) System.out.println("NO"); else System.out.println("YES"); } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
2d851582a38f0dee1e00499feac8c70e
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String ts = br.readLine(), ns; while ((ns = br.readLine()) != null) { int n = Integer.parseInt(ns); String[] arrA = br.readLine().trim().split(" "); String[] arrB = br.readLine().trim().split(" "); ArrayList<Integer> list = new ArrayList<>(); Set<Integer> set = new HashSet<>(); boolean found = false; boolean possible = true; for (int i = 0; i < n; i++) { int a = Integer.parseInt(arrA[i]); int b = Integer.parseInt(arrB[i]); int diff = b - a; if (diff < 0) { possible = false; break; } else if (diff == 0) { if (found) { list.add(diff); set.add(diff); } } else { found = true; list.add(diff); set.add(diff); } } if (set.size() > 2) { possible = false; } else { if (set.size() == 2) { int mx = Collections.max(list); int mn = Collections.min(list); if (mn == 0) { int fIdx = list.indexOf(mx); int lIdx = list.lastIndexOf(mx); int altIdx = list.indexOf(mn); if (altIdx > fIdx && altIdx < lIdx) { possible = false; } } else { possible = false; } } } if (possible) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
970bb523d37235380330425c56a2bb10
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.Scanner; public class first{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int l,r,a[], b[],n,i,j; while(t>0) { t--; n=sc.nextInt(); a=new int[n]; b=new int[n]; for(i=0;i<n;i++) { a[i]=sc.nextInt(); } for(i=0;i<n;i++) { b[i]=sc.nextInt(); } i=0; boolean diff = false; while(i<n && a[i]==b[i]) i++; diff = true; boolean ans=false; int diff_num = (i<n)?(b[i]-a[i]):0; ans = (i==n) ? true : (diff_num>0) ; while(ans && i<n &&a[i]!=b[i]) { if(b[i]-a[i]!=diff_num) { ans = false; break; } i++; } while(ans && (i<n)) { if(a[i]!=b[i]) { ans = false; break; } i++; } System.out.println(ans?"YES":"NO"); } sc.close(); } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
1643176bfa121353f9c89828684b6002
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class MyProgram { public static FastIO file = new FastIO(); private static void solve() { int tt = nextInt(); while (tt-- > 0) { int n = nextInt(); int[] a = nextArray(n); int[] b = nextArray(n); int dif = 0; boolean check = true, check2 = true; for (int i = 0; i < n; i++) { if (a[i] == b[i]) ; else if (check) { dif = a[i] - b[i]; if(dif > 0) break; while (a[i] != b[i]) { if (a[i] - b[i] != dif) check2 = false; i++; if (i == n) break; } check = false; } else { check2 = false; } } System.out.println(check2 && dif <= 0 ? "Yes" : "No"); } } private static int[] nextArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public static int[][] nextArray2D(int n, int m) { int[][] result = new int[n][]; for (int i = 0; i < n; i++) { result[i] = nextArray(m); } return result; } public static long pow(long n, long p) { long ret = 1L; while (p > 0) { if (p % 2 != 0L) ret *= n; n *= n; p >>= 1L; } return ret; } public static String next() { return file.next(); } public static int nextInt() { return file.nextInt(); } public static long nextLong() { return file.nextLong(); } public static double nextDouble() { return file.nextDouble(); } public static String nextLine() { return file.nextLine(); } public static class FastIO { BufferedReader br; StringTokenizer st; PrintWriter out; public FastIO() { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { solve(); } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
cc00c37632cad6616de9e903bdacdfcc
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.HashSet; import java.util.Iterator; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for (int xx = 0; xx < t; xx++) { int n = scanner.nextInt(); int[] a = new int[n]; int[] b = new int[n]; int[] c = new int[n]; for (int i = 0; i < n; i++) a[i] = scanner.nextInt(); for (int i = 0; i < n; i++) b[i] = scanner.nextInt(); int k = 0, j = 0; boolean isTrue = true; int cnt = 0; for (int i = 0; i < n; i++) { c[i] = b[i] - a[i]; if (c[i] < 0) { isTrue = false; break; } if (c[i] == 0) cnt++; } if (isTrue == false) { System.out.println("NO"); continue; } if (cnt == n) { System.out.println("YES"); continue; } isTrue = false; int x = 0; for (int i = 0; i < n; i++) { if (c[i] == 0) { if (isTrue) { x = 1; } } if ((k != c[i] || (k == c[i] && x == 1)) && k > 0 && c[i] > 0) { System.out.println("NO"); isTrue = false; break; } if (c[i] > 0) { k = c[i]; } if (k > 0) { isTrue = true; } } if (isTrue) { System.out.println("YES"); } } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
d7151c37d1d384075b75e14cb927fa64
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; import static java.lang.Math.sqrt; import static java.lang.Math.floor; import static java.lang.Math.abs; public class cf { static final double EPS = 1e-6; final static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); final static Scanner sc=new Scanner(System.in); public static void main(String[] args) throws IOException { // int t=Integer.parseInt(br.readLine()); int t=sc.nextInt(); while (t-->0) { // int[] input=sia(2); int n=sc.nextInt(); int [] a=siasc(n); int [] b=siasc(n); int [] c=new int[n]; int k=0; boolean bb=true; for(int i=0;i<n;i++){ c[i]=b[i]-a[i]; if (c[i]<0) { bb=false; } } int i=0; while (i<n&&c[i]==0) { i++; } int j=i; while (i<n&&c[j]==c[i]) { i++; } while (i<n&&c[i]==0) { i++; } if (i==n&&bb) { System.out.println("YES"); } else { System.out.println("NO"); } } //System.out.println(primeFactors(sc.nextLong())); } public static int[] siasc(int n) { int[] a=new int[n]; for (int i = 0; i < n; i++) { a[i]=sc.nextInt(); } return a; } static int[] getArr(BigInteger num) { String str = num.toString(); int[] arr = new int[str.length()]; for (int i=0; i<arr.length; i++) arr[i] = str.charAt(i)-'0'; return arr; } static int min(Queue<Integer> q){ int min=10000; for (Integer var : q) { min=Math.min(min, var); } return min; } public static int[] sia(int n) throws Exception{ int a[] = new int[n]; String line = br.readLine(); String[] strs = line.trim().split("\\s+"); for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(strs[i]); } return a; } public static String baseConversion(String number,int sBase, int dBase) { // Parse the number with source radix // and return in specified radix(base) return Long.toString(Long.parseLong(number, sBase),dBase); } static long phi(long n) { long result = n; long m=n; for (long p = 2; p * p <= n; ++p) { if (n % p == 0) { while (n % p == 0) n /= p; result -= result / p; } } if (n > 1) result -= result / n; if(result==m-1) result++; return result; } static long primeFactors(long n) { long m=n; if (n%2==0) { m-=n/2; } while (n%2==0) { n /= 2; } for (int i = 3; i <= Math.sqrt(n); i+= 2) { while (n%i == 0) { m-=n/i; n /= i; } } if (n > 2) return m-n/n; return m+1; } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
2ff830daf359138c58b588efa3d74184
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException{ FastReader sc = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int[] a=new int[n]; int[] b=new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } for(int i=0;i<n;i++){ b[i]=sc.nextInt(); b[i]-=a[i]; } int l=0; int r=0; int k=0; for(int i=0;i<n;i++){ if(b[i]!=0){ l=i; k=b[i]; break; } } for(int i=n-1;i>=0;i--){ if(b[i]!=0){ r=i; break; } } boolean ans=true; for(int i=l;i<=r;i++){ if(b[i]!=k){ ans=false; break; } } if(ans&&k>=0){ pw.println("YES"); } else{ pw.println("NO"); } } pw.close(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
7dce70b7f3db53c953d0e29ab8012a35
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; public class Main { static final int INF = (int) (1e9 + 10); static final int MOD = (int) (1e9 + 7); public static void main(String[] args) throws NumberFormatException, IOException { FastReader sc = new FastReader(); PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int [] a = new int [n]; for(int i =0 ; i < n ; i++){ a[i] = sc.nextInt(); } int [] b = new int [n]; for(int i =0 ; i < n ; i++){ b[i] = sc.nextInt(); } boolean ans = true; boolean one = true; int i =0 ; while(i < n ){ if(b[i] < a[i]){ ans = false; break; }else if(a[i] == b[i]){ i++; }else if(a[i] < b[i] && one){ one = false; int dif = b[i] - a[i]; int j = i+1; while(j < n && (b[j] - a[j]) == dif){ j++; } i = j; }else{ ans = false; break; } } if(ans){ pr.println("YES"); }else{ pr.println("NO"); } } pr.flush(); pr.close(); } static boolean solve(char [] ch , int n , int k) { int o =0 , z =0 , u =0; for(int i =0 ; i < k ; i++){ if(ch[i] == '0') z++; if(ch[i] == '1') o++; if(ch[i] == '?') u++; } if(o > u+z) return false; if(z > o+u) return false; for(int i =k ; i < n ; i++ ){ if(ch[i] == '?' && ch[i-k] != '?'){ ch[i] = ch[i-k]; }else if(ch[i] != '?' && ch[i-k] == '?'){ ch[i-k] = ch[i]; }else if(ch[i] != '?' && ch[i-k] != '?' && ch[i] != ch[i-k]) return false; } o = z = u =0; for(int i = k ; i < n ; i++){ if(ch[i] == '1') o++; else if(ch[i] == '0') z++; else if(ch[i] == '?') u++; } if(o > u+z || z > o+u) return false; return true; } /* * Template From Here */ private static boolean possible(long[] arr, int[] f, long mid, long k) { long c = 0; for (int i = 0; i < arr.length; i++) { if ((arr[i] * f[f.length - i - 1]) > mid) { c += (arr[i] - (mid / f[f.length - i - 1])); } } // System.out.println(mid+" "+c); if (c <= k) return true; return false; } public static int lowerBound(ArrayList<Integer> array, int length, long value) { int low = 0; int high = length; while (low < high) { final int mid = (low + high) / 2; if (value <= array.get(mid)) { high = mid; } else { low = mid + 1; } } return low; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static void sortbyColumn(int[][] att, int col) { // Using built-in sort function Arrays.sort Arrays.sort(att, new Comparator<int[]>() { @Override // Compare values according to columns public int compare(final int[] entry1, final int[] entry2) { // To sort in descending order revert // the '>' Operator // if (entry1[col] > entry2[col]) // return 1; // else //(entry1[col] >= entry2[col]) // return -1; return new Integer(entry1[col]).compareTo(entry2[col]); // return entry1[col]. } }); // End of function call sort(). } static class pair { int V, I; pair(int v, int i) { V = v; I = i; } } public static int[] swap(int data[], int left, int right) { int temp = data[left]; data[left] = data[right]; data[right] = temp; return data; } public static int[] reverse(int data[], int left, int right) { while (left < right) { int temp = data[left]; data[left++] = data[right]; data[right--] = temp; } return data; } public static boolean findNextPermutation(int data[]) { if (data.length <= 1) return false; int last = data.length - 2; while (last >= 0) { if (data[last] < data[last + 1]) { break; } last--; } if (last < 0) return false; int nextGreater = data.length - 1; for (int i = data.length - 1; i > last; i--) { if (data[i] > data[last]) { nextGreater = i; break; } } data = swap(data, nextGreater, last); data = reverse(data, last + 1, data.length - 1); return true; } static long nCr(long n, long r) { if (n == r) return 1; return fact(n) / (fact(r) * fact(n - r)); } static long fact(long n) { long res = 1; for (long i = 2; i <= n; i++) res = res * i; return res; } /* * static boolean prime[] = new boolean[1000007]; * * public static void sieveOfEratosthenes(int n) { * * for (int i = 0; i < n; i++) prime[i] = true; * for (int p = 2; p * p <= * n; p++) { // If prime[p] is not changed, then it is a prime if (prime[p] * == true) { // Update all multiples of p for (int i = p * p; i <= n; i += * p) prime[i] = false; } } * * // Print all prime numbers // for(int i = 2; i <= n; i++) // { // * if(prime[i] == true) // System.out.print(i + " "); // } } */ static long power(long fac2, int y, int p) { long res = 1; fac2 = fac2 % p; while (y > 0) { if (y % 2 == 1) res = (res * fac2) % p; fac2 = (fac2 * fac2) % p; } return res; } static long modInverse(long fac2, int p) { return power(fac2, p - 2, p); } static boolean isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static BigInteger lcmm(String a, String b) { BigInteger s = new BigInteger(a); BigInteger s1 = new BigInteger(b); BigInteger mul = s.multiply(s1); BigInteger gcd = s.gcd(s1); BigInteger lcm = mul.divide(gcd); return lcm; } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
f7d10b975e984da23192a8e3bc66c7d0
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.*; public class solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int n=sc.nextInt(); int[] a=new int[n]; int[] b=new int[n]; for(int j=0;j<n;j++) { a[j]=sc.nextInt(); } for(int j=0;j<n;j++) { b[j]=sc.nextInt(); } boolean f=true; int c=0; int max=0; for(int j=0;j<n;j++) { b[j]=b[j]-a[j]; if(b[j]!=0) { if(max==0) { max=b[j]; } else { if(max!=b[j]) { f=false; break; } } } } if(!f) { System.out.println("NO"); } else { for(int j=0;j<n;j++) { if(b[j]>0) { if(f) { f=false; } } else if(b[j]==0){ if(!f) { f=true; c++; } } else { f=false; c=-1; break; } } if(f) { if(c>1) { System.out.println("NO"); } else { System.out.println("YES"); } } else { if(c<0) { System.out.println("NO"); } else if(c<1) { System.out.println("YES"); } else { System.out.println("NO"); } } } } sc.close(); } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
aeac395722a6b5b1496ff602d5615e4c
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0){ int n = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } for(int i=0;i<n;i++){ b[i]=sc.nextInt(); } boolean r = true; int c =0,d=0; for(int i=0;i<n;i++){ if(a[i]!=b[i]){ if(d==0){ d=b[i]-a[i]; } if(c==2 || b[i]-a[i]!=d || d<0){ r=false; break; } c=1; } else{ if(c==1){ c=2; } } } if(r) System.out.println("YES"); else System.out.println("NO"); t--; } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
0d6fa76ba0c24a3439acad6605181522
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.*; public class singlepush { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0;i<t;i++) { int k = sc.nextInt(); int a[] = new int[k]; int b[] = new int[k]; int dif[] = new int[k]; int count=0; for(int w=0;w<k;w++) { a[w] = sc.nextInt(); } for(int j=0;j<k;j++) { b[j] = sc.nextInt(); } for(int z=0;z<k;z++) { dif[z] = b[z] - a[z]; } while(count < k && dif[count] == 0) { count++; } int val=0; if(count < k) val = dif[count]; while(count < k && dif[count] == val && val > 0) { count++; } while(count < k && dif[count] == 0) { count++; } if(count == k) { System.out.println("YES"); continue; } else { System.out.println("NO"); continue; } } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
56a0b3e810b4ac97b8c6a751bab10439
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { static BufferedReader input = new BufferedReader( new InputStreamReader(System.in) ); public static void main(String[] args) throws IOException { byte tests = Byte.parseByte(input.readLine()); while (tests-- > 0) { input.readLine(); String[] a = input.readLine().split(" "); String[] b = input.readLine().split(" "); short[] diff = new short[a.length]; for (int i = 0; i < a.length; i++) diff[i] = (short) (Short.parseShort(b[i]) - Short.parseShort(a[i])); if (solve(diff)) System.out.println("YES"); else System.out.println("NO"); } } public static boolean solve(short[] diff) { int start = 0; for (int i = 0; i < diff.length; i++) if (diff[i] != 0) { start = i; break; } int end = 0; for (int i = diff.length - 1; i > 0; i--) if (diff[i] != 0) { end = i; break; } if (diff[start] < 0) return false; for (int i = start; i < end; i++) if (diff[i] != diff[i + 1]) return false; return true; } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
820c79f0aeb36b76b24475f65eafe8c9
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
//package hiougyf; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc =new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int a[]=new int[n+1]; int b[]=new int[n+1]; for(int i=1;i<=n;i++) a[i]=sc.nextInt(); for(int i=1;i<=n;i++) b[i]=sc.nextInt(); find(a,b,n); } } static void find(int a[],int b[],int n) { int m=0; for(int i=1;i<=n;i++) { if(b[i]-a[i]<0) { System.out.println("NO"); return ; } } for(int i=1;i<=n;i++) b[i]-=a[i]; for(int i=1;i<=n;i++) { if(b[i]>0&&(b[i]!=b[i-1])) { m++; } } if(m>=2) { System.out.println("NO"); return ; } else { System.out.println("YES"); return; } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
60907f996a328980ec5f823375759f25
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class M1 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int i =0; i<t;i++){ int n = s.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for (int j=0;j<n;j++){ a[j] = s.nextInt(); } for (int j=0;j<n;j++){ b[j] = s.nextInt(); } int l = Arrays.mismatch(a, b); if (l!=-1){ int k = b[l]-a[l]; if (k>0){ for (int j = l ; j<a.length; j++){ if (a[j]!=b[j]){ a[j]+=k; }else { break; } } } if (Arrays.equals(a,b)){ System.out.println("YES"); }else { System.out.println("NO"); } }else { System.out.println("YES"); } } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
3b1035e1fd273f3093b2613ab9ac1b25
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.Scanner; public class Push { static boolean proc(int []a, int []b){ int n=a.length; int range=-1; int dis=0; boolean ok=true; for (int i=0; i<n; i++){ if (a[i]==b[i] && ok) { range=i; continue; } else if (a[i]>b[i]) return false; else { if (a[i]<b[i]) { if (i == range + 1) { if (dis == 0) { ok = false; dis = a[i] - b[i]; range = i; } if (dis != 0) { if (a[i]-b[i]!=dis) return false; ok = false; range = i; } } else return false; } } } return true; } public static void main(String[] args){ Scanner input= new Scanner(System.in); int testNum= input.nextInt(); int length; for (int i=0; i<testNum; i++){ length=input.nextInt(); int []a=new int[length]; int []b=new int[length]; for (int j=0; j<length; j++) a[j]=input.nextInt(); for (int j=0; j<length; j++) b[j]=input.nextInt(); if (proc(a,b)) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
41d5755fc05efb02fca4873c3216285a
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { static PrintWriter out = new PrintWriter(System.out); static Reader in = new Reader(); public static void main(String[] args) throws IOException { Main solver = new Main(); solver.solve(); out.flush(); out.close(); } static int INF = (int)1e9; static int maxn = (int)1e5+5; static int mod = 998244353; static int n,m,q,k,t; void solve() throws IOException{ t = in.nextInt(); while (t --> 0) { n = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = in.nextInt(); for (int i = 0; i < n; i++) arr[i] -= in.nextInt(); TreeSet<Integer> set = new TreeSet<>(); boolean flag = false, answer = true; if (arr[0] != 0) flag = true; if (arr[0] != 0) set.add(arr[0]); if (arr[0] > 0) answer = false; for (int i = 1; i < n; i++) { if (arr[i] != 0 && flag && arr[i-1] == 0) { answer = false; } if (arr[i] > 0) answer = false; if (arr[i] != 0) flag = true; if (arr[i] != 0)set.add(arr[i]); } if (set.size() > 1) answer = false; if (answer) out.println("YES"); else out.println("NO"); } } //<> static class Reader { private InputStream mIs; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public Reader() { this(System.in); } public Reader(InputStream is) { mIs = is; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = mIs.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String next() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
315e6fc2bdea4b67120e39af577c9253
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.*; public class single_push { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T=in.nextInt(); while(T-->0) { int n=in.nextInt(); int arr[]=new int[n]; int check[]=new int[n]; Set<Integer> set = new HashSet<>(); for(int i=0;i<n;i++) { arr[i]=in.nextInt(); } for(int i=0;i<n;i++) { check[i]=in.nextInt(); } Integer mid=0; boolean b=false; while(mid<=arr.length-1) { if((check[mid]-arr[mid])<0) { b=true; break; } arr[mid]=check[mid]-arr[mid]; set.add(arr[mid]); mid++; } if(set.size()>=3 || set.size()==2 && set.contains((int)0)!=true) { System.out.println("NO"); } else if(b==true) { System.out.println("NO"); } else { ArrayList<Integer> list = new ArrayList<Integer>(); mid=0; while(mid<=arr.length-1) { if(arr[mid]!=0) { list.add(mid); } mid++; } int i=0; for(i=0;i<list.size()-1;i++) { if(list.get(i+1)-list.get(i)!=1) { System.out.println("NO"); i=Integer.MAX_VALUE; break; } } if(i!=Integer.MAX_VALUE) { System.out.println("YES"); } } } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
2fa715f6336b736d2f742827ce2d3b2a
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); List<Integer> list1 = new ArrayList<>(); List<Integer> list2 = new ArrayList<>(); while (N-- > 0) { int n = sc.nextInt(); list1.clear(); list2.clear(); for (int i = 0; i < n; i++) list1.add(sc.nextInt()); for (int i = 0; i < n; i++) list2.add(sc.nextInt()); int l = -1, r = -1; boolean var = false, isEq = true, is = false; for (int i = 0; i < n; i++) { if (!list2.get(i).equals(list1.get(i))) { if (l == -1) { l = i; isEq = false; } if (is) var = true; } else if (!isEq && r == -1) { r = i; is = true; } } if (var) { System.out.println("NO"); continue; } if (l == -1) { System.out.println("YES"); continue; } if (r == -1) r = n; // System.out.println("l:" + l + " r:" + r); int num = list2.get(l) - list1.get(l); if (num < 0) { System.out.println("NO"); continue; } boolean val = false; for (int i = l + 1; i < r; i++) { if (num != (list2.get(i) - list1.get(i))) { val = true; break; } } if (val) System.out.println("NO"); else System.out.println("YES"); } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
ea31ec6ca1ca1cf5665cf1825656f53e
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { int mod = 1000000007; static public int diff(int[] a, int i, int j) { return Math.abs(a[i] - a[j]); } public static String reverse(String str) { return new StringBuilder(str).reverse().toString(); } // even-length array a, consisting of 0s and 1s. // remove half elements public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int T = sc.nextInt(); for (int t = 0; t < T; t++) { int n = sc.nextInt(); int[] diff = new int[n]; for (int i = 0; i < n; i++) { diff[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { diff[i] = sc.nextInt() - diff[i]; } int l = 0; int r = diff.length - 1; while (l <= r) { int lVal = diff[l]; int rVal = diff[r]; if (lVal != 0 && rVal != 0) { break; } else if (lVal == 0) { l++; } else if (rVal == 0) { r--; } } if (l > r) { out.println("YES"); } else { int val = diff[l]; boolean valid = val > 0; for (int i = l; i <= r; i++) { if (diff[i] != val) { valid = false; break; } } out.println(valid ? "YES" : "NO"); } } out.close(); } // -----------PrintWriter for faster output--------------------------------- public static PrintWriter out; // -----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // -------------------------------------------------------- }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
83684e914bcc40fcb32ed1b8ce43c8c1
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.*; public class A_600 { public static class Pair{ Pair(){ } } public static String solve(int[] arr1,int[] arr2){ ArrayList<Integer> arr=new ArrayList<>(); int flag=0; for(int i=0;i<arr1.length;i++){ arr1[i]=arr1[i]-arr2[i]; if(arr1[i]>0){ return "No"; } } int l=0; while( l<arr1.length && arr1[l]==0){ l++; } if(l==arr1.length){ return "Yes"; } int curr=arr1[l]; int r=l+1; while( r<arr1.length && arr1[r]!=0){ if(arr1[r]!=curr){ return "No"; } r++; } for(;r<arr1.length;r++){ if(arr1[r]!=0){ return "No"; } } return "Yes"; } public static void main(String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); StringBuilder str=new StringBuilder(); while(t-->0){ int n=s.nextInt(); int[] a=new int[n]; int[] b=new int[n]; for(int i=0;i<n;i++){ a[i]=s.nextInt(); } for(int i=0;i<n;i++){ b[i]=s.nextInt(); } str.append(solve(a,b)).append("\n"); } System.out.println(str); } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
0edc04fdf400d5bdf09cdb8ba240fdf4
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; public class SinglePush { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(input.readLine()); while (t-- > 0) { int n = Integer.parseInt(input.readLine()); int[] a = new int[n]; int[] b = new int[n]; StringTokenizer st = new StringTokenizer(input.readLine()); for (int i = 0; i < n; i++) a[i] = Integer.parseInt(st.nextToken()); st = new StringTokenizer(input.readLine()); for (int i = 0; i < n; i++) b[i] = Integer.parseInt(st.nextToken()); int index = 0, k = 0; boolean start = false, end = false; while (index < n) { if (a[index] > b[index]) { System.out.println("NO"); break; } if (!start && a[index] != b[index]) { k = b[index] - a[index]; start = true; } if (start && !end && b[index] - a[index] != k) { if (a[index] != b[index]) { System.out.println("NO"); break; } else { end = true; } } if (end && a[index] != b[index]) { System.out.println("NO"); break; } if (index == n - 1) { System.out.println("YES"); break; } index++; } } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
3410a661254c62d96ac565c4dcf77d5c
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; public class singlePush { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader sc = new FastReader(); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0;i<n;i++) { b[i]=sc.nextInt(); } for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } int l=0; int r=0; int k=0; for(int i=0;i<n;i++) { if(a[i]!=b[i]) { l=i; k=a[i]-b[i]; break; } } for(int i=n-1;i>=0;i--) { if(b[i]!=a[i]) { r=i; break; } } // System.out.println("k:" +k); for(int i=l;i<=r;i++) { b[i]+=k; } if(Arrays.equals(a,b) && k>=0) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
0139f1a94d12e8621923cf2fa06e7255
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.lang.System.*; import static java.util.Arrays.*; public class Main { public static void main(String[] args) throws IOException { FastScanner in = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); while (t-- > 0){ int n = in.nextInt(); int a[] = new int[n]; int b[] = new int[n]; int add = -1; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } for (int i = 0; i < n; i++) { b[i] = in.nextInt(); } boolean can = true; boolean alr = false; for (int i = 0; i < n; i++) { if(a[i] > b[i])can = false; if(add != -1 && !alr){ if(a[i] != b[i]){ a[i] += add; if(a[i] != b[i])can = false; }else{ if(a[i] != b[i])can = false; alr = true; } }else{ if(alr && a[i] != b[i])can = false; if(a[i] != b[i]) add = b[i] - a[i]; } } if(can)out.println("YES"); else out.println("NO"); } out.close(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(s)); } FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
ade09f6a29726999b4c71434dbebcfd0
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.Scanner; public class singlePush { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); for (int m = 0; m < tc; m++) { int n = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { b[i] = sc.nextInt(); } int f = 0, l = 0, r = n-1, d = 0; boolean decision = true; for (int i = 0; i < n; i++) { if (a[i] != b[i]) { if (f == 0) { f = 1; l = i; d = b[i] - a[i]; if (d < 0) { decision = false; break; } } else { int t = b[i] - a[i]; if (t != d) { decision = false; break; } } } else { if(f==1) { r=i-1; break; } } } for (int i = 0; i < n; i++) { if(a[i]!=b[i]&&i>r) { decision=false; break; } } if (decision) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
b4b623c2faabd219ecef955542460d4d
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Freaks3 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { int n = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine(), " "); int a[] = new int[n]; int b[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(st.nextToken()); } st = new StringTokenizer(br.readLine(), " "); for (int i = 0; i < n; i++) { b[i] = Integer.parseInt(st.nextToken()); } int fl = 0, ch = 0; for (int i = 0; i < n; i++) { if (a[i] > b[i]) { fl = -1; break; } if (fl == 0 && a[i] < b[i]) { fl = 1; ch = b[i] - a[i]; } if (fl == 1 && a[i] == b[i]) { fl = 2; } if (fl == 1 && (b[i] - a[i]) != ch) { fl = -1; break; } if (fl == 2 && a[i] != b[i]) { fl = -1; break; } } if (fl == -1) { System.out.println("NO"); } else { System.out.println("YES"); } } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
a2bb9a226e01d80515d3a90aa356f1e7
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.Scanner; public class n020 { static Scanner scan=new Scanner(System.in); public static int[] getarr(int n) { int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=scan.nextInt(); return arr; } public static int getint() { return scan.nextInt(); } public static long getlong() { return scan.nextLong(); } public static String getString() { return scan.nextLine(); } public static void newline() { scan.nextLine(); } public static int getMax(int[] arr) { int max=Integer.MIN_VALUE; for(int i=0;i<arr.length;i++) if(max<arr[i]) max=arr[i]; return max; } public static void printArr(int []arr) { for(int i=0;i<arr.length;i++) System.out.print(arr[i]+" "); System.out.println(); } public static void main(String[] args) { int test=getint(); while(test-->0) { int n=getint(); int org[]=getarr(n); int dup[]=getarr(n); int x=0,count=0,res=0,p=0,q=0; boolean flag=true; for(int i=0;i<n;i++) { if(org[i]!=dup[i] && flag) { p=i; flag=false; } if(org[i]!=dup[i]) { q=i; } } boolean t1=true; int rem=dup[p]-org[p]; //System.out.println(rem); //System.out.println(p+" "+q); for(int i=p;i<=q;i++) { if(dup[i]-org[i]!=rem||rem<0) { System.out.println("NO"); t1=false; break; } } if(t1) System.out.println("YES"); } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
bb18b6c6c47c3371e06634ec8a33fb3c
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.Scanner; public class n020 { static Scanner scan=new Scanner(System.in); public static int[] getarr(int n) { int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=scan.nextInt(); return arr; } public static int getint() { return scan.nextInt(); } public static long getlong() { return scan.nextLong(); } public static String getString() { return scan.nextLine(); } public static void newline() { scan.nextLine(); } public static int getMax(int[] arr) { int max=Integer.MIN_VALUE; for(int i=0;i<arr.length;i++) if(max<arr[i]) max=arr[i]; return max; } public static void printArr(int []arr) { for(int i=0;i<arr.length;i++) System.out.print(arr[i]+" "); System.out.println(); } public static void main(String[] args) { int test=getint(); while(test-->0) { int n=getint(); int org[]=getarr(n); int dup[]=getarr(n); int x=0,count=0,res=0,p=0,q=0; boolean flag=true; for(int i=0;i<n;i++) { if(org[i]!=dup[i] && flag) { p=i; flag=false; } if(org[i]!=dup[i]) { q=i; } } boolean t1=true; int rem=dup[p]-org[p]; //System.out.println(rem); //System.out.println(p+" "+q); for(int i=p;i<=q;i++) { if(dup[i]-org[i]!=rem||rem<0) { System.out.println("NO"); t1=false; break; } } if(t1) System.out.println("YES"); } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
0b5901adebca44106836c8661d3e79d6
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.*;import java.io.*;import java.math.*; public class Main { public static void process()throws IOException { int n=ni(),a[]=new int[n+1],b[]=new int[n+1],diff[]=new int[n+2]; for(int i=1;i<=n;i++) a[i]=ni(); for(int i=1;i<=n;i++){ b[i]=ni(); diff[i]=b[i]-a[i];} for(int i=1;i<=n;i++){ if(diff[i]<0){ pn("NO"); return; } } int cnt=0; for(int i=1;i<=n;){ if(diff[i]==0) { i++; continue; } cnt++; while(i<=n && diff[i]==diff[i+1]){ i++; } i++; } if(cnt==0 || cnt==1) pn("YES"); else pn("NO"); } static AnotherReader sc; static PrintWriter out; public static void main(String[]args)throws IOException { out = new PrintWriter(System.out); sc=new AnotherReader(); boolean oj = true; oj = System.getProperty("ONLINE_JUDGE") != null; if(!oj) sc=new AnotherReader(100); long s = System.currentTimeMillis(); int t=ni(); while(t-->0) process(); out.flush(); if(!oj) System.out.println(System.currentTimeMillis()-s+"ms"); System.out.close(); } static void pn(Object o){out.println(o);} static void p(Object o){out.print(o);} static void pni(Object o){out.println(o);System.out.flush();} static int ni()throws IOException{return sc.nextInt();} static long nl()throws IOException{return sc.nextLong();} static double nd()throws IOException{return sc.nextDouble();} static String nln()throws IOException{return sc.nextLine();} static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));} static boolean multipleTC=false; ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class AnotherReader{BufferedReader br; StringTokenizer st; AnotherReader()throws FileNotFoundException{ br=new BufferedReader(new InputStreamReader(System.in));} AnotherReader(int a)throws FileNotFoundException{ br = new BufferedReader(new FileReader("input.txt"));} String next()throws IOException{ while (st == null || !st.hasMoreElements()) {try{ st = new StringTokenizer(br.readLine());} catch (IOException e){ e.printStackTrace(); }} return st.nextToken(); } int nextInt() throws IOException{ return Integer.parseInt(next());} long nextLong() throws IOException {return Long.parseLong(next());} double nextDouble()throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException{ String str = ""; try{ str = br.readLine();} catch (IOException e){ e.printStackTrace();} return str;}} ///////////////////////////////////////////////////////////////////////////////////////////////////////////// }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
fa8536ac06cfd6bb7a6aeb6607a02c60
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.Locale; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { boolean isLocalRun = args.length == 1 && "localrun".equals(args[0]); new Main().run(isLocalRun); } private void solve(In in, PrintWriter pw) throws IOException { int Z = in.nextInt(); for (int z = 0; z < Z; z++) { int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = in.nextInt(); int[] b = new int[n]; for (int i = 0; i < n; i++) b[i] = in.nextInt(); Integer k = null; Integer l = null; for (int i = 0; i < n; i++) { if (a[i] != b[i]) { k = a[i] - b[i]; l = i; break; } } Integer r = null; for (int i = n - 1; i >= 0; i--) { if (a[i] != b[i]) { r = i; break; } } if (Arrays.equals(a, b)) { pw.println("YES"); } else if (k == null || k > 0) { pw.println("NO"); } else { for (int i = l; i <= r; i++) a[i] -= k; pw.println(Arrays.equals(a, b) ? "YES" : "NO"); } } } private void run(boolean isLocalRun) throws IOException { In in; if (isLocalRun) in = In.fileIO(); else in = In.stdinIO(); final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); try { solve(in, pw); } finally { pw.flush(); } } } class In { // @formatter:off private final BufferedReader br; private StringTokenizer st = null; static In stdinIO() { return new In(new InputStreamReader(System.in)); } static In fileIO() throws FileNotFoundException { return new In(new FileReader("input.txt")); } private In(Reader reader) { Locale.setDefault(Locale.US); this.br = new BufferedReader(reader); } byte nextByte() throws IOException { return Byte.parseByte(next()); } boolean nextBoolean() throws IOException { return Boolean.parseBoolean(next()); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } float nextFloat() throws IOException { return Float.parseFloat(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String next() throws IOException { while (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } // @formatter:on }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
6c842a88eebd550531ff9ec2a5be787b
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; public class B { public static void main(String[] args) throws IOException{ FastScanner fs = new FastScanner(); int test = fs.nextInt(); while(test-->0) { int n = fs.nextInt(); int[] a = fs.readArray(n); int[] b = fs.readArray(n); for(int i=0 ; i<n ; i++) { b[i]-=a[i]; } int i1 = -1, i2 = -1; for(int i=0 ; i<n ; i++) { if(b[i]!=0) { i1 = i; break; } } if(i1==-1) { System.out.println("YES"); continue; }else if(b[i1]<0) { System.out.println("NO"); continue; }else { for(int i=n-1 ; i>=0 ; i--) { if(b[i]!=0) { i2 = i; break; } } if(i2==i1) { System.out.println("YES"); continue; }else if(b[i1]!=b[i2]) { System.out.println("NO"); continue; }else { boolean is = true; for(int i=i1+1; i<=i2 ; i++) { if(b[i]!=b[i-1]) { is = false; break; } } if(is) System.out.println("YES"); else System.out.println("NO"); } } } } static boolean isPrime(long n) { for(int i=2 ; i*i<=n ; i++) { if(n%i==0) return false; } return true; } static int[] sort(int[] a) { int[] b = new int[a.length]; ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) b[i]=l.get(i); return b; } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } String[] readStringArray(int n) { String[] a=new String[n]; for (int i=0; i<n; i++) a[i]=next(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
735dc9dc02c8d3901673dcf73ea829b6
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int q = in.nextInt(); while (q-- > 0) { int n = in.nextInt(); if (n == 1) { answerIt(in.nextInt() <= in.nextInt()); continue; } int[] a = new int[n], b = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } for (int i = 0; i < n; i++) { b[i] = in.nextInt(); } if (Arrays.equals(a, b)) { answerIt(true); continue; } boolean possible = true, equalAgain = false; int D = 0; for (int i = 0; i < n; i++) { if (a[i] > b[i]) { possible = false; break; } int d = b[i] - a[i]; if (D == 0 && d != 0) { D = d; } if (D != 0 && D != d) { if (d != 0) { possible = false; break; } if (!equalAgain) { equalAgain = true; } } else { if (equalAgain) { possible = false; break; } } } answerIt(possible); } } private static void answerIt(boolean b) { System.out.println(b ? "YES" : "NO"); } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
4fd6d652b2110a3d7d52501d197e4653
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; public class a { public static void main(String[] args) throws Exception { FastScanner in = new FastScanner(System.in); int t = in.nextInt(); while (t --> 0) { int n = in.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n; i++) a[i] = in.nextInt(); for (int i = 0; i < n; i++) b[i] = in.nextInt(); int idx = 0; while (idx < n && a[idx] == b[idx]) idx++; boolean bad = false; boolean end = false; int diff = -1; for (int i = idx; i < n; i++) { if (i == idx) { if (a[i] > b[i]) { System.out.println("NO"); bad = true; break; } diff = b[i] - a[i]; continue; } if (end && a[i] != b[i]) { System.out.println("NO"); bad = true; break; } if (a[i] != b[i]) { if (a[i] + diff != b[i]) { bad = true; System.out.println("NO"); break; } } if (a[i] == b[i]) end = true; } if (!bad) System.out.println("YES"); } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream i) { br = new BufferedReader(new InputStreamReader(i)); st = new StringTokenizer(""); } public String next() throws IOException { if(st.hasMoreTokens()) return st.nextToken(); else st = new StringTokenizer(br.readLine()); return next(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
e662cc0f79693a6e6f8bc5ddc7128576
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class Solution { static int TC, N, start, end, diff; static int[] arr, arr2; static StringTokenizer st; static boolean same; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); TC = Integer.parseInt(br.readLine().trim()); for (int tc = 1; tc <= TC; tc++) { N = Integer.parseInt(br.readLine().trim()); arr = new int[N]; arr2 = new int[N]; st = new StringTokenizer(br.readLine(), " "); for (int i = 0; i < N; i++) { arr[i] = Integer.parseInt(st.nextToken()); } st = new StringTokenizer(br.readLine(), " "); for (int i = 0; i < N; i++) { arr2[i] = Integer.parseInt(st.nextToken()); } same = false; start = end = diff = -1; for (int i = 0; i < N; i++) { if (arr[i] != arr2[i]) { // λ‹€λ₯΄λ‹€λ©΄ same = true; if (start == -1) { start = end = i; diff = arr[i] - arr2[i]; } else end = i; } } if (same) { for (int i = start; i <= end; i++) { arr[i] -= diff; } } boolean yes = false; for (int i = 0; i < N; i++) { if (arr[i] != arr2[i]) yes = true; } if (!same) { bw.write("YES\n"); } else { if (!yes && diff < 0) bw.write("YES\n"); else bw.write("NO\n"); } } bw.flush(); bw.close(); } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
1b86a31df6af7a1f93ac654abfcafb58
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Cf131 implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new Cf131(),"Main",1<<27).start(); } static class Pair{ int nod; int ucn; Pair(int nod,int ucn){ this.nod=nod; this.ucn=ucn; } public static Comparator<Pair> wc = new Comparator<Pair>(){ public int compare(Pair e1,Pair e2){ //reverse order if (e1.ucn < e2.ucn) return 1; // 1 for swaping. else if (e1.ucn > e2.ucn) return -1; else{ // if(e1.siz>e2.siz) // return 1; // else // return -1; return 0; } } }; } public static long gcd(long a,long b){ if(b==0)return a; else return gcd(b,a%b); } ////recursive BFS public static int bfsr(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,int[] pre){ b[s]=true; int p = 0; int t = a[s].size(); for(int i=0;i<t;i++){ int x = a[s].get(i); if(!b[x]){ dist[x] = dist[s] + 1; p+= (bfsr(x,a,dist,b,pre)+1); } } pre[s] = p; return p; } //// iterative BFS public static int bfs(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,PrintWriter w){ b[s]=true; int siz = 0; Queue<Integer> q = new LinkedList<>(); q.add(s); while(q.size()!=0){ int i=q.poll(); // w.println(" #"+i+"# "); Iterator<Integer> it =a[i].listIterator(); int z=0; while(it.hasNext()){ z=it.next(); // w.println("#"+i+" "+z); if(!b[z]){ // w.println("* "+z+" *"); b[z]=true; dist[z] = dist[i] + 1; // w.print("*"); // w.println(i+" "+z); siz++; // x.add(z); // w.println("@ "+x.get(x.size()-1)+" @"); q.add(z); } } } return siz; } ////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int defaultValue=0; int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for(int i=0;i<n;i++)a[i]=sc.nextInt(); for(int i=0;i<n;i++)b[i] = sc.nextInt(); int x = 0; boolean f = true; boolean changed = false; for(int i=0;i<n;i++){ //if(a[i]==b[i])continue; if(a[i]>b[i]){f = false;break;} else{ if(x==0){ if(b[i] - a[i]!=0){ if(!changed){ x = b[i] - a[i]; changed=true; } else{ f = false;break; } } } else{ if(b[i]-a[i]==0){x=0;} else{ if(b[i]-a[i]!=x){f = false;break;} } } } } if(f)w.println("YES"); else w.println("NO"); } w.flush(); w.close(); } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
e5d4c2ef0f5d5048d907c0643c372f13
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; public class CF1253A extends PrintWriter { CF1253A() { super(System.out); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1253A o = new CF1253A(); o.main(); o.flush(); } void main() { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] dd = new int[n]; for (int i = 0; i < n; i++) dd[i] -= sc.nextInt(); for (int i = 0; i < n; i++) dd[i] += sc.nextInt(); int i = 0, j = n - 1; while (i <= j) if (dd[i] == 0) i++; else if (dd[j] == 0) j--; else break; boolean yes = true; if (i <= j && dd[i] < 0) yes = false; while (i < j) { if (dd[i] != dd[j]) { yes = false; break; } i++; } println(yes ? "YES" : "NO"); } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
acbb195aec5cc7abadb10be7a0ce5842
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; public class A { Random random = new Random(751454315315L + System.currentTimeMillis()); public void solve() throws IOException { int q = nextInt(); while (q-- > 0) { int n = nextInt(); int[] a = nextArr(n); int[] b = nextArr(n); for (int i = 0; i < n; i++) { b[i] -= a[i]; a[i] = b[i]; } boolean possible = true; boolean found = false; for (int i = 0; i < n; i++) { if (a[i] < 0) { possible = false; break; } if (a[i] == 0) { if (i > 0 && a[i - 1] != 0) { found = true; } continue; } if (found) { possible = false; break; } if (i > 0 && a[i - 1] > 0 && a[i] != a[i - 1]) { possible = false; break; } } if (possible) { out.println("YES"); } else { out.println("NO"); } } } public void run() { try { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } private void shuffle(int[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); int t = s[i]; s[i] = s[j]; s[j] = t; } } class Pair implements Comparable<Pair> { int f; int s; public Pair(int f, int s) { this.f = f; this.s = s; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; return f == pair.f && s == pair.s; } @Override public int hashCode() { return Objects.hash(f, s); } @Override public int compareTo(Pair o) { if (f == o.f) { return s - o.s; } return f - o.f; } } BufferedReader br; StringTokenizer in; PrintWriter out; public String nextToken() throws IOException { while (in == null || !in.hasMoreTokens()) { in = new StringTokenizer(br.readLine()); } return in.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } public long nextLong() throws IOException { return Long.parseLong(nextToken()); } public int[] nextArr(int n) throws IOException { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } public static void main(String[] args) throws IOException { Locale.setDefault(Locale.US); new A().run(); } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
5e393eb48a09b580e5edb39a601660f9
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.util.*; public class Solution { public static void main(String arg[]) { Scanner sc=new Scanner(System.in); int tc = sc.nextInt(); while(tc-- > 0) { int n = sc.nextInt(); int [] a = new int[n]; int [] b = new int[n]; for(int i=0;i<n;i++) { a[i] = sc.nextInt(); } for(int i=0;i<n;i++) { b[i] = sc.nextInt(); } boolean dif = false; boolean difAllreadyFound = false; String sol = "YES"; int c = 0; for(int i=0;i<n;i++) { int ab = b[i] - a[i]; if(dif) { if(ab == 0) { dif = false; } else if(ab != c ) { sol = "NO"; break; } } else if(ab != 0) { if(difAllreadyFound) { sol = "NO"; break; } else { difAllreadyFound = true; dif = true; c = ab; if(c < 0) { sol = "NO"; break; } } } } System.out.println(sol); } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
2c17dd21dca9262c0678d16cf7c75b50
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; public class test { /* * array list * * ArrayList<Integer> al=new ArrayList<>(); creating BigIntegers * * BigInteger a=new BigInteger(); BigInteger b=new BigInteger(); * * hash map * * HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>(); for(int * i=0;i<ar.length;i++) { Integer c=hm.get(ar[i]); if(hm.get(ar[i])==null) { * hm.put(ar[i],1); } else { hm.put(ar[i],++c); } } * * while loop * * int t=sc.nextInt(); while(t>0) { t--; } * * array input * * int n = sc.nextInt(); int ar[] = new int[n]; for (int i = 0; i < ar.length; * i++) { ar[i] = sc.nextInt(); } */ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static final Scanner sc = new Scanner(System.in); private static final FastReader fs = new FastReader(); public static void main(String[] args) { int t = sc.nextInt(); while (t > 0) { int n = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { b[i] = sc.nextInt(); } int start = 0; boolean s = false; boolean e = false; boolean ans = true; for (int i = 0; i < n; i++) { if (a[i] == b[i]) continue; else if (a[i] > b[i]) { ans = false; break; } else { start = i; break; } } int end = n-1; if (ans) { for (int i = start; i < n; i++) { if (a[i] == b[i]) { end = i - 1; break; } else if (a[i] > b[i]) { ans = false; break; } } } int k = b[start] - a[start]; for (int j = start; j <= end; j++) { a[j] += k; } if (ans) { if (Arrays.equals(a, b)) System.out.println("YES"); else System.out.println("NO"); } else System.out.println("NO"); t--; } } }/* till here */
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
ef89c7ac1cde0bcac8b16648c9b30a26
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.io.*; import java.util.*; public class Solution { static int MAX = (int)1e5+1; public static void main(String[] args)throws Exception{ //InputReader input = new InputReader(System.in); Scanner input = new Scanner(System.in); OutputStreamWriter out = new OutputStreamWriter(System.out); int test = input.nextInt(); while(test-->0){ int n = input.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for(int i =0;i<n;i++)a[i] = input.nextInt(); for(int i =0;i<n;i++)b[i] = input.nextInt(); HashSet<Integer>set = new HashSet<>(); int l =0,r=0; for(int i =0;i<n;i++) { if(a[i] == b[i])continue; else { l = i; while(i<n && a[i] != b[i]) { i++; } r =i-1; } } int ans = b[r]-a[r]; boolean ok = true; if(ans<0)ok = false; for(int i = l;i<=r;i++) { a[i]+=ans; } for(int i =0;i<n;i++) { if(a[i] != b[i])ok = false; } if(ok)System.out.println("YES"); else System.out.println("NO"); } } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public double readDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
e0c77bbeaed9cceb35476f82d72d7d35
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
import java.awt.*; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Array; import java.util.*; public class Main { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } //********************************************************* VENI VIDI VICI **************************************************************\\ public static void main(String[] args) throws IOException { Reader r = new Reader(); int t = r.nextInt(); while (t-- > 0) { int n = r.nextInt(); int[] a = new int[n]; int[] b = new int[n]; boolean temp = true; for (int i = 0; i < n; i++) { a[i] = r.nextInt(); } for (int i = 0; i < n; i++) { b[i] = r.nextInt(); } for(int i=0;i<n;i++){ if(a[i]!=b[i]) temp = false; } if(temp) System.out.println("YES"); else { ArrayList<Integer> al = new ArrayList<>(); for (int i = 0; i < n; i++) { if (a[i] != b[i]) al.add(i); } boolean flag = true; int left = al.get(0); int right = al.get(al.size() - 1); int k = b[al.get(0)] - a[al.get(0)]; for (int i = left; i <= right; i++) { a[i] += k; } for (int i = 0; i < n; i++) { if (a[i] != b[i]) flag = false; } if (flag && k > 0) System.out.println("YES"); else System.out.println("NO"); } } } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
44915a876bc9ce6056f8f64e2fa200e2
train_001.jsonl
1573914900
You're given two arrays $$$a[1 \dots n]$$$ and $$$b[1 \dots n]$$$, both of the same length $$$n$$$.In order to perform a push operation, you have to choose three integers $$$l, r, k$$$ satisfying $$$1 \le l \le r \le n$$$ and $$$k &gt; 0$$$. Then, you will add $$$k$$$ to elements $$$a_l, a_{l+1}, \ldots, a_r$$$.For example, if $$$a = [3, 7, 1, 4, 1, 2]$$$ and you choose $$$(l = 3, r = 5, k = 2)$$$, the array $$$a$$$ will become $$$[3, 7, \underline{3, 6, 3}, 2]$$$.You can do this operation at most once. Can you make array $$$a$$$ equal to array $$$b$$$?(We consider that $$$a = b$$$ if and only if, for every $$$1 \le i \le n$$$, $$$a_i = b_i$$$)
256 megabytes
//template import java.util.*; import java.util.stream.Stream; import java.io.*; public class Main{ static BufferedReader in= new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); public static void main(String[] args) throws IOException{ int t=Integer.parseInt(in.readLine()); z:while(t-->0) { int n=Integer.parseInt(in.readLine()); int[] a=readInts(); int[] b=readInts(); boolean f=false; int d=Integer.MAX_VALUE; for(int i=0;i<n;i++) { if(a[i]!=b[i]) { if(!f) { if(d!=Integer.MAX_VALUE) { out.append("NO\n"); continue z; } f=true; d=b[i]-a[i]; }else { if(d!=b[i]-a[i]) { out.append("NO\n"); continue z; } } }else { f=false; } } if(d<0) out.append("NO\n"); else out.append("YES\n"); } out.flush(); in.close(); out.close(); } public static boolean palindrome(String s) { boolean palindrome=true; int i=0,j=s.length()-1; while(i<j&&palindrome) { if(s.charAt(i++)!=s.charAt(j--)) palindrome=false; } return palindrome; } public static long reverse(String s) { String aux=""; for(int i=s.length()-1;i>=0;i--) { aux+=s.charAt(i); } return Long.parseLong(aux); } private static int modulo(int S, int N) { return ((S) & (N - 1)); } // returns S % N, where N is a power of 2 private static int isPowerOfTwo(int S) { return (S & (S - 1)) == 0 ? 1 : 0; } private static int[] readInts() throws IOException { return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } private static int readInt() throws IOException { return Integer.parseInt(in.readLine()); } private static long[] readLongs() throws IOException { return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray(); } private static long readLong() throws IOException { return Long.parseLong(in.readLine()); } }
Java
["4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6"]
1 second
["YES\nNO\nYES\nNO"]
NoteThe first test case is described in the statement: we can perform a push operation with parameters $$$(l=3, r=5, k=2)$$$ to make $$$a$$$ equal to $$$b$$$.In the second test case, we would need at least two operations to make $$$a$$$ equal to $$$b$$$.In the third test case, arrays $$$a$$$ and $$$b$$$ are already equal.In the fourth test case, it's impossible to make $$$a$$$ equal to $$$b$$$, because the integer $$$k$$$ has to be positive.
Java 11
standard input
[ "implementation" ]
0e0ef011ebe7198b7189fce562b7d6c1
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) β€” the number of test cases in the input. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100\ 000$$$) β€” the number of elements in each array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,000
For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing at most once the described operation or "NO" if it's impossible. You can print each letter in any case (upper or lower).
standard output
PASSED
42728142432a3fafe7196409af24495e
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.StringTokenizer; import java.util.stream.Stream; public class Solution implements Runnable { static final double time = 1e9; static final int MOD = (int) 1e9 + 7; static final long mh = Long.MAX_VALUE; static final Reader in = new Reader(); static final PrintWriter out = new PrintWriter(System.out); StringBuilder answer = new StringBuilder(); public static void main(String[] args) { new Thread(null, new Solution(), "persefone", 1 << 28).start(); } @Override public void run() { long start = System.nanoTime(); solve(); printf(); long elapsed = System.nanoTime() - start; // out.println("stamp : " + elapsed / time); // out.println("stamp : " + TimeUnit.SECONDS.convert(elapsed, TimeUnit.NANOSECONDS)); close(); } void solve() { String text = in.next(); int n = in.nextInt(); String[] pattern = new String[n]; for (int i = 0; i < n; i++) pattern[i] = in.next(); int t = text.length(); int[] ri = new int[t]; Arrays.fill(ri, Integer.MAX_VALUE); for (String s : pattern) { int l = s.length(); for (int i = 0; i <= t - l; i++) if (text.substring(i, i + l).equals(s)) ri[i] = min(ri[i], i + l - 1); } int max = 0, pos = t - 1; if (ri[t - 1] == Integer.MAX_VALUE) { max = 1; ri[t - 1] = t; } for (int i = t - 2; i > -1; i--) { if (ri[i] >= ri[i + 1]) ri[i] = ri[i + 1]; if (ri[i] - i > max) { max = ri[i] - i; pos = i; } } if (max != 0) printf(max + " " + pos); else printf("0 0"); } void printf() { out.print(answer); } void close() { out.close(); } void printf(Stream<?> str) { str.forEach(o -> add(o, " ")); add("\n"); } void printf(Object... obj) { printf(false, obj); } void printfWithDescription(Object... obj) { printf(true, obj); } private void printf(boolean b, Object... obj) { if (obj.length > 1) { for (int i = 0; i < obj.length; i++) { if (b) add(obj[i].getClass().getSimpleName(), " - "); if (obj[i] instanceof Collection<?>) { printf((Collection<?>) obj[i]); } else if (obj[i] instanceof int[][]) { printf((int[][])obj[i]); } else if (obj[i] instanceof long[][]) { printf((long[][])obj[i]); } else if (obj[i] instanceof double[][]) { printf((double[][])obj[i]); } else printf(obj[i]); } return; } if (b) add(obj[0].getClass().getSimpleName(), " - "); printf(obj[0]); } void printf(Object o) { if (o instanceof int[]) printf(Arrays.stream((int[]) o).boxed()); else if (o instanceof char[]) printf(new String((char[]) o)); else if (o instanceof long[]) printf(Arrays.stream((long[]) o).boxed()); else if (o instanceof double[]) printf(Arrays.stream((double[]) o).boxed()); else add(o, "\n"); } void printf(int[]... obj) { for (int i = 0; i < obj.length; i++) printf(obj[i]); } void printf(long[]... obj) { for (int i = 0; i < obj.length; i++) printf(obj[i]); } void printf(double[]... obj) { for (int i = 0; i < obj.length; i++) printf(obj[i]); } void printf(Collection<?> col) { printf(col.stream()); } <T, K> void add(T t, K k) { if (t instanceof Collection<?>) { ((Collection<?>) t).forEach(i -> add(i, " ")); } else if (t instanceof Object[]) { Arrays.stream((Object[]) t).forEach(i -> add(i, " ")); } else add(t); add(k); } <T> void add(T t) { answer.append(t); } @SuppressWarnings("unchecked") <T extends Comparable<? super T>> T min(T... t) { if (t.length == 0) return null; T m = t[0]; for (int i = 1; i < t.length; i++) if (t[i].compareTo(m) < 0) m = t[i]; return m; } @SuppressWarnings("unchecked") <T extends Comparable<? super T>> T max(T... t) { if (t.length == 0) return null; T m = t[0]; for (int i = 1; i < t.length; i++) if (t[i].compareTo(m) > 0) m = t[i]; return m; } int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } long gcd(long a, long b) { return (b == 0) ? a : gcd(b, a % b); } // c = gcd(a, b) -> extends gcd method: ax + by = c <----> (b % a)p + q = c; int[] ext_gcd(int a, int b) { if (b == 0) return new int[] {a, 1, 0 }; int[] vals = ext_gcd(b, a % b); int d = vals[0]; // gcd int p = vals[2]; // int q = vals[1] - (a / b) * vals[2]; return new int[] { d, p, q }; } // find any solution of the equation: ax + by = c using extends gcd boolean find_any_solution(int a, int b, int c, int[] root) { int[] vals = ext_gcd(Math.abs(a), Math.abs(b)); if (c % vals[0] != 0) return false; printf(vals); root[0] = c * vals[1] / vals[0]; root[1] = c * vals[2] / vals[0]; if (a < 0) root[0] *= -1; if (b < 0) root[1] *= -1; return true; } int mod(int x) { return x % MOD; } int mod(int x, int y) { return mod(mod(x) + mod(y)); } long mod(long x) { return x % MOD; } long mod (long x, long y) { return mod(mod(x) + mod(y)); } int lw(long[] f, int l, int r, long k) { int R = r, m = 0; while (l <= r) { m = l + r >> 1; if (m == R) return m; if (f[m] >= k) r = m - 1; else l = m + 1; } return l; } int up(long[] f, int l, int r, long k) { int R = r, m = 0; while (l <= r) { m = l + r >> 1; if (m == R) return m; if (f[m] > k) r = m - 1; else l = m + 1; } return l; } int lw(int[] f, int l, int r, int k) { int R = r, m = 0; while (l <= r) { m = l + r >> 1; if (m == R) return m; if (f[m] >= k) r = m - 1; else l = m + 1; } return l; } int up(int[] f, int l, int r, int k) { int R = r, m = 0; while (l <= r) { m = l + r >> 1; if (m == R) return m; if (f[m] > k) r = m - 1; else l = m + 1; } return l; } static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>> implements Comparable<Pair<K, V>> { private K k; private V v; Pair() {} Pair(K k, V v) { this.k = k; this.v = v; } K getK() { return k; } V getV() { return v; } void setK(K k) { this.k = k; } void setV(V v) { this.v = v; } void setKV(K k, V v) { this.k = k; this.v = v; } @SuppressWarnings("unchecked") @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof Pair)) return false; Pair<K, V> p = (Pair<K, V>) o; return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0; } @Override public int hashCode() { int hash = 31; hash = hash * 89 + k.hashCode(); hash = hash * 89 + v.hashCode(); return hash; } @Override public int compareTo(Pair<K, V> pair) { return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k); } @Override public Pair<K, V> clone() { return new Pair<K, V>(this.k, this.v); } @Override public String toString() { return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n"); } } static class Reader { private BufferedReader br; private StringTokenizer st; Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } long nextLong() { return Long.parseLong(next()); } String nextLine() { String s = ""; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 8
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
8d6d25bbc4409b4dca35d1bf0c0a57f0
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class F { static String[] f = new String[] { "Carrots", "Kiwis", "Grapes"}; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); char[] s = sc.next().toCharArray(); int t = sc.nextInt(); String[] subs = new String[t]; for(int i = 0; i < t; ++i) subs[i] = sc.next(); int pos = 0, len = 0; ll: for(int i = 0, j = 0; j < s.length; ++j) { for(int k = 0; k < t; ++k) { int idx = j - subs[k].length() + 1; if(idx >= i && equal(s, idx, subs[k])) { i = idx + 1; --j; continue ll; } } if(j - i + 1 > len) { len = j - i + 1; pos = i; } } out.println(len + " " + pos); out.close(); } static boolean equal(char[] s, int k, String t) { for(int i = 0; i < t.length(); ++i) if(s[i + k] != t.charAt(i)) return false; return true; } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public boolean ready() throws IOException {return br.ready();} } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 8
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
ab3fc013c737a145420763f5c8cab377
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.TreeSet; import java.util.ArrayList; import java.io.BufferedOutputStream; import java.util.StringTokenizer; import java.io.Writer; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author An Almost Retired Guy */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, InputReader in, OutputWriter out) { char[] str = in.nextCharArray(); int n = in.nextInt(); TreeSet<PairLong> set = new TreeSet<>(); ArrayList<PairLong>[] list = new ArrayList[str.length]; for (int i = 0; i < str.length; i++) list[i] = new ArrayList<>(); for (int i = 0; i < n; i++) { char[] P = in.nextCharArray(); for (int j = 0; j + P.length <= str.length; j++) { boolean valid = true; for (int k = 0; k < P.length; k++) if (str[j + k] != P[k]) valid = false; if (valid) { PairLong pair = new PairLong(j + P.length, i); set.add(pair); list[j].add(pair); } } } int len = 0, pos = 0; for (int i = 0; i < str.length; i++) { int end = set.isEmpty() ? str.length : (int) set.first().first - 1, start = i; if (end - start > len) { len = end - start; pos = start; } for (PairLong pair : list[i]) set.remove(pair); } out.println(len + " " + pos); } } static class OutputWriter extends PrintWriter { public OutputWriter(OutputStream outputStream) { super(new BufferedOutputStream(outputStream)); } public OutputWriter(Writer writer) { super(writer); } public void close() { super.close(); } } static class PairLong implements Comparable<PairLong> { public final long first; public final long second; public PairLong(long first, long second) { this.first = first; this.second = second; } public int hashCode() { int hu = (int) (first ^ (first >>> 32)); int hv = (int) (second ^ (second >>> 32)); return 31 * hu + hv; } public boolean equals(Object o) { PairLong other = (PairLong) o; return first == other.first && second == other.second; } public int compareTo(PairLong other) { return Long.compare(first, other.first) != 0 ? Long.compare(first, other.first) : Long.compare(second, other.second); } public String toString() { return "[u=" + first + ", v=" + second + "]"; } } static class InputReader { BufferedReader br; StringTokenizer st; public InputReader(InputStream inputStream) { br = new BufferedReader(new InputStreamReader(inputStream)); } public String next() { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(nextLine()); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public String nextString() { return next(); } public char[] nextCharArray() { return nextString().toCharArray(); } public String nextLine() { try { return br.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 8
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
ee3adc23259ceb974d074ce3aaedf933
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } } class TaskC { public void solve(int testNumber, InputReader in, OutputWriter out) { String s = in.nextLine(); int n = Integer.parseInt(in.nextLine()); String[] b = new String[n]; for (int i = 0; i < n; ++i) b[i] = in.nextLine(); int[] ans = new int[s.length()]; Arrays.fill(ans, Integer.MAX_VALUE); for (String c : b) { int[] ans2 = new int[s.length()]; for (int i = Math.max(0, s.length() - c.length() + 1); i < s.length(); ++i) ans2[i] = s.length() - i; for (int i = s.length() - c.length(); i >= 0; --i) if (s.charAt(i) != c.charAt(0) || !s.substring(i, i + c.length()).equals(c)) ans2[i] = i == ans2.length - 1 ? 1 : ans2[i + 1] + 1; else ans2[i] = c.length() - 1; for (int i = 0; i < ans.length; ++i) ans[i] = Math.min(ans[i], ans2[i]); } int i_max = 0, len_max = 0; for (int i = 0; i < ans.length; ++i) if (ans[i] > len_max) { i_max = i; len_max = ans[i]; } out.print(len_max, i_max); } } class InputReader { BufferedReader br; public InputReader(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public InputReader(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } public String nextLine() { try { return br.readLine(); } catch (IOException e) { e.printStackTrace(); } return null; } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void close() { writer.close(); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 8
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
d5e918e95434b67fa3d9591ad8fdb7e1
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); c79 solver = new c79(); solver.solve(1, in, out); out.close(); } static class c79 { public void solve(int testNumber, InputReader in, PrintWriter out) { String s = in.next(); int n = in.nextInt(); String[] b = new String[n]; for (int i = 0; i < n; i++) { b[i] = in.next(); } int[] finish = new int[s.length()]; for (int i = 0; i < s.length(); i++) { finish[i] = s.length(); } for (int i = 0; i < n; i++) { for (int j = 0; j < s.length(); j++) { int same = 0; for (int k = 0; k < b[i].length(); k++) { if (j + k >= s.length()) break; if (s.charAt(j + k) == b[i].charAt(k)) { same++; } } if (same == b[i].length()) { finish[j] = Math.min(finish[j], j + b[i].length() - 1); } } } for (int i = s.length() - 2; i >= 0; i--) { finish[i] = Math.min(finish[i], finish[i + 1]); } int ans = 0; int ansInd = 0; for (int i = 0; i < s.length(); i++) { int cur = finish[i] - i; if (ans < cur) { ans = cur; ansInd = i; } } out.println(ans + " " + ansInd); } } static class InputReader { private BufferedReader reader; private StringTokenizer stt; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { return null; } } public String next() { while (stt == null || !stt.hasMoreTokens()) { stt = new StringTokenizer(nextLine()); } return stt.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 8
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
30384a398b6f47e03827005506eb47ae
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Solution{ static void getZarr(String str,int[] z){ int n = str.length(); int l=0,r=0; for(int i=1;i<n;i++){ if(i>r){ l = r = i; while(r<n && str.charAt(r-l)==str.charAt(r)) r++; z[i] = r-l; r--; }else{ int k = i-l; if(z[k]<r-i+1) z[i] = z[k]; else{ l = i; while(r<n && str.charAt(r-l)==str.charAt(r)) r++; z[i] = r-l; r--; } } } } public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; //PrintWriter out = new PrintWriter(System.out); String s = br.readLine(); st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); String[] a = new String[n]; for(int i=0;i<n;i++) a[i] = br.readLine(); int[] fin = new int[s.length()]; Arrays.fill(fin,-1); for(int i=0;i<n;i++){ String str = a[i] + "$" + s; int[] z = new int[a[i].length() + 1 + s.length()]; getZarr(str,z); int ind = 0; for(int j=0;j<s.length();j++){ ind = j + a[i].length() + 1; if(z[ind]==a[i].length()){ if(fin[j]==-1) fin[j] = z[ind]; else fin[j] = (int) Math.min(fin[j],z[ind]); } } } //for(int i=0;i<s.length();i++) System.out.print(fin[i]+" "); boolean first = true; int val = 0; for(int i=s.length()-1;i>=0;i--){ if(fin[i]!=-1){ if(first){ first = false; val = i+fin[i]-2; }else{ if(val<i+fin[i]-2){ fin[i] = val - i + 2; }else { val = i + fin[i] - 2; } } } } TreeSet<Integer> begin = new TreeSet<Integer>(); TreeMap<Integer,Integer> end = new TreeMap<Integer,Integer>(); begin.add(0); if(fin[s.length()-1]==-1) end.put(s.length()-1,1); for(int i=0;i<s.length();i++){ if(fin[i]!=-1){ if(i<s.length()-1) begin.add(i+1); if(!end.containsKey(i+fin[i]-2)) end.put(i+fin[i]-2,1); else { int nb = end.get(i+fin[i]-2) + 1; end.put(i+fin[i]-2,nb); } } } //System.out.println(begin.size()+" "+end.size()); int max = 0; int place = 0; while(!end.isEmpty()){ int pos = end.ceilingKey(-1); int nb = end.get(pos); end.remove(pos); //System.out.println(" "+pos+" "+nb); while(nb>0){ nb--; int beg = begin.pollFirst(); //System.out.println(beg); if(pos-beg+1>max){ max = pos-beg+1; place = beg; } } } System.out.println(max+" "+place); //out.flush(); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 8
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
8efbc1f4d4e1b05c88ad0f7f192c30b9
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.math.*; import java.util.*; public class icpc { public static void main(String[] args) throws IOException { // Reader in = new Reader(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s = in.readLine(); int n = Integer.parseInt(in.readLine()); String[] A = new String[n]; for (int i=0;i<n;i++) A[i] = in.readLine(); KMPAlgorithm kmpAlgorithm = new KMPAlgorithm(); ArrayList<Game> B = new ArrayList<>(); ArrayList<Integer>[] adj = (ArrayList<Integer>[])new ArrayList[s.length()]; for (int i=0;i<s.length();i++) adj[i] = new ArrayList<>(); for (int i=0;i<n;i++) { ArrayList<Integer> indices = kmpAlgorithm.KMPMatcher(s.toCharArray(), A[i].toCharArray()); for (int j=0;j<indices.size();j++) adj[indices.get(j)].add(A[i].length()); } for (int i=0;i<s.length();i++) Collections.sort(adj[i]); int[] right = new int[s.length()]; PriorityQueue<Integer> pq = new PriorityQueue<>(); pq.add(s.length()); for (int i = s.length() - 1;i>=0;i--) { if (adj[i].size() == 0) continue; else { int x = pq.poll(); int y = adj[i].get(0) + i - 1; right[i] = Math.min(x, y); pq.add(x); pq.add(y); } } int max = Integer.MIN_VALUE; int pos = 0; int last = 0; for (int i=0;i<s.length();i++) { if (adj[i].size() > 0) { int length = right[i] - last; if (length > max) { max = length; pos = last; } last = i + 1; } } if (s.length() - last > max) { max = s.length() - last; pos = last; } System.out.println(max + " " + pos); } } class Game { int a; int b; public Game(int a, int b) { this.a = a; this.b = b; } } class NumberTheory { public boolean isPrime(long n) { if(n < 2) return false; for(long x = 2;x * x <= n;x++) { if(n % x == 0) return false; } return true; } public ArrayList<Long> primeFactorisation(long n) { ArrayList<Long> f = new ArrayList<>(); for(long x=2;x * x <= n;x++) { while(n % x == 0) { f.add(x); n /= x; } } if(n > 1) f.add(n); return f; } public int[] sieveOfEratosthenes(int n) { int[] sieve = new int[n + 1]; for(int x=2;x<=n;x++) { if(sieve[x] != 0) continue; sieve[x] = x; for(int u=2*x;u<=n;u+=x) if(sieve[u] == 0) sieve[u] = x; } return sieve; } public long gcd(long a, long b) { if(b == 0) return a; return gcd(b, a % b); } public long phi(long n) { double result = n; for(long p=2;p*p<=n;p++) { if(n % p == 0) { while (n % p == 0) n /= p; result *= (1.0 - (1.0 / (double)p)); } } if(n > 1) result *= (1.0 - (1.0 / (double)n)); return (long)result; } public Name extendedEuclid(long a, long b) { if(b == 0) return new Name(a, 1, 0); Name n1 = extendedEuclid(b, a % b); Name n2 = new Name(n1.d, n1.y, n1.x - (long)Math.floor((double)a / b) * n1.y); return n2; } public long modularExponentiation(long a, long b, long n) { long d = 1L; String bString = Long.toBinaryString(b); for(int i=0;i<bString.length();i++) { d = (d * d) % n; if(bString.charAt(i) == '1') d = (d * a) % n; } return d; } } class Name { long d; long x; long y; public Name(long d, long x, long y) { this.d = d; this.x = x; this.y = y; } } class SuffixArray { int ALPHABET_SZ = 256, N; int[] T, lcp, sa, sa2, rank, tmp, c; public SuffixArray(String str) { this(toIntArray(str)); } private static int[] toIntArray(String s) { int[] text = new int[s.length()]; for (int i = 0; i < s.length(); i++) text[i] = s.charAt(i); return text; } public SuffixArray(int[] text) { T = text; N = text.length; sa = new int[N]; sa2 = new int[N]; rank = new int[N]; c = new int[Math.max(ALPHABET_SZ, N)]; construct(); kasai(); } private void construct() { int i, p, r; for (i = 0; i < N; ++i) c[rank[i] = T[i]]++; for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1]; for (i = N - 1; i >= 0; --i) sa[--c[T[i]]] = i; for (p = 1; p < N; p <<= 1) { for (r = 0, i = N - p; i < N; ++i) sa2[r++] = i; for (i = 0; i < N; ++i) if (sa[i] >= p) sa2[r++] = sa[i] - p; Arrays.fill(c, 0, ALPHABET_SZ, 0); for (i = 0; i < N; ++i) c[rank[i]]++; for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1]; for (i = N - 1; i >= 0; --i) sa[--c[rank[sa2[i]]]] = sa2[i]; for (sa2[sa[0]] = r = 0, i = 1; i < N; ++i) { if (!(rank[sa[i - 1]] == rank[sa[i]] && sa[i - 1] + p < N && sa[i] + p < N && rank[sa[i - 1] + p] == rank[sa[i] + p])) r++; sa2[sa[i]] = r; } tmp = rank; rank = sa2; sa2 = tmp; if (r == N - 1) break; ALPHABET_SZ = r + 1; } } private void kasai() { lcp = new int[N]; int[] inv = new int[N]; for (int i = 0; i < N; i++) inv[sa[i]] = i; for (int i = 0, len = 0; i < N; i++) { if (inv[i] > 0) { int k = sa[inv[i] - 1]; while ((i + len < N) && (k + len < N) && T[i + len] == T[k + len]) len++; lcp[inv[i] - 1] = len; if (len > 0) len--; } } } } class ZAlgorithm { public int[] calculateZ(char input[]) { int Z[] = new int[input.length]; int left = 0; int right = 0; for(int k = 1; k < input.length; k++) { if(k > right) { left = right = k; while(right < input.length && input[right] == input[right - left]) { right++; } Z[k] = right - left; right--; } else { //we are operating inside box int k1 = k - left; //if value does not stretches till right bound then just copy it. if(Z[k1] < right - k + 1) { Z[k] = Z[k1]; } else { //otherwise try to see if there are more matches. left = k; while(right < input.length && input[right] == input[right - left]) { right++; } Z[k] = right - left; right--; } } } return Z; } public ArrayList<Integer> matchPattern(char text[], char pattern[]) { char newString[] = new char[text.length + pattern.length + 1]; int i = 0; for(char ch : pattern) { newString[i] = ch; i++; } newString[i] = '$'; i++; for(char ch : text) { newString[i] = ch; i++; } ArrayList<Integer> result = new ArrayList<>(); int Z[] = calculateZ(newString); for(i = 0; i < Z.length ; i++) { if(Z[i] == pattern.length) { result.add(i - pattern.length - 1); } } return result; } } class KMPAlgorithm { public int[] computeTemporalArray(char[] pattern) { int[] lps = new int[pattern.length]; int index = 0; for(int i=1;i<pattern.length;) { if(pattern[i] == pattern[index]) { lps[i] = index + 1; index++; i++; } else { if(index != 0) { index = lps[index - 1]; } else { lps[i] = 0; i++; } } } return lps; } public ArrayList<Integer> KMPMatcher(char[] text, char[] pattern) { int[] lps = computeTemporalArray(pattern); int j = 0; int i = 0; int n = text.length; int m = pattern.length; ArrayList<Integer> indices = new ArrayList<>(); while(i < n) { if(pattern[j] == text[i]) { i++; j++; } if(j == m) { indices.add(i - j); j = lps[j - 1]; } else if(i < n && pattern[j] != text[i]) { if(j != 0) j = lps[j - 1]; else i = i + 1; } } return indices; } } class Hashing { public long[] computePowers(long p, int n, long m) { long[] powers = new long[n]; powers[0] = 1; for(int i=1;i<n;i++) { powers[i] = (powers[i - 1] * p) % m; } return powers; } public long computeHash(String s) { long p = 31; long m = 1_000_000_009; long hashValue = 0L; long[] powers = computePowers(p, s.length(), m); for(int i=0;i<s.length();i++) { char ch = s.charAt(i); hashValue = (hashValue + (ch - 'a' + 1) * powers[i]) % m; } return hashValue; } } class BasicFunctions { public long min(long[] A) { long min = Long.MAX_VALUE; for(int i=0;i<A.length;i++) { min = Math.min(min, A[i]); } return min; } public long max(long[] A) { long max = Long.MAX_VALUE; for(int i=0;i<A.length;i++) { max = Math.max(max, A[i]); } return max; } } class Matrix { long a; long b; long c; long d; public Matrix(long a, long b, long c, long d) { this.a = a; this.b = b; this.c = c; this.d = d; } } class MergeSortInt { // Merges two subarrays of arr[]. // First subarray is arr[l..m] // Second subarray is arr[m+1..r] void merge(int arr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ int L[] = new int[n1]; int R[] = new int[n2]; /*Copy data to temp arrays*/ for (int i = 0; i < n1; ++i) L[i] = arr[l + i]; for (int j = 0; j < n2; ++j) R[j] = arr[m + 1 + j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } // Main function that sorts arr[l..r] using // merge() void sort(int arr[], int l, int r) { if (l < r) { // Find the middle point int m = (l + r) / 2; // Sort first and second halves sort(arr, l, m); sort(arr, m + 1, r); // Merge the sorted halves merge(arr, l, m, r); } } } class MergeSortLong { // Merges two subarrays of arr[]. // First subarray is arr[l..m] // Second subarray is arr[m+1..r] void merge(long arr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ long L[] = new long[n1]; long R[] = new long[n2]; /*Copy data to temp arrays*/ for (int i = 0; i < n1; ++i) L[i] = arr[l + i]; for (int j = 0; j < n2; ++j) R[j] = arr[m + 1 + j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } // Main function that sorts arr[l..r] using // merge() void sort(long arr[], int l, int r) { if (l < r) { // Find the middle point int m = (l + r) / 2; // Sort first and second halves sort(arr, l, m); sort(arr, m + 1, r); // Merge the sorted halves merge(arr, l, m, r); } } } class Node { int sum; int len; Node(int a, int b) { this.sum = a; this.len = b; } @Override public boolean equals(Object ob) { if(ob == null) return false; if(!(ob instanceof Node)) return false; if(ob == this) return true; Node obj = (Node)ob; if(this.sum == obj.sum && this.len == obj.len) return true; return false; } @Override public int hashCode() { return (int)this.len; } } class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } class FenwickTree { public void update(long[] fenwickTree,long delta,int index) { index += 1; while(index < fenwickTree.length) { fenwickTree[index] += delta; index = index + (index & (-index)); } } public long prefixSum(long[] fenwickTree,int index) { long sum = 0L; index += 1; while(index > 0) { sum += fenwickTree[index]; index -= (index & (-index)); } return sum; } } class SegmentTree { public int nextPowerOfTwo(int num) { if(num == 0) return 1; if(num > 0 && (num & (num - 1)) == 0) return num; while((num &(num - 1)) > 0) { num = num & (num - 1); } return num << 1; } public int[] createSegmentTree(int[] input) { int np2 = nextPowerOfTwo(input.length); int[] segmentTree = new int[np2 * 2 - 1]; for(int i=0;i<segmentTree.length;i++) segmentTree[i] = Integer.MIN_VALUE; constructSegmentTree(segmentTree,input,0,input.length-1,0); return segmentTree; } private void constructSegmentTree(int[] segmentTree,int[] input,int low,int high,int pos) { if(low == high) { segmentTree[pos] = input[low]; return; } int mid = (low + high)/ 2; constructSegmentTree(segmentTree,input,low,mid,2*pos + 1); constructSegmentTree(segmentTree,input,mid+1,high,2*pos + 2); segmentTree[pos] = Math.max(segmentTree[2*pos + 1],segmentTree[2*pos + 2]); } public int rangeMinimumQuery(int []segmentTree,int qlow,int qhigh,int len) { return rangeMinimumQuery(segmentTree,0,len-1,qlow,qhigh,0); } private int rangeMinimumQuery(int segmentTree[],int low,int high,int qlow,int qhigh,int pos) { if(qlow <= low && qhigh >= high){ return segmentTree[pos]; } if(qlow > high || qhigh < low){ return Integer.MIN_VALUE; } int mid = (low+high)/2; return Math.max(rangeMinimumQuery(segmentTree, low, mid, qlow, qhigh, 2 * pos + 1), rangeMinimumQuery(segmentTree, mid + 1, high, qlow, qhigh, 2 * pos + 2)); } } class Trie { private class TrieNode { Map<Character, TrieNode> children; boolean endOfWord; public TrieNode() { children = new HashMap<>(); endOfWord = false; } } private final TrieNode root; public Trie() { root = new TrieNode(); } public void insert(String word) { TrieNode current = root; for (int i=0;i<word.length();i++) { char ch = word.charAt(i); TrieNode node = current.children.get(ch); if (node == null) { node = new TrieNode(); current.children.put(ch, node); } current.endOfWord = true; } } public boolean search(String word) { TrieNode current = root; for (int i=0;i<word.length();i++) { char ch = word.charAt(i); TrieNode node = current.children.get(ch); if (node == null) return false; current = node; } return current.endOfWord; } public void delete(String word) { delete(root, word, 0); } private boolean delete(TrieNode current, String word, int index) { if (index == word.length()) { if (!current.endOfWord) return false; current.endOfWord = false; return current.children.size() == 0; } char ch = word.charAt(index); TrieNode node = current.children.get(ch); if (node == null) return false; boolean shouldDeleteCurrentNode = delete(node, word, index + 1); if (shouldDeleteCurrentNode) { current.children.remove(ch); return current.children.size() == 0; } return false; } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 8
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
26b5f63129adc45eb60c7a0644a33f75
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.util.Vector; /** * 4 4 * 1 5 3 4 * 1 2 * 1 3 * 2 3 * 3 3 * * * @author pttrung */ public class A { public static long Mod = (long) (1e9) + 7; static int[][] dp; static int[] X = {0, -1, 0, 1}; static int[] Y = {-1, 0, 1, 0}; public static void main(String[] args) throws FileNotFoundException { PrintWriter out = new PrintWriter(System.out); //PrintWriter out = new PrintWriter(new FileOutputStream(new File("output.txt"))); Scanner in = new Scanner(); String s = in.next(); int n = in.nextInt(); String[] data = new String[n]; int max = 0; for(int i = 0; i < data.length; i++){ data[i] = in.next(); max = Math.max(max, data[i].length()); } int l = s.length(); int[]dp = new int[l]; int result = 0; int pos = 0; for(int i = l - 1; i >=0 ; i--){ int v = 0; for(int j = 0; j < max && i + j < l; j++){ String tmp = s.substring(i , i + j + 1); boolean ok = true; for(int k = 0; k < n; k++){ if(tmp.endsWith(data[k])){ ok = false; break; } } if(ok){ v = j + 1; }else{ break; } } dp[i] = v; if(v == max){ if(i + 1 < l && dp[i + 1] >= max){ dp[i] += dp[i + 1] - max + 1; } } // System.out.println(dp[i] + " " + i); if(result < dp[i]){ result = dp[i]; pos = i; } } out.println(result + " " + pos); out.close(); } static long[] extendEuclid(long a, long b) { if (b == 0) { return new long[]{a, 1, 0}; } long[] re = extendEuclid(b, a % b); long x = re[2]; long y = re[1] - (a / b) * re[2]; re[1] = x; re[2] = y; return re; } static long[] modularLinearSolver(long a, long b, long n) { long[] ex = extendEuclid(a, n); if (b % ex[0] != 0) { throw new IllegalArgumentException("No solution"); } long[] result = new long[(int) n]; result[0] = (ex[1] * (b / ex[0])) % n; for (int i = 1; i < ex[0]; i++) { result[i] = result[0] + i * (n / ex[0]); } return result; } static int[] KMP(String v) { int i = 0, j = -1; int[] result = new int[v.length() + 1]; result[0] = -1; while (i < v.length()) { while (j >= 0 && v.charAt(i) != v.charAt(j)) { j = result[j]; } i++; j++; result[i] = j; } return result; } static int find(int index, int[] u) { if (index != u[index]) { return u[index] = find(u[index], u); } return index; } public static long pow(int a, int b, long mod) { if (b == 0) { return 1; } if (b == 1) { return a; } long v = pow(a, b / 2, mod); if (b % 2 == 0) { return (v * v) % mod; } else { return (((v * v) % mod) * a) % mod; } } public static int[][] powSquareMatrix(int[][] A, long p) { int[][] unit = new int[A.length][A.length]; for (int i = 0; i < unit.length; i++) { unit[i][i] = 1; } if (p == 0) { return unit; } int[][] val = powSquareMatrix(A, p / 2); if (p % 2 == 0) { return mulMatrix(val, val); } else { return mulMatrix(A, mulMatrix(val, val)); } } public static int[][] mulMatrix(int[][] A, int[][] B) { int[][] result = new int[A.length][B[0].length]; for (int i = 0; i < result.length; i++) { for (int j = 0; j < result[0].length; j++) { long temp = 0; for (int k = 0; k < A[0].length; k++) { temp += ((long) A[i][k] * B[k][j] % Mod); temp %= Mod; } temp %= Mod; result[i][j] = (int) temp; } } return result; } public static boolean nextPer(int[] data) { int i = data.length - 1; while (i > 0 && data[i] < data[i - 1]) { i--; } if (i == 0) { return false; } int j = data.length - 1; while (data[j] < data[i - 1]) { j--; } int temp = data[i - 1]; data[i - 1] = data[j]; data[j] = temp; Arrays.sort(data, i, data.length); return true; } static class FT { long[] data; FT(int n) { data = new long[n]; } void update(int index, int val) { // System.out.println("UPDATE INDEX " + index); while (index < data.length) { data[index] += val; index += index & (-index); // System.out.println("NEXT " +index); } } long get(int index) { // System.out.println("GET INDEX " + index); long result = 0; while (index > 0) { result += data[index]; index -= index & (-index); // System.out.println("BACK " + index); } return result; } public String toString() { return Arrays.toString(data); } } static long gcd(long a, long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } static long pow(long a, int b) { if (b == 0) { return 1; } if (b == 1) { return a; } long val = pow(a, b / 2); if (b % 2 == 0) { return val * val % Mod; } else { return (val * val % Mod) * a % Mod; } } // static Point intersect(Point a, Point b, Point c) { // double D = cross(a, b); // if (D != 0) { // return new Point(cross(c, b) / D, cross(a, c) / D); // } // return null; // } // // static Point convert(Point a, double angle) { // double x = a.x * cos(angle) - a.y * sin(angle); // double y = a.x * sin(angle) + a.y * cos(angle); // return new Point(x, y); // } static Point minus(Point a, Point b) { return new Point(a.x - b.x, a.y - b.y); } // // static Point add(Point a, Point b) { // return new Point(a.x + b.x, a.y + b.y); // } // /** * Cross product ab*ac * * @param a * @param b * @param c * @return */ static double cross(Point a, Point b, Point c) { Point ab = new Point(b.x - a.x, b.y - a.y); Point ac = new Point(c.x - a.x, c.y - a.y); return cross(ab, ac); } static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; } /** * Dot product ab*ac; * * @param a * @param b * @param c * @return */ static long dot(Point a, Point b, Point c) { Point ab = new Point(b.x - a.x, b.y - a.y); Point ac = new Point(c.x - a.x, c.y - a.y); return dot(ab, ac); } static long dot(Point a, Point b) { long total = a.x * b.x; total += a.y * b.y; return total; } static double dist(Point a, Point b) { long total = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); return Math.sqrt(total); } static long norm(Point a) { long result = a.x * a.x; result += a.y * a.y; return result; } static double dist(Point a, Point b, Point x, boolean isSegment) { double dist = cross(a, b, x) / dist(a, b); // System.out.println("DIST " + dist); if (isSegment) { Point ab = new Point(b.x - a.x, b.y - a.y); long dot1 = dot(a, b, x); long norm = norm(ab); double u = (double) dot1 / norm; if (u < 0) { return dist(a, x); } if (u > 1) { return dist(b, x); } } return Math.abs(dist); } static long squareDist(Point a, Point b) { long x = a.x - b.x; long y = a.y - b.y; return x * x + y * y; } static class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; } @Override public String toString() { return "Point{" + "x=" + x + ", y=" + y + '}'; } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() throws FileNotFoundException { //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true)); br = new BufferedReader(new InputStreamReader(System.in)); //br = new BufferedReader(new FileReader(new File("input.txt"))); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { st = null; try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(); } } public boolean endLine() { try { String next = br.readLine(); while (next != null && next.trim().isEmpty()) { next = br.readLine(); } if (next == null) { return true; } st = new StringTokenizer(next); return st.hasMoreTokens(); } catch (Exception e) { throw new RuntimeException(); } } } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 8
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
3741dee75cf3307e5a65add6174a9bf7
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.*; import java.util.*; public class Main { void solve() { String s = in.next(); int m=in.nextInt(),n=s.length(); String a[] = new String[m]; for(int i=0;i<m;++i){ a[i]=in.next(); } int res=-1,pos=-1; int last=n-1; for(int i=n-1;i>=0;--i){ for(int j=0;j<m;++j){ if(i + a[j].length() > n) continue; boolean f = true; for(int k=0,k1=i;k<a[j].length();++k,++k1){ if(a[j].charAt(k) != s.charAt(k1)){ f = false; break; } } if(f){ last = Math.min(last,i + a[j].length()-2); } } if(res < last-i+1){ res = last-i+1; pos = i; } } if(res == 0 || pos >= n) pos = 0; out.print(res+" "+pos); } FastScanner in; PrintWriter out; void run() { in = new FastScanner(); out = new PrintWriter(System.out); solve(); out.close(); } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static void main(String[] args) { new Main().run(); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 8
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
0c71f62ae067c7a5ca0ac9fbae1f5de0
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.*; /** * 79C * <p> * O(n*max(len(substrs))*len(s)) time * O(len(s)) space * * @author artyom */ public class Beaver implements Runnable { private BufferedReader in; private PrintStream out; private StringTokenizer tok; private void solve() throws IOException { char[] s = nextToken().toCharArray(); int n = nextInt(); Set<char[]> substrs = new HashSet<>(n); for (int i = 0; i < n; i++) { substrs.add(nextToken().toCharArray()); } int[] t = new int[s.length + 1]; Arrays.fill(t, -1); for (char[] subs : substrs) { for (int i = 0, m = s.length - subs.length; i <= m; i++) { int j = 0, k = i; while (j < subs.length && s[k] == subs[j]) { j++; k++; } if (j == subs.length) { if (t[i + j - 1] == -1 || t[i + j - 1] < i) { t[i + j - 1] = i; } } } } int maxLen = 0, maxIndex = 0; t[s.length] = s.length; for (int i = -1; i <= s.length; i++) { for (int j = i + 1; j <= s.length; j++) { if (t[j] > i) { if (j - i - 1 > maxLen) { maxLen = j - i - 1; maxIndex = i + 1; } i = t[j]; } } } out.print(maxLen + " " + maxIndex); } //-------------------------------------------------------------- public static void main(String[] args) { new Beaver().run(); } @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); out = System.out; tok = null; solve(); in.close(); } catch (IOException e) { System.exit(0); } } private String nextToken() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } private int nextInt() throws IOException { return Integer.parseInt(nextToken()); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 8
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
128302ac25a51eb39c88854614071413
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int n = Integer.parseInt(br.readLine()); String[] bad = new String[n]; for (int i=0; i<n; i++) bad[i] = br.readLine(); int maxLen = -1, bestPos = -1; int fn = s.length() - 1; for (int st = s.length() - 1; st >= 0; st--) { for (int i=0; i < n; i++) { if (st + bad[i].length() > s.length()) continue; boolean ok = true; for (int a = st, b = 0; b < bad[i].length(); a++, b++) if (bad[i].charAt(b) != s.charAt(a)) { ok = false; break; } if (ok) fn = Math.min(fn, st + bad[i].length() - 2); } if (fn - st + 1 > maxLen) { maxLen = fn - st + 1; bestPos = st; } } System.out.println(maxLen + " " + bestPos); br.close(); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
a79197ede55957766d22ebc8949c23fc
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.*; import java.util.*; public class Beaver implements Runnable { private void solve() throws IOException { String s = nextToken(); int n = nextInt(); String [] a = new String[n]; for(int i=0;i<n;i++) a[i] = nextToken(); int left = 0; int pos = 0; int len = 0; for(int i=1;i<=s.length();i++){ String cur = s.substring(0,i); for(String x:a){ if(cur.endsWith(x)) left = Math.max(left, i - x.length()+ 1); } if(i-left > len){ len = i - left; pos = left; } } writer.println(len+" "+ pos); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; @Override public void run() { try { reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out); tokenizer = null; solve(); reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public static void main(String[] args) { new Beaver().run(); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
126fb8e5e8bd9028e8810a4d43327f1a
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.IOException; import java.sql.Array; import java.util.Arrays; import java.util.Scanner; /** * Author: dened * Date: 26.03.11 */ public class C { public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); String s = in.next(); int n = in.nextInt(); int[] len = new int[s.length()]; Arrays.fill(len, Integer.MAX_VALUE); for (int i = 0; i < n; ++i) { String b = in.next(); for (int j = 0; j + b.length() <= s.length(); ++j) { if (s.substring(j, j + b.length()).equals(b)) { len[j] = Math.min(len[j], b.length()); } } } int bestFirst = s.length(); int bestLen = 0; int curLen = 0; for (int i = s.length() - 1; i >= 0; --i) { curLen = Math.min(len[i]-1, curLen+1); if (curLen > bestLen) { bestFirst = i; bestLen = curLen; } } System.out.println("" + bestLen + " " + bestFirst); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
ed8306690ef38a9c4369fee08fa27431
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.util.*; import java.io.*; import java.math.BigInteger; import static java.lang.Math.*; public class Sol implements Runnable { StringTokenizer tokenizer = new StringTokenizer(""); BufferedReader in; PrintStream out; public void debug(String s) { System.err.println(s); } public static void main(String[] args) { new Thread(new Sol()).start(); } public void run() { try { Locale.setDefault(Locale.US); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintStream(System.out); char [] c = in.readLine().toCharArray(); int n = c.length, m = nextInt(); int [] wt = new int[n]; Arrays.fill(wt, -1); for (int i = 0; i < m; i++) { char [] b = in.readLine().toCharArray(); int l = b.length; inner: for (int j = 0; j < n - l + 1; j++) { for (int k = 0; k < l; k++) { if (c[j + k] != b[k]) continue inner; } wt[j] = wt[j] == -1 ? j + l - 1 : min(wt[j], j + l - 1); } } int left = 0, bi = 0, blen = 0; while (left < n) { int mr = n, badL = n, right = left; while (right < mr) { if (wt[right] != -1) { if (wt[right] < mr) { badL = right; mr = wt[right]; } } right++; } debug(left + " " + right); if (mr - left > blen) { blen = mr - left; bi = left; } left = badL + 1; } out.println(blen + " " + bi); } catch (Exception e) { e.printStackTrace(); } } long time; void sTime() { time = System.currentTimeMillis(); } long gTime() { return System.currentTimeMillis() - time; } boolean seekForToken() { while (!tokenizer.hasMoreTokens()) { String s = null; try { s = in.readLine(); } catch (Exception e) { e.printStackTrace(); } if (s == null) return false; tokenizer = new StringTokenizer(s); } return true; } String nextToken() { return seekForToken() ? tokenizer.nextToken() : null; } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } BigInteger nextBig() { return new BigInteger(nextToken()); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
c14ef2e7f1b84c1bc0f7e6a2ad333860
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.util.*; import java.io.*; import java.math.BigInteger; import static java.lang.Math.*; public class Sol implements Runnable { StringTokenizer tokenizer = new StringTokenizer(""); BufferedReader in; PrintStream out; public void debug(String s) { System.err.println(s); } public static void main(String[] args) { new Thread(new Sol()).start(); } public void run() { try { Locale.setDefault(Locale.US); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintStream(System.out); char [] c = in.readLine().toCharArray(); int n = c.length, m = nextInt(); int [] wt = new int[n]; Arrays.fill(wt, n); for (int i = 0; i < m; i++) { char [] b = in.readLine().toCharArray(); int l = b.length; inner: for (int j = 0; j < n - l + 1; j++) { for (int k = 0; k < l; k++) { if (c[j + k] != b[k]) continue inner; } wt[j] = min(wt[j], j + l - 1); } } for (int i = n - 2; i >= 0; i--) { wt[i] = min(wt[i], wt[i + 1]); } int bi = 0, blen = 0; for (int i = 0; i < n; i++) { if (wt[i] - i > blen) { blen = wt[i] - i; bi = i; } } out.println(blen + " " + bi); } catch (Exception e) { e.printStackTrace(); } } long time; void sTime() { time = System.currentTimeMillis(); } long gTime() { return System.currentTimeMillis() - time; } boolean seekForToken() { while (!tokenizer.hasMoreTokens()) { String s = null; try { s = in.readLine(); } catch (Exception e) { e.printStackTrace(); } if (s == null) return false; tokenizer = new StringTokenizer(s); } return true; } String nextToken() { return seekForToken() ? tokenizer.nextToken() : null; } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } BigInteger nextBig() { return new BigInteger(nextToken()); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
b1d4c463040487e08bc389b09dec5591
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
/** * Created by ckboss on 14-9-3. */ import java.util.*; public class Beaver { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next().trim(); int n = in.nextInt(); String[] b = new String[n + 1]; for (int i = 0; i < n; i++) b[i] = in.next().trim(); int slen = s.length(); int maxlen=-1,id=-1; int right=0; for (int i = 0; i < slen; i++) { for(int j=0;j<n;j++) { int k=b[j].length(); if(i-k+1>=0&&s.substring(i-k+1,i+1).equals(b[j])) { right=Math.max(right,i-k+2); } } if(i-right+1>maxlen) { maxlen=i-right+1; id=right; } } System.out.println(maxlen+" "+id); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
1c469a5c96624bf2a32a9820b8182b0b
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; import java.math.BigInteger; public class Main { public static void main(String[] args) throws IOException { try { if (new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt")); } catch (SecurityException e) { } new Thread(null, new Runnable() { public void run() { try { new Main().run(); } catch (Throwable e) { e.printStackTrace(); exit(999); } } }, "1", 1 << 23).start(); } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); Random rnd = new Random(); long BASE = BigInteger.probablePrime(32, rnd).longValue(); long[] code = new long[150]; private void run() throws IOException { long[] pow = new long[11]; pow[0] = 1; for (int i = 1; i < 11; i++) pow[i] = pow[i - 1] * BASE; for (int i = 48; i < 123; i++) code[i] = rnd.nextInt(10000); // System.out.println((int)'0'); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); String text = nextToken(); int n = nextInt(); long[] hs = new long[n]; int[] len = new int[n]; for (int i = 0; i < n; i++) { String s = nextToken(); len[i] = s.length(); hs[i] = hash(s); // System.out.println(hs[i]); } long[] hash = new long[text.length()]; int ansPos = 0; int ansLen = 0; int pos = 0; long h = 0; for (int i = 0; i < text.length(); i++) { hash[i] = h * BASE + code[text.charAt(i)]; h = hash[i]; boolean good = true; int mx = pos; // System.out.println(pos + " " + i); for (int j = 0; j < n; j++) { int ln = len[j]; if (ln <= i - pos + 1) { long p = i - ln < 0 ? 0 : hash[i - ln]; if (h - p * pow[ln] == hs[j]) { good = false; mx = max(mx, i - ln + 2); } } } // System.out.println(good); int nl = i - pos; if (good) nl ++; if (nl > ansLen) { ansLen = nl; ansPos = pos; } pos = mx; } out.println(ansLen + " " + ansPos); in.close(); out.close(); } long hash(String s) { long hash = 0; for (int i = 0; i < s.length(); i++) { hash = hash * BASE + code[s.charAt(i)]; } return hash; } void chk(boolean b) { if (b) return; System.out.println(new Error().getStackTrace()[1]); exit(999); } void deb(String fmt, Object... args) { System.out.printf(Locale.US, fmt + "%n", args); } String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
8b922028933f3e1a208e0b68bbde7262
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.*; import java.util.*; public class beaver { public static void main (String [] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String original = in.readLine(); int orgLength = original.length(), numOthers = Integer.parseInt(in.readLine()); String [] others = new String[numOthers]; for (int count = 0; count < numOthers; count ++) others[count] = in.readLine(); Arrays.sort(others, new StringComp()); int maxLength = 0, from = 0, curLength = 0, curFrom = 0, minFrom = 0; for (int count = 0; count < orgLength; count ++, curLength ++) { for (int count2 = 0; count2 < numOthers; count2 ++) { String other = others[count2]; if (count < other.length() - 1) continue; if (other.equals(original.substring(count - other.length() + 1, count + 1))) { if (curLength > maxLength) { maxLength = curLength; from = curFrom; } curLength = other.length() - 2; curFrom = count - other.length() + 2; if (curFrom < minFrom) { curLength += (curFrom - minFrom); curFrom = minFrom; } minFrom = curFrom; break; } } } if (curLength > maxLength) { maxLength = curLength; from = curFrom; } System.out.printf("%d %d\n", maxLength, from); System.exit(0); } } class StringComp implements Comparator <String> { public int compare (String s1, String s2) { if (s1.length() < s2.length()) return -1; if (s1.length() > s2.length()) return 1; return 0; } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
1089f1c48c36c97db644d8bce3ffd6e8
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.*; import java.util.*; public class beaver { public static void main (String [] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String original = in.readLine(); int orgLength = original.length(), numOthers = Integer.parseInt(in.readLine()); String [] others = new String[numOthers]; for (int count = 0; count < numOthers; count ++) others[count] = in.readLine(); Arrays.sort(others, new StringComp()); int maxLength = 0, from = 0, curLength = 0, curFrom = 0, minFrom = 0; for (int count = 0; count < orgLength; count ++, curLength ++) { for (int count2 = 0; count2 < numOthers; count2 ++) { String other = others[count2]; if (count < other.length() - 1) continue; if (other.equals(original.substring(count - other.length() + 1, count + 1))) { if (curLength > maxLength) { maxLength = curLength; from = curFrom; } curLength = other.length() - 2; curFrom = count - other.length() + 2; if (curFrom < minFrom) { curLength += (curFrom - minFrom); curFrom = minFrom; } minFrom = curFrom; break; } } } if (curLength > maxLength) { maxLength = curLength; from = curFrom; } System.out.printf("%d %d\n", maxLength, from); //System.exit(0); } } class StringComp implements Comparator <String> { public int compare (String s1, String s2) { if (s1.length() < s2.length()) return -1; if (s1.length() > s2.length()) return 1; return 0; } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
8fafde4b2dcfdad1ab66aa22243ebf1a
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char[]taro = null; String line = null; String[]badStrs = null; int n = -1; while(null != (line = br.readLine())){ if(n==-1){ taro = new char[line.length()]; for(int i = 0; i < line.length(); i++){ taro[i] = line.charAt(i); } n = Integer.parseInt(br.readLine()); badStrs = new String[n]; continue; } badStrs[--n] = line; if(n<=0)break; } int maxPos = 0; int maxLen = -1; int currLen = 0; int currPos = 0; int shiftBack = -1; boolean isReset = true; for(int i = 0; i < taro.length; i++){ if(isReset){ isReset = false; if(maxLen<currLen){ maxLen = currLen; maxPos = currPos; } i-=(shiftBack==-1?0:shiftBack-1); currPos = i; currLen = 0; } int numDiff = 0; shiftBack = taro.length+1; for(int j = 0; j < badStrs.length; j++){ boolean wasDifferent = false; for(int k = badStrs[j].length()-1; k >= 0; k--){ if(i-badStrs[j].length()+1+k<currPos||taro[i-badStrs[j].length()+1+k]!=badStrs[j].charAt(k)){ wasDifferent = true; break; } } if(wasDifferent)numDiff++; else{ if(shiftBack>badStrs[j].length())shiftBack = badStrs[j].length(); } } if(numDiff==badStrs.length)currLen++; else isReset = true; } if(maxLen<currLen){ maxLen = currLen; maxPos = currPos; } System.out.println(maxLen + " " + maxPos); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
4f9a78ea94ec0346bd9c8302931fec4b
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.util.*; public class cf79c { public static void main(String[] args) { Scanner in = new Scanner(System.in); String v = in.next().trim(); int n = in.nextInt(); String[] x = new String[n]; for(int i=0; i<n; i++) x[i] = in.next().trim(); //find the longest string ending at i //progressively update the start int start = 0; int best = 0; int bestlen = 0; for(int i=1; i<=v.length(); i++) { String ss = v.substring(0,i); for(String s : x) { if(ss.endsWith(s)) start = Math.max(start,i-s.length()+1); } if(i-start > bestlen) { bestlen = i-start; best = start; } } System.out.println(bestlen + " " + best); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
de884fb16e9585ead3e9c07e484d07e4
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.util.InputMismatchException; import java.io.*; import java.math.*; import java.util.Vector; /** * Generated by Contest helper plug-in * Actual solution is at the bottom */ public class Main { public static void main(String[] args) { InputReader in = new StreamInputReader(System.in); PrintWriter out = new PrintWriter(System.out); run(in, out); } public static void run(InputReader in, PrintWriter out) { Solver solver = new Boring(); solver.solve(1, in, out); Exit.exit(in, out); } } abstract class InputReader { private boolean finished = false; public abstract int read(); public int nextInt() { return Integer.parseInt(nextToken()); } public String nextToken() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String readString() { // need int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public void setFinished(boolean finished) { this.finished = finished; } public abstract void close(); } class StreamInputReader extends InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar, numChars; public StreamInputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } @Override public void close() { try { stream.close(); } catch (IOException ignored) { } } } class Exit { private Exit() { } public static void exit(InputReader in, PrintWriter out) { in.setFinished(true); in.close(); out.close(); } } interface Solver { public void solve(int testNumber, InputReader in, PrintWriter out); } class Boring implements Solver { public void solve(int testNumber, InputReader in, PrintWriter out) { char s[] = in.nextToken().toCharArray(); int n = in.nextInt(); char t[][] = new char[n][]; Vector<Integer> g[] = new Vector[n]; for (int i =0 ; i < g.length; ++i) { g[i] = new Vector<Integer>(0); } for (int i = 0; i < n; ++i) { t[i] = in.nextToken().toCharArray(); } for (int i = 0; i < n; ++i) { for (int j = 0; j +t[i].length - 1 < s.length; ++j) { boolean ok = true; for (int u =0 ; u < t[i].length; ++u) { ok &= (t[i][u] == s[u + j]) ; } if (ok) g[i].add(j); } } int array[][] = new int[g.length][]; for (int i =0 ; i < array.length; ++i) { array[i] = new int[g[i].size()]; for (int j = 0; j < g[i].size(); ++j) { array[i][j] = g[i].get(j); } } int res = 0, pos = 0; int l = 0, r = s.length; while (l <= r) { int m = (l + r) >> 1; boolean ok = false; int index = -1; for (int i = 0; !ok && i + m - 1 < s.length; ++i) { int cnt = 0; for (int j = 0; j < n; ++j) { int ll = 0, rr = array[j].length - 1, rres = Integer.MAX_VALUE / 2; while (ll <= rr ) { int mm = (ll + rr) >> 1; if (array[j][mm] >= i) { rres = Math.min(rres,array[j][mm] ); rr = mm - 1; } else { ll = mm + 1; } } if (rres == Integer.MAX_VALUE / 2) { ++ cnt; continue; } if (!(rres + t[j].length - 1 <= i + m - 1)) { ++ cnt; } else break; } if (cnt == n) { ok = true; index = i; } } if (ok) { if (res < m) { res = m; pos = index; } l = m + 1; } else r = m - 1; } out.print(res + " " + pos); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
b3998d7773140c42875c6e2b2bd5bc9c
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.util.*; import java.math.*; import static java.lang.Character.isDigit; import static java.lang.Character.isLowerCase; import static java.lang.Character.isUpperCase; import static java.lang.Math.*; import static java.math.BigInteger.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.lang.Character.isDigit; public class Main{ static void debug(Object...os){ System.err.println(deepToString(os)); } void run(){ String s=next(); int n=nextInt(); int len = s.length(); String[] subs=new String[len]; for(int i=0;i<len;i++) { subs[i] = s.substring(i,min(len,i+10)); } int[] dp=new int[len]; int INF=1<<28; fill(dp,INF); for(int i=0;i<n;i++) { String t=next(); for(int j=0;j<len;j++) { if(subs[j].startsWith(t)) { dp[j] = min(dp[j],t.length()-1); } } } dp[len-1] = min(dp[len-1],1); int mx=-1; int mxi=-1; for(int i=len-1;i>=0;i--) { if(dp[i]>mx) { mx=dp[i]; mxi=i; } if(i>0)dp[i-1] = min(dp[i-1],dp[i]+1); } System.out.println(mx+" "+mxi); } int nextInt(){ try{ int c=System.in.read(); if(c==-1) return c; while(c!='-'&&(c<'0'||'9'<c)){ c=System.in.read(); if(c==-1) return c; } if(c=='-') return -nextInt(); int res=0; do{ res*=10; res+=c-'0'; c=System.in.read(); }while('0'<=c&&c<='9'); return res; }catch(Exception e){ return -1; } } long nextLong(){ try{ int c=System.in.read(); if(c==-1) return -1; while(c!='-'&&(c<'0'||'9'<c)){ c=System.in.read(); if(c==-1) return -1; } if(c=='-') return -nextLong(); long res=0; do{ res*=10; res+=c-'0'; c=System.in.read(); }while('0'<=c&&c<='9'); return res; }catch(Exception e){ return -1; } } double nextDouble(){ return Double.parseDouble(next()); } String next(){ try{ StringBuilder res=new StringBuilder(""); int c=System.in.read(); while(Character.isWhitespace(c)) c=System.in.read(); do{ res.append((char)c); }while(!Character.isWhitespace(c=System.in.read())); return res.toString(); }catch(Exception e){ return null; } } String nextLine(){ try{ StringBuilder res=new StringBuilder(""); int c=System.in.read(); while(c=='\r'||c=='\n') c=System.in.read(); do{ res.append((char)c); c=System.in.read(); }while(c!='\r'&&c!='\n'); return res.toString(); }catch(Exception e){ return null; } } public static void main(String[] args){ new Main().run(); } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
3d0c297f3241f197711a99b8fca7b389
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Beaver { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); char[] arr=r.readLine().toCharArray(); int[] dp=new int[arr.length+1]; int n=Integer.parseInt(r.readLine()); String[] w=new String[n]; for(int i=0;i<n;i++) w[i]=r.readLine(); int maxL=0; int maxI=0; int currentIndex=0; int endIndex=0; for(int i=1;i<dp.length;i++){ endIndex++; int minLength=20; for(String str:w){ if(ends(arr,currentIndex,endIndex,str)){ minLength=Math.min(minLength, str.length()); } } if(minLength==20){ dp[i]=dp[i-1]+1; } else{ currentIndex=endIndex-minLength+1; dp[i]=minLength-1; } if(maxL<dp[i]){ maxL=dp[i]; maxI=i-1; } } System.out.println(maxL+" "+(maxI-maxL+1)); } private static boolean ends(char[] arr, int currentIndex, int endIndex, String str) { int min=endIndex-str.length(); if(min>=0&&currentIndex<=min){ for(int i=0;i<str.length();i++){ if(arr[endIndex-str.length()+i]!=str.charAt(i))return false; } return true; } return false; } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
55101fb9abbb64aa234dbc2d7f85c424
train_001.jsonl
1304175600
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Beaver { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); char[] arr=r.readLine().toCharArray(); int[] dp=new int[arr.length+1]; int n=Integer.parseInt(r.readLine()); String[] w=new String[n]; for(int i=0;i<n;i++) w[i]=r.readLine(); int maxL=0; int maxI=0; int currentIndex=0; int endIndex=0; for(int i=1;i<dp.length;i++){ endIndex++; int minLength=20; for(String str:w){ if(ends(arr,currentIndex,endIndex,str)){ minLength=Math.min(minLength, str.length()); } } if(minLength==20){ dp[i]=dp[i-1]+1; } else{ currentIndex=endIndex-minLength+1; dp[i]=minLength-1; } if(maxL<dp[i]){ maxL=dp[i]; maxI=i-1; } } System.out.println(maxL+" "+(maxI-maxL+1)); } private static boolean ends(char[] arr, int currentIndex, int endIndex, String str) { int min=endIndex-str.length(); if(min>=0&&currentIndex<=min){ for(int i=0;i<str.length();i++){ if(arr[endIndex-str.length()+i]!=str.charAt(i))return false; } return true; } return false; } }
Java
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
2 seconds
["12 4", "0 0", "5 5"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
Java 6
standard input
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
b5f5fc50e36b2afa3b5f16dacdf5710b
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
1,800
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
standard output
PASSED
1118d225218cc2714fa5cef97ccbe275
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.util.Scanner; public class Main { static boolean espal(String a){ int medio=(a.length())/2; for (int i= 0; i < medio; i++) { if (a.charAt(i)!=a.charAt(a.length()-1-i)) { return false; } } return true; } public static void main(String[] args) { Scanner n=new Scanner(System.in); String a=n.next(); int b=n.nextInt(); boolean r=true; if (b>a.length()||a.length()%b!=0) { r=false; } int c=b; int i=0; while(c>1){ String aux=a.substring(i, i+a.length()/b); if (!espal(aux)) { r=false; } c--; i+=a.length()/b; } String aux=a.substring(i, i+a.length()/b); if (!espal(aux)) { r=false; } if (r) { System.out.println("YES"); }else System.out.println("NO"); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
2fbcc5dfb02f061b8e2488c83cdb0143
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.util.Scanner; public class MikeAndFox { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.next().trim(); int k=sc.nextInt(); System.out.println(checkPalindrome(s,k)==true?"YES":"NO"); } private static boolean checkPalindrome(String s, int k){ if(s.length()%k!=0){ return false; } for(int i=0;i<k;i++){ String temp=new String(s.substring(i*s.length()/k, (i+1)*s.length()/k)); StringBuilder sb=new StringBuilder(temp); sb=sb.reverse(); //System.out.println(temp+" "+sb.toString()); if(!temp.equals(sb.toString())) { return false; } } return true; } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
4741b7a9cf1b7bba5027531b3c43f3ff
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.nextLine(); int k = in.nextInt(); int lenghtEachPart = s.length() / k; String result = "NO"; if (s.length() % k == 0) { int j = 0; for (int i = 0; i < k; i++) { String part = s.substring(j, j + lenghtEachPart); j += lenghtEachPart; if (part.equals(new StringBuilder(part).reverse().toString())) { result = "YES"; } else { result = "NO"; break; } } } in.close(); System.out.println(result); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
9e1df3f7d97a7b8ba289c131ac21cc21
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.util.Scanner; public class Codeforces_Round_305_A_Mike_and_Fax { static boolean isPalendrom(String x) { for (int i = 0, j = x.length() - 1; i < x.length(); j--, i++) { if (x.charAt(i) != x.charAt(j)) return false; } return true; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); int k = in.nextInt(); float len = s.length() / k; if (s.length() % k != 0) { System.out.println("NO"); return; } else { String[] x = new String[k]; for (int i = 0, j = 0; j < k; i += len, j++) { x[j] = s.substring(i, (int) (i + len)); } for (int j = 0; j < x.length; j++) { if (!isPalendrom(x[j])) { System.out.println("NO"); return; } } } System.out.println("YES"); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
72e0b81e53f9c8c098c3eac780637ff7
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.util.Scanner; /** * Created by Trajkovski on 26-May-15. */ public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s = scanner.next(); int k = scanner.nextInt(); if (s.length() % k != 0) { System.out.println("NO"); return; } boolean valid = true; for (int i = 0; i < s.length(); i += (s.length() / k)) { String p1 = s.substring(i, i + (s.length() / k)); String p2 = new StringBuilder(p1).reverse().toString(); if (!p1.equals(p2)) { valid = false; break; } } if (valid) System.out.println("YES"); else System.out.println("NO"); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
bddb555f25c9bac05a075f60cd485ccf
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.ArrayList; public class MikeAndFax { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); OutputStream out = new BufferedOutputStream(System.out); String s = br.readLine(); int k = Integer.parseInt(br.readLine()); ArrayList<String> list = new ArrayList<String>(); if (s.length() % k == 0) { int kl = s.length() / k; boolean flag = true; for (int i = 0; i <= s.length() - 1; i += kl) { String temp = s.substring(i, i + (kl)); list.add(temp); } for (String ss : list) { StringBuilder sb = new StringBuilder(ss); if (!ss.equals(sb.reverse().toString())) flag = false; } if (flag) out.write(("YES\n").getBytes()); else out.write(("NO\n").getBytes()); } else out.write(("NO\n").getBytes()); out.flush(); br.close(); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
3ab98e72d256a846845495f300f892b1
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.util.Scanner; public class A { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); int k = in.nextInt(); int len = s.length(); if(s!="" && len!=0) { int plen = len/k; if(len < k || len%plen != 0 || len%k !=0) { System.out.println("NO"); } else { int count=0; for( int i = 0 ;i < len ; i+=plen) { String original = s.substring(i, i+plen); String reverse=""; for ( int j = original.length() - 1; j >= 0; j-- ) reverse = reverse + original.charAt(j); if(original.equals(reverse)) { count++; } else{ break; } } if(count == k) System.out.println("YES"); else System.out.println("NO"); } } else System.out.println("NO"); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
6f56a252afae15e4e0e48a76f75f3f1c
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.util.Scanner; public class Tester { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner =new Scanner(System.in); String string=scanner.nextLine(); int numOfPal=scanner.nextInt(); int stringLength=string.length(); int stringpart=stringLength/numOfPal; int count=0; if(stringpart*numOfPal==stringLength){ for(int i=0;i<stringLength;i+=stringpart){ String temp=string.substring(i, i+stringpart); String reverse=""; int length=temp.length(); for(int j= (length-1);j>=0;j--){ reverse=reverse+temp.charAt(j); } if(!reverse.equals(temp)){ break; } count++; } if(count==numOfPal){ System.out.println("YES"); }else{ System.out.println("NO"); } }else{ System.out.println("NO"); } } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
106ab910c6b86a094c1d2fe2483eae2b
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * * @author Tamil */ public class MikeAndFax { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String mg = in.readLine(); int k = Integer.parseInt(in.readLine()); if (k > mg.length() || (mg.length() %k != 0 && k != mg.length()-1)) { System.out.println("NO"); return; }else if(k == mg.length()){ System.out.println("YES"); return; } int start = 0; int len = mg.length() / k; int end = len; //System.out.println(len); for (int i = 0; i < k; i++) { String pal = mg.substring(start, end); if (new StringBuilder(pal).reverse().toString().equals(pal)) { start = end; end += len; } else { System.out.println("NO"); return; } //System.out.println(pal); } System.out.println("YES"); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
c8c85e7298749427ec9911d6006e4782
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.io.*; import java.util.*; public class temp{ public static void main(String[] arg) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s = in.readLine(); int k = Integer.parseInt(in.readLine()); String[] ss = new String[k]; boolean res = true; if (s.length()%k != 0) res = false; else{ outer: for (int i = 0; i < k; i++) { ss[i] = s.substring(i*s.length()/k, (i+1)*s.length()/k); for (int j = 0 ; j <= ss[i].length()/2; j++) { if (ss[i].charAt(j) != ss[i].charAt(ss[i].length()-j-1)) { res = false; break outer; } } } } if (res) System.out.print("YES"); else System.out.print("NO"); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
61973b086208db6ae210498aa572fe39
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
//package round305div2; import java.util.*; import java.io.*; public class A { static String INPUT = "res/input.txt"; void solve() { String s = in.next(); int k = in.nextInt(); int n = s.length(); if(n % k != 0) { out.println("NO"); return; } int step = n / k; for(int i = 0; i < n; i += step) { int start = i; int end = i + step - 1; if(end >= n) break; while(start <= end) { if(s.charAt(start) != s.charAt(end)) { out.println("NO"); return; } start++; end--; } } out.println("YES"); } void run() throws Exception { is = oj ? System.in : new FileInputStream(new File(INPUT)); if(in == null) in = new Scanner(is); if(out == null) out = new PrintWriter(System.out); long start = System.currentTimeMillis(); solve(); out.flush(); tr((System.currentTimeMillis() - start) + " ms"); } public static void main(String[] args) throws Exception { new A().run(); } static Scanner in = null; static PrintWriter out = null; static InputStream is = null; private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if(!oj) System.out.println(Arrays.deepToString(o)); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
874d33df1988657d9d50efd21cb3fe1f
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.awt.Point; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.PriorityQueue; import java.util.StringTokenizer; /** * * @author Mojtaba */ public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); //StringTokenizer tokenizer = new StringTokenizer(reader.readLine()); String str = reader.readLine(); int n = Integer.parseInt(reader.readLine()); if (str.length() % n != 0) { System.out.println("NO"); System.exit(0); } int gam = str.length() / n; for (int i = 0; i < str.length(); i += gam) { String sub = str.substring(i, i + gam); StringBuilder temp = new StringBuilder(sub); if (!sub.equals(temp.reverse().toString())) { System.out.println("NO"); System.exit(0); } } sb.append("YES"); System.out.println(sb.toString().trim()); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
592b6b7375a4bca02f22aa67bff93582
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.lang.*; import java.util.*; public class Solution{ public static void main(String args[]){ Scanner in = new Scanner(System.in); String s = in.next(); int n = in.nextInt(); int len = s.length()/n; if(s.length()==n) {System.out.println("YES");return;} if(s.length()%n!=0){System.out.println("NO");return;} int i=0; while(i+len<=s.length()){ if(!isPal(s.substring(i,i+len))) {System.out.println("NO");return;} i+=len; } System.out.println("YES"); return; } public static boolean isPal(String s){ int i=0;int j=s.length()-1; while(i<j){ if(s.charAt(i)!=s.charAt(j)){ return false; } i++; j--; } return true; } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
f591eb47db1a909899787333f8b59066
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class A218 { public static void main(String[] args) throws IOException { new A218().solve(); //System.out.println(gcd(120l, 75l)); // System.out.println((int)logOfBase(1, 1)); } public static Long[] getLongArray(String line) { String s[] = line.split(" "); Long a[] = new Long[s.length]; for (int i = 0; i < s.length; ++i) { a[i] = Long.parseLong(s[i]); } return a; } public static int[] getIntArray(String line) { String s[] = line.split(" "); int a[] = new int[s.length]; for (int i = 0; i < s.length; ++i) { a[i] = Integer.parseInt(s[i]); } return a; } public static Double[] getDoubleArray(String line) { String s[] = line.split(" "); Double a[] = new Double[s.length]; for (int i = 0; i < s.length; ++i) { a[i] = Double.parseDouble(s[i]); } return a; } public void solve() throws IOException { Scanner sc = new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); long mod = 1000000000 + 7; String s = br.readLine(); int n = Integer.parseInt(br.readLine()); int k = s.length() / n; if (s.length() % n != 0) { System.out.println("NO"); System.exit(0); } for (int i = 0; i < n; i++) { String a = s.substring(0 + i * k, 0 + i * k + k); //System.out.println(a); if (!new StringBuilder(a).reverse().toString().equals(a)) { System.out.println("NO"); System.exit(0); } } System.out.println("YES"); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
a687f0afda4d142ef3987f436f5cd0e2
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { boolean pali( String s, int b, int e ) { for( int i = b; i < e; i++ ) if( s.charAt( i ) != s.charAt( e - i + b - 1 ) ) return false; return true; } void solve() throws IOException { String s = nextToken(); int k = nextInt(); String ans = "YES"; if( s.length() % k != 0 ) ans = "NO"; else { int l = s.length() / k; for( int i = 0; i < k; i++ ) if( !pali( s, i * l, ( i + 1 ) * l ) ) ans = "NO"; } out.println( ans ); } public static void main( String[] args ) { new Main().run(); } public void run() { try { in = new BufferedReader( new InputStreamReader( System.in ) ); out = new PrintWriter( System.out ); st = null; solve(); } catch( Exception e ) { e.printStackTrace(); System.exit( 1 ); } finally { out.close(); } } String nextToken() throws IOException { while( st == null || !st.hasMoreTokens() ) st = new StringTokenizer( in.readLine() ); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt( nextToken() ); } BufferedReader in; PrintWriter out; StringTokenizer st; }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
8f54e7677a073bc0fd33bc6c4f4dce1a
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.io.File; import java.util.ArrayList; import java.util.Scanner; public class A { public static void main(String[] args) throws Exception { // Scanner sc = new Scanner(new File("in.txt")); Scanner sc = new Scanner(System.in); String s = sc.next(); final int k = sc.nextInt(); if (s.length() % k != 0) { System.out.println("NO"); return; } int c = 0; for(int i = 0; i < s.length(); i += s.length() / k){ // System.out.println(s.substring(i, i + s.length() / k)); if(isPal(s.substring(i, i + s.length() / k))) c++; } System.out.println(c == k ? "YES" : "NO"); } static boolean isPal(String s) { return new StringBuilder(s).reverse().toString().compareTo(s) == 0; } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
fa939dc73ae21f3191eb3ca3adb180b7
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
//package code_alone; import com.sun.org.apache.bcel.internal.Constants; import java.util.ArrayList; import java.util.Scanner; public class Code_Alone { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int y = sc.nextInt(); if(s.length()%y!=0){System.out.print("NO");return;} int step=s.length()/y; for(int i=0;i<s.length();i+=step) if(!s.substring(i , i+step).equals(new StringBuilder(s.substring(i , i+step)).reverse().toString())) {System.out.print("NO "); return;} {System.out.print("YES");} } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
982bd804840d026305c21b5836015927
train_001.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.util.Scanner; public class A{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int y = sc.nextInt(); if(s.length()%y!=0){System.out.print("NO");return;} int step=s.length()/y; for(int i=0;i<s.length();i+=step) if(!s.substring(i , i+step).equals(new StringBuilder(s.substring(i , i+step)).reverse().toString())) {System.out.print("NO"); return;} System.out.print("YES"); } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 7
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output