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
bf796dc82595dfd171f9e206568d083b
train_003.jsonl
1299340800
Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with vertices at the points (x0, y0, z0), (x1, y1, z1), ..., (xn, yn, zn). At the beginning of the game the snitch is positioned at the point (x0, y0, z0), and then moves along the polyline at the constant speed vs. The twins have not yet found out how the snitch behaves then. Nevertheless, they hope that the retrieved information will help Harry Potter and his team in the upcoming match against Slytherin. Harry Potter learned that at the beginning the game he will be at the point (Px, Py, Pz) and his super fast Nimbus 2011 broom allows him to move at the constant speed vp in any direction or remain idle. vp is not less than the speed of the snitch vs. Harry Potter, of course, wants to catch the snitch as soon as possible. Or, if catching the snitch while it is moving along the polyline is impossible, he wants to hurry the Weasley brothers with their experiments. Harry Potter catches the snitch at the time when they are at the same point. Help Harry.
256 megabytes
import java.text.NumberFormat; import java.util.Scanner; public class C { Scanner sc; public void init(){ sc = new Scanner(System.in); formatter.setMaximumFractionDigits(10); formatter.setMinimumFractionDigits(10); formatter.setGroupingUsed(false); } NumberFormat formatter = NumberFormat.getNumberInstance(); public void getAns(point potter,point start,point end){ double err = 100; point np = null; for(;Math.abs(err) > (1e-11);){ np = start.mid(end); err = np.distance(start); double dist = potter.distance(np); if(np.start*vp < dist){ start = np; }else{ end = np; } } System.out.println("YES"); System.out.println(formatter.format(np.start)); System.out.println(formatter.format(np.x)+" "+formatter.format(np.y)+" "+formatter.format(np.z)); } class point{ double x; double y; double z; double start; point(int x, int y,int z,point pre){ this.x = x; this.y = y; this.z = z; start = pre.start + (distance(pre)/vs); } point(int x, int y,int z,double start){ this.x = x; this.y = y; this.z = z; this.start =start; } double distance(point from){ double dist = (this.x - from.x)*(this.x - from.x); dist += (this.y - from.y)*(this.y - from.y); dist += (this.z - from.z)*(this.z - from.z); return Math.sqrt(dist); } point mid(point tar){ point ret = new point(0, 0, 0, 0); ret.x = (this.x+tar.x)/2; ret.y = (this.y+tar.y)/2; ret.z = (this.z+tar.z)/2; ret.start = (this.start+tar.start)/2; return ret; } } int vs; int vp; public void run(){ int n = sc.nextInt(); int[] inX = new int [n+1]; int[] inY = new int [n+1]; int[] inZ = new int [n+1]; for(int i = 0 ; i < n+1;i++){ inX[i] = sc.nextInt() ; inY[i] = sc.nextInt() ; inZ[i] = sc.nextInt() ; } vp = sc.nextInt(); vs = sc.nextInt(); int pX = sc.nextInt(); int pY = sc.nextInt(); int pZ = sc.nextInt(); point[] p = new point[n+1]; p[0] = new point(inX[0],inY[0],inZ[0],0); point potter = new point(pX,pY,pZ,0); if(Math.abs(inX[0] - pX) < 1e-7){ if(Math.abs(inY[0] - pY) < 1e-7){ if(Math.abs(inZ[0] - pZ) < 1e-7){ System.out.println("YES"); System.out.println(formatter.format(0)); System.out.println(formatter.format(inX[0])+" "+formatter.format(inY[0])+" "+formatter.format(inZ[0])); return; } } } for(int i = 1; i < n+1;i++){ p[i] = new point(inX[i],inY[i],inZ[i],p[i-1]); double dist = potter.distance(p[i]); if(p[i].start*vp > dist){ getAns(potter,p[i-1],p[i]); return; } } double dist = potter.distance(p[n]); if(1e-6> dist - p[n].start*vp){ System.out.println("YES"); System.out.println(formatter.format(p[n].start)); System.out.println(formatter.format(inX[n])+" "+formatter.format(inY[n])+" "+formatter.format(inZ[n])); return; } System.out.println("NO"); } public static void main(String[] args){ C m = new C(); m.init(); m.run(); } }
Java
["4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 25", "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 50", "1\n1 2 3\n4 5 6\n20 10\n1 2 3"]
2 seconds
["YES\n25.5000000000\n10.0000000000 4.5000000000 0.0000000000", "NO", "YES\n0.0000000000\n1.0000000000 2.0000000000 3.0000000000"]
null
Java 6
standard input
[ "binary search", "geometry" ]
6e2a8aa58ed8cd308cb482e4c24cbbbb
The first line contains a single integer n (1 ≀ n ≀ 10000). The following n + 1 lines contain the coordinates xi, yi, zi, separated by single spaces. The coordinates of any two consecutive points do not coincide. The next line contains the velocities vp and vs, the last line contains Px, Py, Pz, separated by single spaces. All the numbers in the input are integers, their absolute value does not exceed 104. The speeds are strictly positive. It is guaranteed that vs ≀ vp.
2,100
If Harry Potter can catch the snitch while it is moving along the polyline (including the end (xn, yn, zn)), print "YES" in the first line (without the quotes). Print in the second line t, which is the earliest moment of time, when Harry will be able to catch the snitch. On the third line print three numbers X, Y, Z, the coordinates of the point at which this happens. The absolute or relative error in the answer should not exceed 10 - 6. If Harry is not able to catch the snitch during its moving along the described polyline, print "NO".
standard output
PASSED
8a255601d55e9fc752b426779ed286e1
train_003.jsonl
1299340800
Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with vertices at the points (x0, y0, z0), (x1, y1, z1), ..., (xn, yn, zn). At the beginning of the game the snitch is positioned at the point (x0, y0, z0), and then moves along the polyline at the constant speed vs. The twins have not yet found out how the snitch behaves then. Nevertheless, they hope that the retrieved information will help Harry Potter and his team in the upcoming match against Slytherin. Harry Potter learned that at the beginning the game he will be at the point (Px, Py, Pz) and his super fast Nimbus 2011 broom allows him to move at the constant speed vp in any direction or remain idle. vp is not less than the speed of the snitch vs. Harry Potter, of course, wants to catch the snitch as soon as possible. Or, if catching the snitch while it is moving along the polyline is impossible, he wants to hurry the Weasley brothers with their experiments. Harry Potter catches the snitch at the time when they are at the same point. Help Harry.
256 megabytes
import java.io.*; import java.util.*; public class C { MyScanner in; PrintWriter out; final static String filename = ""; class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner(String file) { try { br = new BufferedReader(new FileReader(file)); st = new StringTokenizer(""); } catch (FileNotFoundException e) { e.printStackTrace(); System.exit(1); } } public MyScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); st = new StringTokenizer(""); } String nextToken() { try { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); System.exit(1); } return st.nextToken(); } int nextInt() { return Integer.parseInt(this.nextToken()); } double nextDouble() { return Double.parseDouble(this.nextToken()); } long nextLong() { return Long.parseLong(this.nextToken()); } void close() throws IOException { br.close(); } } int[] a; int n; class Point { double x; double y; double z; public Point(double a, double b, double c) { x = a; y = b; z = c; } double length() { return Math.sqrt(x * x + y * y + z * z); } } double get(Point a, Point b, double v) { Point c = new Point(b.x - a.x, b.y - a.y, b.z - a.z); return c.length() / v; } Point func(Point a, Point b, double k) { return new Point(a.x + (b.x - a.x) * k, a.y + (b.y - a.y) * k, a.z + (b.z - a.z) * k); } void solve() throws IOException { n = in.nextInt(); Point[] a = new Point[n + 1]; for (int i = 0; i <= n; i++) a[i] = new Point(in.nextInt(), in.nextInt(), in.nextInt()); double vp = in.nextDouble(); double vs = in.nextDouble(); Point p = new Point(in.nextInt(), in.nextInt(), in.nextInt()); double t = 0; double eps = 1e-10; if (a[0].x == p.x && a[0].y == p.y && a[0].z == p.z) { out.println("YES"); out.println(0); out.println(p.x + " " + p.y + " " + p.z); return; } for (int i = 1; i <= n; i++) { double dt = get(a[i - 1], a[i], vs); double r = get(p, a[i], vp); if (t + dt > r - eps) { double left = 0; double right = dt; int cnt = 0; while (right - left > eps && cnt < 1000) { cnt++; double h = (left + right) / 2; Point f = func(a[i - 1], a[i], h / dt); double x = get(a[i - 1], f, vs) + t; double y = get(p, f, vp); if (x > y) right = h; else left = h; } double time = (left + right) / 2; out.println("YES"); out.println(t + time); Point f = func(a[i - 1], a[i], time / dt); out.println(f.x + " " + f.y + " " + f.z); return; } t = t + dt; } out.println("NO"); } void run() { try { in = new MyScanner(System.in); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } public static void main(String[] args) { new C().run(); } }
Java
["4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 25", "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 50", "1\n1 2 3\n4 5 6\n20 10\n1 2 3"]
2 seconds
["YES\n25.5000000000\n10.0000000000 4.5000000000 0.0000000000", "NO", "YES\n0.0000000000\n1.0000000000 2.0000000000 3.0000000000"]
null
Java 6
standard input
[ "binary search", "geometry" ]
6e2a8aa58ed8cd308cb482e4c24cbbbb
The first line contains a single integer n (1 ≀ n ≀ 10000). The following n + 1 lines contain the coordinates xi, yi, zi, separated by single spaces. The coordinates of any two consecutive points do not coincide. The next line contains the velocities vp and vs, the last line contains Px, Py, Pz, separated by single spaces. All the numbers in the input are integers, their absolute value does not exceed 104. The speeds are strictly positive. It is guaranteed that vs ≀ vp.
2,100
If Harry Potter can catch the snitch while it is moving along the polyline (including the end (xn, yn, zn)), print "YES" in the first line (without the quotes). Print in the second line t, which is the earliest moment of time, when Harry will be able to catch the snitch. On the third line print three numbers X, Y, Z, the coordinates of the point at which this happens. The absolute or relative error in the answer should not exceed 10 - 6. If Harry is not able to catch the snitch during its moving along the described polyline, print "NO".
standard output
PASSED
7dc2bc7e387f5394c4f790fbdbb58f72
train_003.jsonl
1301410800
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≀ i ≀ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled: An example of such a bar can be seen on the picture. For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
256 megabytes
import java.util.Scanner; public class B_71_Progress_Bar { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(),k=input.nextInt(),t=input.nextInt(); double x=n*k*t; x=x/100; int sum=(int)Math.floor(x); int[] sats=new int[n]; int n1=sum/k; int n2=sum%k; int i; for(i=0;i<n1;i++) sats[i]=k; if(i<n) sats[i]=n2; for(i=0;i<n;i++) System.out.print(sats[i]+" "); } }
Java
["10 10 54", "11 13 37"]
1 second
["10 10 10 10 10 4 0 0 0 0", "13 13 13 13 0 0 0 0 0 0 0"]
null
Java 7
standard input
[ "implementation", "math" ]
0ad96b6a8032d70df400bf2ad72174bf
We are given 3 space-separated integers n, k, t (1 ≀ n, k ≀ 100, 0 ≀ t ≀ 100).
1,300
Print n numbers. The i-th of them should be equal to ai.
standard output
PASSED
6b47a030290d9633789df36be93a4534
train_003.jsonl
1301410800
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≀ i ≀ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled: An example of such a bar can be seen on the picture. For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
256 megabytes
/* * @author Sane */ import java.io.File; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.FileWriter; import java.util.Scanner; import java.io.FileOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.OutputStreamWriter; public class TheMain { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), k = sc.nextInt(), t = sc.nextInt(); double T = t*100.0/(n*k); double current = 0; boolean complete = false; for (int i = 1; i <= n; ++i) { if (complete) System.out.print(0); else if (current + 100.0/n <= t + 1e-9) { System.out.print(k); current += 100.0/n; } else { System.out.print((int) (k*n/100.0*(t-current))); complete = true; } if (i != n) System.out.print(" "); } System.out.println(); } }
Java
["10 10 54", "11 13 37"]
1 second
["10 10 10 10 10 4 0 0 0 0", "13 13 13 13 0 0 0 0 0 0 0"]
null
Java 7
standard input
[ "implementation", "math" ]
0ad96b6a8032d70df400bf2ad72174bf
We are given 3 space-separated integers n, k, t (1 ≀ n, k ≀ 100, 0 ≀ t ≀ 100).
1,300
Print n numbers. The i-th of them should be equal to ai.
standard output
PASSED
7e9f5e6838579003ad199b432dfabf6c
train_003.jsonl
1301410800
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≀ i ≀ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled: An example of such a bar can be seen on the picture. For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; /** * http://codeforces.com/contest/71/problem/B * * @author sultan.of.swing * */ public class TaskB { public FasterScanner mFScanner; public PrintWriter mOut; public TaskB() { mFScanner = new FasterScanner(); mOut = new PrintWriter(System.out); } public void solve() { int n, k, t; int total; int abs; int val; n = mFScanner.nextInt(); k = mFScanner.nextInt(); t = mFScanner.nextInt(); total = n * k; abs = t * total; abs /= 100; while (n-- > 0) { val = Math.min(abs, k); mOut.print(val + " "); abs -= val; } mOut.println(); } public void flush() { mOut.flush(); } public void close() { mOut.close(); } public static void main(String[] args) { TaskB mSol = new TaskB(); mSol.solve(); mSol.flush(); mSol.close(); } class FasterScanner { private InputStream mIs; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FasterScanner() { this(System.in); } public FasterScanner(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 nextString() { 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 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 double nextDouble() { Double next; next = Double.parseDouble(nextString()); return next; } 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; } public char[] nextCharArray(int N) { int i; char[] array; String str; array = new char[N]; i = 0; str = nextLine(); for (i = 0; i < N && i < str.length(); i++) { array[i] = str.charAt(i); } return array; } public char[][] nextChar2DArray(int M, int N) { int i; char[][] array; array = new char[M][N]; i = 0; for (i = 0; i < M; i++) { array[i] = nextCharArray(N); } return array; } public int[] nextIntArray(int N) { int i; int[] array; array = new int[N]; i = 0; for (i = 0; i < N; i++) { array[i] = nextInt(); } return array; } public int[][] nextInt2DArray(int M, int N) { int i; int[][] array; array = new int[M][N]; i = 0; for (i = 0; i < M; i++) { array[i] = nextIntArray(N); } return array; } public long[] nextLongArray(int N) { int i; long[] array; array = new long[N]; i = 0; for (i = 0; i < N; i++) { array[i] = nextLong(); } return array; } public long[][] nextLong2DArray(int M, int N) { int i; long[][] array; array = new long[M][N]; i = 0; for (i = 0; i < M; i++) { array[i] = nextLongArray(N); } return array; } public double[] nextDoubleArray(int N) { int i; double[] array; array = new double[N]; for (i = 0; i < N; i++) { array[i] = nextDouble(); } return array; } public double[][] nextDouble2DArray(int M, int N) { int i; double[][] array; array = new double[M][N]; for (i = 0; i < M; i++) { array[i] = nextDoubleArray(N); } return array; } } }
Java
["10 10 54", "11 13 37"]
1 second
["10 10 10 10 10 4 0 0 0 0", "13 13 13 13 0 0 0 0 0 0 0"]
null
Java 7
standard input
[ "implementation", "math" ]
0ad96b6a8032d70df400bf2ad72174bf
We are given 3 space-separated integers n, k, t (1 ≀ n, k ≀ 100, 0 ≀ t ≀ 100).
1,300
Print n numbers. The i-th of them should be equal to ai.
standard output
PASSED
7ef8a18d570be0158fb90d152a9f1115
train_003.jsonl
1301410800
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≀ i ≀ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled: An example of such a bar can be seen on the picture. For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
256 megabytes
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int k = in.nextInt(); int t = in.nextInt(); int complete = n * k * t / 100; int[] a = new int[n]; for (int i = 0; i < n; i++) { if (complete >= k) { a[i] = k; complete -= k; } else { a[i] = complete; complete = 0; } } for (int i = 0; i < n; i++) { out.printf("%d ", a[i]); } } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } }
Java
["10 10 54", "11 13 37"]
1 second
["10 10 10 10 10 4 0 0 0 0", "13 13 13 13 0 0 0 0 0 0 0"]
null
Java 7
standard input
[ "implementation", "math" ]
0ad96b6a8032d70df400bf2ad72174bf
We are given 3 space-separated integers n, k, t (1 ≀ n, k ≀ 100, 0 ≀ t ≀ 100).
1,300
Print n numbers. The i-th of them should be equal to ai.
standard output
PASSED
f95bc5db1ed900f8bbb729354b0cc127
train_003.jsonl
1301410800
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≀ i ≀ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled: An example of such a bar can be seen on the picture. For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.
256 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.Scanner; public class ProgressBar { public static void main(String[] args) throws IOException { Scanner x=new Scanner(System.in); int n,k,t; long sum; n=x.nextInt(); k=x.nextInt(); t=x.nextInt(); int arr[]=new int[n]; sum=(long)(n)*(k*t)/100; int kk=(int) (sum/k); int moder=(int) (sum%k); for(int i=0;i<kk;i++) arr[i]=k; if(kk<n) arr[kk]=moder; for(int i=kk+1;i<n;i++) arr[i]=0; BufferedWriter w = new BufferedWriter( new OutputStreamWriter(System.out)); w.append(arr[0]+""); for(int i=1;i<n;i++) w.append(" "+arr[i]); w.append("\n"); w.flush(); w.close(); } }
Java
["10 10 54", "11 13 37"]
1 second
["10 10 10 10 10 4 0 0 0 0", "13 13 13 13 0 0 0 0 0 0 0"]
null
Java 7
standard input
[ "implementation", "math" ]
0ad96b6a8032d70df400bf2ad72174bf
We are given 3 space-separated integers n, k, t (1 ≀ n, k ≀ 100, 0 ≀ t ≀ 100).
1,300
Print n numbers. The i-th of them should be equal to ai.
standard output
PASSED
8ecdcec0652a0fe405d29936b83d044b
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int index = 0; int even = 0; int odd = 0; ArrayList<Integer> x = new ArrayList<>(); for (int i = 1; i <= n; i++) { int xi = scanner.nextInt(); xi = xi % 2; x.add(xi); if (xi == 0) { even++; } else if (xi != 0) { odd++; } } if (even > odd) { index = x.indexOf(1) + 1; } else if (odd > even) { index = x.indexOf(0) + 1; } System.out.println(index); scanner.close(); } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
dc4edcd42a517b54867d55d7d3dd97f5
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.*; public class sadd { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t=0,a=0,n=0,m=0,cont=0,cont2=0; t= in .nextInt(); for(int i=0;i<t;i++) { a= in .nextInt(); if(a%2==0) { cont++; n = i+1; } else { cont2++; m = i+1; } } if(cont==1) System.out.print(n); else if(cont2==1) System.out.print(m); } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
4e29afee73473b4246a38c3de7335d91
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Alice */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, Scanner in, PrintWriter out) { Scanner str = new Scanner(System.in); int n = str.nextInt(); int count = 0, num = 0; int []arr = new int[n]; for(int i = 0; i < n; i++) { arr[i] = str.nextInt(); } for(int i = 0; i < n; i++) { if(arr[i]%2 == 0) { count++; } } if(count > 1) { for(int i = 0; i < n; i++) { if(arr[i]%2 != 0) { num = i + 1; } } } else { for(int i = 0; i < n; i++) { if(arr[i]%2 == 0) { num = i + 1; } } } System.out.println(num); } } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
f306a639a381882f2705211202506f9a
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.*; public class Problem { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); List<Integer> input = new ArrayList<>(); for (int i = 0; i < n; i++) { input.add(sc.nextInt()); } if (input.get(0) % 2 == 0 && input.get(1) % 2 == 0) { for (int i = 0, l = input.size(); i < l; i++) { if (input.get(i) % 2 != 0) { System.out.println(i + 1); break; } } } else if (input.get(0) % 2 != 0 && input.get(1) % 2 != 0) { for (int i = 0, l = input.size(); i < l; i++) { if (input.get(i) % 2 == 0) { System.out.println(i + 1); break; } } } else { if (input.get(1) % 2 == 0 && input.get(2) % 2 == 0) { // print the first System.out.println(1); } else if (input.get(1) % 2 != 0 && input.get(2) % 2 != 0) { System.out.println(1); } else { //print the second System.out.println(2); } } } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
09a8fae300bb2578fea0547c56a247cd
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.*; import java.util.stream.*; import java.io.*; public class Solution { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int[] arr = new int[n]; Arrays.setAll(arr, i -> s.nextInt()); int sum = IntStream.range(0, arr.length).map(i -> (arr[i] & 1) * (i+1)).sum(); int sum1To100 = (n*(n+1))/2; if(sum > n) { System.out.println(sum1To100 - sum); } else { System.out.println(sum); } } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
31d83a9add5e255dd46e5df747e91324
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class Aibek { public static void main(String[] args) { Scanner in = new Scanner (System.in); int n=in.nextInt(); int [] a=new int[n]; int res=0; ArrayList<Integer> chet=new ArrayList<> (); ArrayList<Integer> nechet=new ArrayList<> (); for (int i = 0; i < n; i++) { a[i]=in.nextInt(); if(a[i]%2==0) chet.add(a[i]); else nechet.add(a[i]); } if(chet.size()==1) { for (int i = 0; i < n; i++) { if (chet.get (0) == a[i]) { res = i + 1; break; } } } else { for (int i = 0; i < n; i++) { if (nechet.get(0) == a[i]) { res = i + 1; break; } } } System.out.println (res); } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
361db59fe0371a98886ba8f15503f15c
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.ArrayList; import java.util.LinkedList; import java.util.Scanner; public class CodeforA { public static void main(String[] args) { int i = 0, j = 0,even =0 , odd=0; ArrayList<Integer> list = new ArrayList<>(); LinkedList<Character> linked = new LinkedList<Character>(); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int arr[] = new int[n]; int arr1[] = new int[n]; for(i=0 ; i!=n ; i++) arr[i]=sc.nextInt(); for(i=0 ; i!=n ; i++) arr1[i]=arr[i]%2; for(i=0 ; i!=n ; i++) { if(arr1[i]==0) even++; else odd++; } if(even>odd) { for(i=0 ; i!=n ; i++) if(arr[i]%2>0) { System.out.println(i+1); return; } } if(even<odd) { for(i=0 ; i!=n ; i++) if(arr[i]%2==0){ System.out.println(i+1); return;} } } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
12c57f61f46131bb4c00bf4af78c1867
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.Scanner; public class IQTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int even = sc.nextInt() % 2; int even2 = sc.nextInt() % 2; int even3 = sc.nextInt() % 2; if (even != even2) { if (even2 != even3) { System.out.println(2); System.exit(0); } else { System.out.println(1); System.exit(0); } } else { if (even2 != even3) { System.out.println(3); System.exit(0); } } for (int i = 3; i < n; i++) { if (sc.nextInt() % 2 != even) { System.out.println(i + 1); break; } } } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
e969554acaa7c24486f02fcab03ba49d
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.*; import java.io.*; public class Main{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); int a; int eve=0; int odd=0; a = sc.nextInt(); int arr[] = new int[a]; for(int i=0;i<a;i++) { arr[i]=sc.nextInt(); if(arr[i]%2==0) eve++; else odd++; } if(eve>odd) { for(int i=0;i<a;i++) { if(arr[i]%2!=0){ System.out.println(i+1); break;} } } else { for(int i=0;i<a;i++) { if(arr[i]%2==0){ System.out.println(i+1); break;} } } } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
d3f637d73a509d27229e757aacaee733
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.*; import java.io.*; public class Main{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); int a; int eve=0; int odd=0; a = sc.nextInt(); int arr[] = new int[a]; for(int i=0;i<a;i++) { arr[i]=sc.nextInt(); if(arr[i]%2==0) eve++; else odd++; } if(eve>odd) { for(int i=0;i<a;i++) { if(arr[i]%2!=0) System.out.println(i+1); // break;} } } else { for(int i=0;i<a;i++) { if(arr[i]%2==0) System.out.println(i+1); //break;} } } } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
bacee0f6620f69fb59f5776aad5379ad
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
/* Comment block here ... */ import java.util.Scanner; public class prog_6 { public static void main(String[] args) { Scanner keyb = new Scanner(System.in); int [] eed = new int [100]; int kammarra,var; int x=0; kammarra=keyb.nextInt(); for(int i=0;i<kammarra;i++) { var=keyb.nextInt(); eed [i]=var%2; } for(int i=kammarra;i<100;i++) { eed [i]=3; } for(int j=1;j<=kammarra;j++) { x++; if(eed [j-1]==eed[j]) continue; else if(eed [j]==eed[j+1]&&eed [j-1]!=eed[j+1]){ System.out.print(x); System.exit(0); } else if (kammarra == j){ System.out.print(x); System.exit(0); } else { System.out.print(x+1); System.exit(0); } } keyb.close(); } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
2434d41d163ffd2104c282dc8ddba1db
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.Scanner; import java.lang.Math; public class IQTest{ public static void main(String args[]){ Scanner scan = new Scanner(System.in); int numbers = scan.nextInt(); int numEvens = 0; int even_index = -1; int odd_index = -1; for(int i=0;i<numbers;i++){ int next = scan.nextInt(); if(next%2 == 0){ numEvens++; even_index = i; }else{ odd_index = i; } } if(numEvens == 1){ System.out.println(even_index+1); }else{ System.out.println(odd_index+1); } } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
b0e37e41bf7a0a8a0df2357beb4ddcef
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.*; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; int as = 0; int bs = 0; for(int i = 0;i < n;i++) { a[i] = sc.nextInt(); if(a[i] % 2 == 0) { as++; } else { bs++; } } if(as < bs) { for(int i = 0,j = 1;i < n && j < n+1;i++,j++) { if(a[i] % 2 == 0) { System.out.println(j); return; } } } else { for(int i = 0,j = 1;i < n && j < n+1;i++,j++) { if(a[i] % 2 != 0) { System.out.println(j); return; } } } } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
abac776ba597fd54d4e25cf011da85d1
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.io.*; import java.util.*; public class Example { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int[] num= new int[n]; int flag=0; for(int i=0;i<n;i++){ num[i]=in.nextInt(); } boolean count=false; for(int i=0; i<n;i++){ int temp=num[i]; if(count==false){ int j=0; while(j<n){ if(j!=i){ int c=Math.abs(temp-num[j]); if(c%2==0){ flag=0; count=false; break; }else{ flag=i+1; count=true; } } j++; } }else{ break; } } System.out.println(flag); } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
c387f33ac4e821c96e698770a24b377d
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.Scanner; /** * * @author Leonidas */ public class IQTest { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = 4, c = 0, pos = 0, i = 0, cpar = 0,cimpar = 0; String sec; n = Integer.valueOf(sc.nextLine()); boolean sw = true; sec = sc.nextLine(); String[] vectsec = sec.split(" "); for (int j = 0; j < n; j++) { if (Integer.valueOf(vectsec[j]) % 2 == 0) { cpar++; } else { cimpar++; } } for (int j = 0; j < n; j++) { if (n == 1) { if (Integer.valueOf(vectsec[0]) % 2 == 0) { pos = 1; } else { pos = 0; } sw = false; } else { if (cpar > cimpar) { if (!(Integer.valueOf(vectsec[j]) % 2 == 0)) { pos = j+1; } }else{ if (Integer.valueOf(vectsec[j]) % 2 == 0) { pos = j+1; } } } } System.out.println(pos); } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
84fa3336d7916f59c660fa2e07b8611e
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.Scanner; public class IQ_test { public static void main(String[] args) { Scanner in = new Scanner(System.in); int size = in.nextInt(); int [] input = new int [size]; for ( int i=0 ; i<size ; i++) { input[i]=in.nextInt(); } int count =0; int count1=0; int count2=0; int count3=0; int j =1; //if (count<1) //{ int k =input.length-1; for ( int i=0 ; j<size ; i++,j++,k--) { if (k==i||k==j||k<0) { break; } if ((input[i]==input[j]&&input[i]==input[k])||input[i]==input[k]) { // equal(input); // count++; // break; count1++; } } //} // if (count<1) // { j=1; for ( int i=0 ; j<size ; i++,j++) { if (input[i]%2==0&&input[j]%2==0) { // isOdd(input); // count++; // break; count2++; } } // } // // // // // if (count<1) // { j=1; for ( int i=0 ; j<size ; i++,j++) { if (input[i]%2!=0&&input[j]%2!=0) { // isEven(input); // count++; // break; count3++; } } // } if (count2>count1&&count2>count3) isOdd(input); else if (count3>count1&&count3>count2) isEven(input); else equal(input); } public static void equal (int[]input) { int j =1; int con =0; for (int i=0 ; i<input.length-1;i++) { if (input[i]==input[j]||input[i]==input[input.length-1]) { con = input[i]; break; } j++; } //j=1; for (int i=0 ; i<input.length ; i++) { if (input[i]!=con) { System.out.println(i+1); break; } // j++; } } public static void isOdd(int [] input) { for ( int i=0 ; i<input.length;i++) { if (input[i]%2>0) { System.out.println(i+1); break; } } } public static void isEven(int [] input) { for ( int i=0 ; i<input.length;i++) { if (input[i]%2==0) { System.out.println(i+1); break; } } } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
9e02376ec8ac8472122c8e164c6c5827
train_003.jsonl
1280761200
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
256 megabytes
import java.util.Scanner; public class IQ { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int arr[] = new int[n]; for (int i=0;i<n;i++){ arr[i]= s.nextInt(); } int e=0; int o =0; int ans =-1; for(int i=1;i<n-1;i++){ if(i-1>=0 && arr[i-1]%2==0){ e=1; } if(i-1>=0 && arr[i-1]%2!=0){ o=1; } if(arr[i]%2==0 && arr[i+1]%2!=0 && o==1){ ans = i; } if(arr[i]%2!=0 && arr[i+1]%2==0 && o==1){ ans = i+1; } if(arr[i]%2==0 && arr[i+1]%2!=0 && e==1){ ans = i+1; } if(arr[i]%2!=0 && arr[i+1]%2==0 && e==1){ ans = i; } } if(ans==-1){ System.out.println(1); }else System.out.println(ans+1); } }
Java
["5\n2 4 7 8 10", "4\n1 2 1 1"]
2 seconds
["3", "2"]
null
Java 8
standard input
[ "brute force" ]
dd84c2c3c429501208649ffaf5d91cee
The first line contains integer n (3 ≀ n ≀ 100) β€” amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
1,300
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
standard output
PASSED
7cb9c4db4c64d5007783a7796e5b75e3
train_003.jsonl
1592491500
This is a harder version of the problem H with modification queries.Lester and Delbert work at an electronics company. They are currently working on a microchip component serving to connect two independent parts of a large supercomputer.The component is built on top of a breadboardΒ β€” a grid-like base for a microchip. The breadboard has $$$n$$$ rows and $$$m$$$ columns, and each row-column intersection contains a node. Also, on each side of the breadboard there are ports that can be attached to adjacent nodes. Left and right side have $$$n$$$ ports each, and top and bottom side have $$$m$$$ ports each. Each of the ports is connected on the outside to one of the parts bridged by the breadboard, and is colored red or blue respectively. Ports can be connected by wires going inside the breadboard. However, there are a few rules to follow: Each wire should connect a red port with a blue port, and each port should be connected to at most one wire. Each part of the wire should be horizontal or vertical, and turns are only possible at one of the nodes. To avoid interference, wires can not have common parts of non-zero length (but may have common nodes). Also, a wire can not cover the same segment of non-zero length twice.The capacity of the breadboard is the largest number of red-blue wire connections that can be made subject to the rules above. For example, the breadboard above has capacity $$$7$$$, and one way to make seven connections is pictured below. Up to this point statements of both versions are identical. Differences follow below.As is common, specifications of the project change a lot during development, so coloring of the ports is not yet fixed. There are $$$q$$$ modifications to process, each of them has the form of "colors of all ports in a contiguous range along one of the sides are switched (red become blue, and blue become red)". All modifications are persistent, that is, the previous modifications are not undone before the next one is made.To estimate how bad the changes are, Lester and Delbert need to find the breadboard capacity after each change. Help them do this efficiently.
512 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author lewin */ 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); HBreadboardCapacity solver = new HBreadboardCapacity(); solver.solve(1, in, out); out.close(); } static class HBreadboardCapacity { int n; int m; public static int INF = 1 << 20; String col = "RB"; String dir = "LRUD"; SegmentTreeX[] rt; HBreadboardCapacity.ST2[] cts; int[][] ss; int get() { int[] r = {n, m}; int ans = INF; for (int i = 0; i < 2; i++) { HBreadboardCapacity.State x = rt[i].query(0, rt[i].n - 1); for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { int t1 = j == 0 ? ss[i][0] : (r[1 - i] - ss[i][0]); int t2 = k == 0 ? ss[i][1] : (r[1 - i] - ss[i][1]); ans = Math.min(ans, x.a[x.flip * 4 + j * 2 + k] + t1 + t2); } } } return ans; } public void solve(int testNumber, InputReader in, OutputWriter out) { n = in.nextInt(); m = in.nextInt(); int q = in.nextInt(); int[][] g = new int[4][]; for (int i = 0; i < 4; i++) { char[] x = in.next().toCharArray(); g[i] = new int[x.length]; for (int k = 0; k < x.length; k++) { g[i][k] = col.indexOf(x[k]); } } cts = new HBreadboardCapacity.ST2[4]; ss = new int[2][2]; for (int i = 0; i < 4; i++) { cts[i] = new HBreadboardCapacity.ST2(g[i]); ss[1 - i / 2][i % 2] = cts[i].query(0, cts[i].n - 1); } rt = new SegmentTreeX[2]; rt[0] = new SegmentTreeX(n, m, g[0], g[1]); rt[1] = new SegmentTreeX(m, n, g[2], g[3]); out.println(get()); while (q-- > 0) { int id = dir.indexOf(in.next().charAt(0)); int l = in.nextInt() - 1, r = in.nextInt() - 1; if (l > r) { int t = l; l = r; r = t; } cts[id].modify(l, r, 1); rt[id / 2].modify(l, r, (id % 2) + 1); ss[1 - id / 2][id % 2] = cts[id].query(0, cts[id].n - 1); out.println(get()); } } static class State { public int[] a; public int flip; public State() { a = new int[16]; this.flip = 0; } } static class ST2 extends SegmentTree<Integer, Integer> { public int[] arr; public ST2(int[] arr) { super(arr.length); this.arr = arr; this.reset(); } public Integer getNeutralDelta() { return 0; } public Integer getNeutralValue() { return 0; } public Integer getInitValue(int position) { return arr[position]; } public Integer joinValueWithDelta(Integer value, Integer delta, int segmentLength) { if (delta == 0) return value; if (delta == 1) return segmentLength - value; return null; } public Integer joinDeltas(Integer delta1, Integer delta2) { return delta1 ^ delta2; } public Integer joinValues(Integer value1, Integer value2) { return value1 + value2; } } public class SegmentTreeX { public int n; public int m; HBreadboardCapacity.State[] value; int[] top; int[] bottom; public SegmentTreeX(int n, int m, int[] top, int[] bottom) { this.n = n; this.m = m; this.top = top; this.bottom = bottom; value = new HBreadboardCapacity.State[4 * n]; init(0, 0, n - 1); } public HBreadboardCapacity.State getInitValue(int position) { HBreadboardCapacity.State ret = new HBreadboardCapacity.State(); AUtils.deepFill(ret.a, INF); for (int j = 0; j < 4; j++) { int val = (((j & 1) == 1) ? (1 - top[position]) : (top[position])) + (((j & 2) == 2) ? (1 - bottom[position]) : (bottom[position])); ret.a[j * 4] = val; ret.a[j * 4 + 3] = 2 - val; } return ret; } public HBreadboardCapacity.State joinValues(HBreadboardCapacity.State value1, HBreadboardCapacity.State value2) { HBreadboardCapacity.State ret = new HBreadboardCapacity.State(); AUtils.deepFill(ret.a, INF); for (int q = 0; q < 4; q++) { ret.a[q * 4 + 0 * 2 + 0] = Math.min(ret.a[q * 4 + 0 * 2 + 0], value1.a[(q ^ value1.flip) * 4 + 0 * 2 + 0] + value2.a[(q ^ value2.flip) * 4 + 0 * 2 + 0]); ret.a[q * 4 + 0 * 2 + 0] = Math.min(ret.a[q * 4 + 0 * 2 + 0], value1.a[(q ^ value1.flip) * 4 + 0 * 2 + 0] + value2.a[(q ^ value2.flip) * 4 + (0 ^ 1) * 2 + 0] + this.m); ret.a[q * 4 + 0 * 2 + 0] = Math.min(ret.a[q * 4 + 0 * 2 + 0], value1.a[(q ^ value1.flip) * 4 + 0 * 2 + 1] + value2.a[(q ^ value2.flip) * 4 + 1 * 2 + 0]); ret.a[q * 4 + 0 * 2 + 0] = Math.min(ret.a[q * 4 + 0 * 2 + 0], value1.a[(q ^ value1.flip) * 4 + 0 * 2 + 1] + value2.a[(q ^ value2.flip) * 4 + (1 ^ 1) * 2 + 0] + this.m); ret.a[q * 4 + 0 * 2 + 1] = Math.min(ret.a[q * 4 + 0 * 2 + 1], value1.a[(q ^ value1.flip) * 4 + 0 * 2 + 0] + value2.a[(q ^ value2.flip) * 4 + 0 * 2 + 1]); ret.a[q * 4 + 0 * 2 + 1] = Math.min(ret.a[q * 4 + 0 * 2 + 1], value1.a[(q ^ value1.flip) * 4 + 0 * 2 + 0] + value2.a[(q ^ value2.flip) * 4 + (0 ^ 1) * 2 + 1] + this.m); ret.a[q * 4 + 0 * 2 + 1] = Math.min(ret.a[q * 4 + 0 * 2 + 1], value1.a[(q ^ value1.flip) * 4 + 0 * 2 + 1] + value2.a[(q ^ value2.flip) * 4 + 1 * 2 + 1]); ret.a[q * 4 + 0 * 2 + 1] = Math.min(ret.a[q * 4 + 0 * 2 + 1], value1.a[(q ^ value1.flip) * 4 + 0 * 2 + 1] + value2.a[(q ^ value2.flip) * 4 + (1 ^ 1) * 2 + 1] + this.m); ret.a[q * 4 + 1 * 2 + 0] = Math.min(ret.a[q * 4 + 1 * 2 + 0], value1.a[(q ^ value1.flip) * 4 + 1 * 2 + 0] + value2.a[(q ^ value2.flip) * 4 + 0 * 2 + 0]); ret.a[q * 4 + 1 * 2 + 0] = Math.min(ret.a[q * 4 + 1 * 2 + 0], value1.a[(q ^ value1.flip) * 4 + 1 * 2 + 0] + value2.a[(q ^ value2.flip) * 4 + (0 ^ 1) * 2 + 0] + this.m); ret.a[q * 4 + 1 * 2 + 0] = Math.min(ret.a[q * 4 + 1 * 2 + 0], value1.a[(q ^ value1.flip) * 4 + 1 * 2 + 1] + value2.a[(q ^ value2.flip) * 4 + 1 * 2 + 0]); ret.a[q * 4 + 1 * 2 + 0] = Math.min(ret.a[q * 4 + 1 * 2 + 0], value1.a[(q ^ value1.flip) * 4 + 1 * 2 + 1] + value2.a[(q ^ value2.flip) * 4 + (1 ^ 1) * 2 + 0] + this.m); ret.a[q * 4 + 1 * 2 + 1] = Math.min(ret.a[q * 4 + 1 * 2 + 1], value1.a[(q ^ value1.flip) * 4 + 1 * 2 + 0] + value2.a[(q ^ value2.flip) * 4 + 0 * 2 + 1]); ret.a[q * 4 + 1 * 2 + 1] = Math.min(ret.a[q * 4 + 1 * 2 + 1], value1.a[(q ^ value1.flip) * 4 + 1 * 2 + 0] + value2.a[(q ^ value2.flip) * 4 + (0 ^ 1) * 2 + 1] + this.m); ret.a[q * 4 + 1 * 2 + 1] = Math.min(ret.a[q * 4 + 1 * 2 + 1], value1.a[(q ^ value1.flip) * 4 + 1 * 2 + 1] + value2.a[(q ^ value2.flip) * 4 + 1 * 2 + 1]); ret.a[q * 4 + 1 * 2 + 1] = Math.min(ret.a[q * 4 + 1 * 2 + 1], value1.a[(q ^ value1.flip) * 4 + 1 * 2 + 1] + value2.a[(q ^ value2.flip) * 4 + (1 ^ 1) * 2 + 1] + this.m); } ret.flip = 0; return ret; } public void init(int root, int left, int right) { if (left == right) { value[root] = getInitValue(left); } else { int mid = (left + right) >> 1; init(2 * root + 1, left, mid); init(2 * root + 2, mid + 1, right); value[root] = joinValues(value[2 * root + 1], value[2 * root + 2]); } } void pushDelta(int root, int left, int right) { if (value[root].flip != 0) { value[2 * root + 1].flip ^= value[root].flip; value[2 * root + 2].flip ^= value[root].flip; value[root] = joinValues(value[2 * root + 1], value[2 * root + 2]); } } public HBreadboardCapacity.State query(int from, int to) { return query(from, to, 0, 0, n - 1); } HBreadboardCapacity.State query(int from, int to, int root, int left, int right) { if (from == left && to == right) return value[root]; pushDelta(root, left, right); int mid = (left + right) >> 1; if (from <= mid && to > mid) return joinValues( query(from, mid, root * 2 + 1, left, mid), query(mid + 1, to, root * 2 + 2, mid + 1, right)); else if (from <= mid) return query(from, mid, root * 2 + 1, left, mid); else if (to > mid) return query(mid + 1, to, root * 2 + 2, mid + 1, right); else throw new RuntimeException("Incorrect query from " + from + " to " + to); } public void modify(int from, int to, int delta) { modify(from, to, delta, 0, 0, n - 1); } void modify(int from, int to, int delta, int root, int left, int right) { if (from == left && to == right) { this.value[root].flip ^= delta; return; } pushDelta(root, left, right); int mid = (left + right) >> 1; if (from <= mid) modify(from, Math.min(to, mid), delta, 2 * root + 1, left, mid); if (to > mid) modify(Math.max(from, mid + 1), to, delta, 2 * root + 2, mid + 1, right); value[root] = joinValues(value[2 * root + 1], value[2 * root + 2]); } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1 << 16]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (this.numChars == -1) { throw new InputMismatchException(); } else { if (this.curChar >= this.numChars) { this.curChar = 0; try { this.numChars = this.stream.read(this.buf); } catch (IOException var2) { throw new InputMismatchException(); } if (this.numChars <= 0) { return -1; } } return this.buf[this.curChar++]; } } public int nextInt() { int c; for (c = this.read(); isSpaceChar(c); c = this.read()) { ; } byte sgn = 1; if (c == 45) { sgn = -1; c = this.read(); } int res = 0; while (c >= 48 && c <= 57) { res *= 10; res += c - 48; c = this.read(); if (isSpaceChar(c)) { return res * sgn; } } throw new InputMismatchException(); } public String next() { int c; while (isSpaceChar(c = this.read())) { ; } StringBuilder result = new StringBuilder(); result.appendCodePoint(c); while (!isSpaceChar(c = this.read())) { result.appendCodePoint(c); } return result.toString(); } public static boolean isSpaceChar(int c) { return c == 32 || c == 10 || c == 13 || c == 9 || c == -1; } } static class AUtils { public static void deepFill(int[] x, int val) { Arrays.fill(x, val); } } static 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 close() { writer.close(); } public void println(int i) { writer.println(i); } } static abstract class SegmentTree<E, T> { public int n; protected E[] value; protected T[] delta; public abstract T getNeutralDelta(); public abstract E getNeutralValue(); public abstract E getInitValue(int position); public abstract E joinValueWithDelta(E value, T delta, int segmentLength); public abstract T joinDeltas(T delta1, T delta2); public abstract E joinValues(E value1, E value2); public SegmentTree(int n) { this.n = n; value = (E[]) new Object[2 * n]; delta = (T[]) new Object[2 * n]; // this.reset(); } public void reset() { for (int i = 0; i < n; i++) { value[i + n] = getInitValue(i); } for (int i = 2 * n - 1; i > 1; i -= 2) { value[i >> 1] = joinValues(value[i], value[i ^ 1]); } for (int i = 0; i < 2 * n; i++) delta[i] = getNeutralDelta(); } protected void pushDelta(int i) { int d = 0; for (; (i >> d) > 0; d++) { } for (d -= 2; d >= 0; d--) { int x = i >> d; value[x >> 1] = joinNodeValueWithDelta(x >> 1, 1 << (d + 1)); delta[x] = joinDeltas(delta[x], delta[x >> 1]); delta[x ^ 1] = joinDeltas(delta[x ^ 1], delta[x >> 1]); delta[x >> 1] = getNeutralDelta(); } } protected E joinNodeValueWithDelta(int i, int len) { return joinValueWithDelta(value[i], delta[i], len); } public E query(int from, int to) { from += value.length >> 1; to += value.length >> 1; pushDelta(from); pushDelta(to); E res = getNeutralValue(); boolean found = false; for (int len = 1; from <= to; from = (from + 1) >> 1, to = (to - 1) >> 1, len <<= 1) { if ((from & 1) != 0) { res = found ? joinValues(res, joinNodeValueWithDelta(from, len)) : joinNodeValueWithDelta(from, len); found = true; } if ((to & 1) == 0) { res = found ? joinValues(res, joinNodeValueWithDelta(to, len)) : joinNodeValueWithDelta(to, len); found = true; } } if (!found) throw new RuntimeException(); return res; } public void modify(int from, int to, T delta) { from += value.length >> 1; to += value.length >> 1; pushDelta(from); pushDelta(to); int a = from; int b = to; for (; from <= to; from = (from + 1) >> 1, to = (to - 1) >> 1) { if ((from & 1) != 0) { this.delta[from] = joinDeltas(this.delta[from], delta); } if ((to & 1) == 0) { this.delta[to] = joinDeltas(this.delta[to], delta); } } for (int i = a, len = 1; i > 1; i >>= 1, len <<= 1) { if (i % 2 == 1) i ^= 1; value[i >> 1] = joinValues(joinNodeValueWithDelta(i, len), joinNodeValueWithDelta(i ^ 1, len)); } for (int i = b, len = 1; i > 1; i >>= 1, len <<= 1) { if (i % 2 == 1) i ^= 1; value[i >> 1] = joinValues(joinNodeValueWithDelta(i, len), joinNodeValueWithDelta(i ^ 1, len)); } } } }
Java
["4 5 4\nBBRR\nRBBR\nBBBBB\nRRRRR\nL 2 3\nR 3 4\nU 1 5\nD 1 5"]
2 seconds
["7\n7\n9\n4\n9"]
null
Java 11
standard input
[]
64b942d23386ab53af7a4a02243248ce
The first line contains three integers $$$n, m, q$$$ ($$$1 \leq n, m \leq 10^5$$$, $$$0 \leq q \leq 10^5$$$)Β β€” the number of rows and columns of the breadboard, and the number of modifications respectively. The next four lines describe initial coloring of the ports. Each character in these lines is either R or B, depending on the coloring of the respective port. The first two of these lines contain $$$n$$$ characters each, and describe ports on the left and right sides respectively from top to bottom. The last two lines contain $$$m$$$ characters each, and describe ports on the top and bottom sides respectively from left to right. The next $$$q$$$ lines describe modifications. Each of these lines contains a character $$$s$$$, followed by two integers $$$l$$$ and $$$r$$$. If $$$s$$$ is L or R, the modification is concerned with ports on the left/right side respectively, $$$l$$$ and $$$r$$$ satisfy $$$1 \leq l \leq r \leq n$$$, and ports in rows between $$$l$$$ and $$$r$$$ (inclusive) on the side switch colors. Similarly, if $$$s$$$ is U or D, then $$$1 \leq l \leq r \leq m$$$, and ports in columns between $$$l$$$ and $$$r$$$ (inclusive) on the top/bottom side respectively switch colors.
3,500
Print $$$q + 1$$$ integers, one per lineΒ β€” the breadboard capacity after $$$0, \ldots, q$$$ modifications have been made to the initial coloring.
standard output
PASSED
2b7b859d66df9d1c2d5cda5387827dbd
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.*; import java.io.*; public class a { public static PrintWriter out; public static FS sc; public static void main(String[] Args) throws Exception { sc = new FS(System.in); out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(System.out))); int t = sc.nextInt(); while (t-->0) { String s = sc.next(); int n = s.length(); int first = n; int last = 0; int total = 0; for (int i = 0; i < n; i++) if (s.charAt(i) == '1') { total++; if (first == n) first = i; last = i; } int ans = last - first + 1 - total; if (first == n) ans = 0; out.println(ans); } out.close(); } public static class FS { BufferedReader br; StringTokenizer st; FS(InputStream in) throws Exception { br = new BufferedReader(new InputStreamReader(in)); st = new StringTokenizer(br.readLine()); } String next() throws Exception { if (st.hasMoreTokens()) return st.nextToken(); st = new StringTokenizer(br.readLine()); return next(); } int nextInt() throws Exception { return Integer.parseInt(next()); } long nextLong() throws Exception { return Long.parseLong(next()); } double nextDouble() throws Exception { return Double.parseDouble(next()); } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
002d507986bf4335df1ed124e0a32c9d
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.ArrayList; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class TestJava { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList<String> lines = new ArrayList<String>(); for (int i = 0; i < n + 1; i++) { String g = sc.nextLine(); lines.add(g); } for (String s : lines) { if (!s.isEmpty()) { Pattern pattern = Pattern.compile("10+(?=1)"); Matcher matcher = pattern.matcher(s); if (matcher.find()) { int start = 0; int num = 0; while (matcher.find(start)) { int cc = matcher.group().replaceAll("1", "").length(); num += cc; start = matcher.end(); } System.out.println(num); } else { System.out.println(0); } } } } } //System.out.println(w);
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
ddfec0d9a38ae566a3ffbccfb6b5bca0
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Erasing_Zeroes { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while(t-- > 0) { String str = br.readLine(); int first = str.indexOf("1"); int end = str.lastIndexOf("1"); int count = 0; if( first == end ) System.out.println("0"); else { for(int i = first;i < end ;i++) { if(str.charAt(i) == '0') count++; }System.out.println(count); } } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
cdbd8492e4383190ca8e0d417d6862fa
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
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){ String s = sc.next(); char ch[]=s.toCharArray(); if(ch.length==1){ System.out.println(0); } else{ int count=0; int j = 0; for(j=ch.length-1;j>=0;j--){ if(ch[j]=='1'){ break; } } // while(ch[j]!='1'){ // j--; // } for(int i=1;i<=j;i++){ if(ch[i-1]=='1' && ch[i]=='0' && ch[j]=='1'){ count++; ch[i] = '1'; } } System.out.println(count); } t--; } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
09d479ba2d871a6594dd058af5a1ae9a
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.Scanner; public class b3abes { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int cnt = 0; String str = sc.next(); int start = str.indexOf("1"); int end = str.lastIndexOf("1"); if(start == end) System.out.println("0"); else { for(int i=start;i<=end;i++) if(str.charAt(i) == '0') cnt++; System.out.println(cnt); }} } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
5100a887b7fc478fe66b789e3368413a
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
/*package whatever //do not write package name here */ import java.io.*; import java.util.*; public class GFG { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ String A=sc.next(); char ch[]=A.toCharArray(); int i,one=-1,count0=0; boolean flag=false; for(i=0;i<ch.length;i++){ if(ch[i]=='1'){ if(flag){ flag=false; } one=i; flag=true; } else{ if(flag){ count0++; } }} if(one>=0) System.out.println(count0-(ch.length-one-1)); else System.out.println(0); } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
5ceb3301f034cfb011e482c81d0f5d63
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.io.*; import java.util.*; public class Erasing_Zeroes { 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()); } 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) { String s = sc.nextLine(); int l = 0, r = s.length() ; while (l < s.length() && s.charAt(l) == '0') { ++l; } while (r > l && s.charAt(r-1) == '0') { --r; } int c = 0; int i = l; while(i<r) { if(s.charAt(i) == '1') { c++; } i++; } int ans = r - l - c; if(ans > 0) { System.out.println(ans); }if(ans <= 0) { System.out.println("0"); } } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
002d0de6030ff9081e78f19fd1b10196
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.*; public class Solution { public static void main(String args[]) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String t; for(int i = 0; i < n; i++) { t = in.next(); int check1 = -1; int check2 = -1; for(int j = 0; j < t.length(); j++) { if(Character.toString(t.charAt(j)).equals("1")) { if(check1 == -1) { check1 = j; } } } for(int j = t.length() - 1; j >=0; j--) { if(Character.toString(t.charAt(j)).equals("1")) { if(check2 == -1) { check2 = j; } } } if(t.length() > 2 && check1 != check2) { String h = t.substring(check1, check2+1); int res = 0; for(int j = 0; j < h.length(); j++) { if(Character.toString(h.charAt(j)).equals("0")) { res++; } } System.out.println(res); } else {System.out.println(0);} } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
a1bb7c55894c8a0fdf01c89e5af48739
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class codeforces { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i = 0 ; i <n ;i++) { int count = 0; String s = sc.next(); for(int j = s.indexOf('1'); j < s.lastIndexOf('1'); j++) { if(s.charAt(j) == '0') { count++; } } System.out.println(count); } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
57515162d0aeb46575eea31952473030
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.*; public class PhoenixA { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { String s=sc.next(); int flag=0; int l=0; int cou=0; int start=0; for(int j=0;j<s.length();j++) { if(s.charAt(j)=='1' && flag==0) { start=j; flag=1; continue; } else if(s.charAt(j)=='1' && flag==1) { start=j; continue; } else if(s.charAt(j)=='0' && flag==0) { continue; } else { cou++; if(j==s.length()-1 && flag==1) { cou=cou-(j-start); } } } System.out.println(cou); } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
ffbce9dff9e1cf23e341af7f2a72ced5
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
//package com.company; import java.io.*; import java.util.*; public class ErasingZeroes { public static void main(String[] args) { out = new PrintWriter(new BufferedOutputStream(System.out)); MyScanner sc = new MyScanner();//start int size = sc.nextInt(); for (int i = 0; i < size; i++) { int zero = 0,low=-1,high=-1; String str = sc.nextLine(); for (int n = 0; n < str.length(); n++) {//0 is must or it will not get the first 1 if(str.charAt(n)=='1') { low = n;break; }//we got the low now look for 0 } for (int k = str.length()-1; k > 0; k--) {//last one zero or 1 doesnt matter if(str.charAt(k)=='1'){ high = k;break; }//make a container }//container done now hunt for 0 if(low!=-1 && high!=-1)//shit moved hunt beguns for (int z = low; z <= high; z++) { if(str.charAt(z)=='0'){zero++;}//take all zeros } out.println(zero); } 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
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
a1f1a89b5952d80855e4bebb9e53f527
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.*; public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int i = 0; i < t; i++) { String s = in.next(); int start = 0; int end = 0; int count = 0; if (s.length() < 3) { System.out.println("0"); continue; } for (int j = 0; j < s.length(); j++) { if (s.charAt(j) == '1') { start = j; break; } } for (int z = s.length() - 1; z > -1; z--) { if (s.charAt(z) == '1') { end = z; break; } } if (end == 0 && start == end) { System.out.println("0"); continue; } for (int j = start; j <= end; j++) { if (s.charAt(j) == '0') { count++; } } System.out.println(count); } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
47d1f9a19ee78f59c5003d7e041ce65d
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Solution{ public static void main(String []args) throws IOException{ BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(in.readLine()); while(t-->0) { String s=in.readLine(); int start=0,end=0,count=0; for(int i=0;i<s.length();i++) { if(s.charAt(i)=='1') { start=i; break; } } for(int i=s.length()-1;i>=0;i--) { if(s.charAt(i)=='1') { end=i; break; } } if(start<end) { for(int i=start;i<=end;i++) { if(s.charAt(i)=='0') count++; } } System.out.println(count); } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
000254e0f64e3fffe312fe8961e3b9cc
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; public class ErasingZeroes { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int amountOfTestCases = Integer.parseInt(reader.readLine()); for (int i = 0; i < amountOfTestCases; i++) { System.out.println(amountOfNonLeadingTrailingZeroes(reader.readLine())); } } static long amountOfNonLeadingTrailingZeroes(String input) { var firstIndex = input.indexOf('1'); var lastIndex = input.lastIndexOf('1'); if (firstIndex == -1 || lastIndex == -1) { return 0; } return input.substring(firstIndex, lastIndex).chars().filter(c -> c == '0').count(); } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
567250ecc616fcd9dea534d82b07ce26
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; public class ErasingZeroes { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int amountOfTestCases = Integer.parseInt(reader.readLine()); for (int i = 0; i < amountOfTestCases; i++) { System.out.println(amountOfNonLeadingTrailingZeroes(reader.readLine())); } } static long amountOfNonLeadingTrailingZeroes(String input) { int firstIndex = input.indexOf('1'); int lastIndex = input.lastIndexOf('1'); if (firstIndex == -1 || lastIndex == -1) { return 0; } return input.substring(firstIndex, lastIndex).chars().filter(c -> c == '0').count(); } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
2ae9e83609740a6554c97b14d8bbe59a
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.*; import java.io.*; public class A { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); while(t-->0) { String s = br.readLine(); int c=0,fi =s.length(),li=s.length()-1; for(int i=0;i<s.length();i++) { if(s.charAt(i)=='1') { fi=i; break; } } for(int i=s.length()-1;i>=0;i--) if(s.charAt(i)=='1') { li=i; break; } for(int i=fi;i<=li;i++) if(s.charAt(i)=='0')c++; pw.println(c); } pw.flush(); } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
2d7d37d7543b050ae3c9b47179ce2eee
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.io.*; import java.util.*; public class ErasingZeroes { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { String s=sc.next(); int prev=-1,sum=0; for(int i=0;i<s.length();i++) { if(s.charAt(i)=='1') { if(prev==-1) prev=i; else { sum=sum+(i-prev-1); prev=i; } } } System.out.println(sum); } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
0f49dd48783a943e889ddceff7229353
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.Scanner; public class CF1303AImproved { public static void main(String[] args) { Scanner s = new Scanner(System.in); int cases = Integer.parseInt(s.nextLine()); for (int c = 0; c < cases; c++) { String input = s.nextLine().trim(); System.out.println(numToErase(input)); } } public static int numToErase(String input) { int firstOneIdx = -1; int lastOneIdx = -1; int idx = 0; while (idx < input.length()) { if (input.charAt(idx) == '1') { firstOneIdx = idx; break; } idx++; } idx = input.length() - 1; while (idx >= 0) { if (input.charAt(idx) == '1') { lastOneIdx = idx; break; } idx--; } int count = 0; for (int i = (firstOneIdx + 1); i < lastOneIdx; i++) { if (input.charAt(i) == '0') { count++; } } return count; } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
5724bb59fc38fa709e37f86f30bba194
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.Scanner; public class CF1303A { public static void main(String[] args) { Scanner s = new Scanner(System.in); int numCases = Integer.parseInt(s.nextLine()); for (int c = 0; c < numCases; c++) { String input = s.nextLine().trim(); System.out.println(numZerosToErase(input)); } } private static int numZerosToErase(String input) { int numZerosToErase = 0; int idx = 0; while (idx < input.length() && input.charAt(idx) == '0') { idx++; } while (idx < input.length() && input.charAt(idx) == '1') { idx++; } // Reset back at the last 1 idx = idx - 1; while(true) { int nextOneIdx = nextOneIdx(input, idx); if (nextOneIdx == -1) { break; } numZerosToErase = numZerosToErase + (nextOneIdx - idx - 1); idx = nextOneIdx; } return numZerosToErase; } private static int nextOneIdx(String input, int startingPos) { int nextOneIdx = -1; int cur = startingPos + 1; while (cur < input.length()) { if (input.charAt(cur) == '1') { return cur; } else { cur++; } } return nextOneIdx; } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
9cfec75853f0beb3a538efa5cd86927d
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.*; public class a{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- >0){ int count = 0; String s = sc.next(); int first = Integer.MAX_VALUE; int last = 0; for(int i=0;i<s.length();i++){ if(s.charAt(i) == '1'){ if(i < first){ first = i; } last = i; } } /*for(int i=first;i<s.length();i++){ if(s.charAt(i) == '1'){ last = i; } }*/ //System.out.print(first+" "+last); for(int i=first;i<=last;i++){ if(s.charAt(i) == '0'){ count += 1; } } System.out.println(count); } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
f3720ccaf3e6ab2931b8f2bbf155b813
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.*; public class a{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- >0){ int count = 0; String s = sc.next(); int first = Integer.MAX_VALUE; int last = 0; for(int i=0;i<s.length();i++){ if(s.charAt(i) == '1'){ if(i < first){ first = i; } } } for(int i=first;i<s.length();i++){ if(s.charAt(i) == '1'){ last = i; } } //System.out.print(first+" "+last); for(int i=first;i<=last;i++){ if(s.charAt(i) == '0'){ count += 1; } } System.out.println(count); } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
6d867ea34e4214c53cc1571bc953c827
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.*; public class ErasingZeroes { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int q=10,count=0,Ocount=0; for(int i=0;i<n;i++) { String s=sc.next(); String r[]=s.split(""); for(int j=0;j<r.length;j++) { if(r[j].equals("1")) { for(int k=j+1;k<r.length;k++) { if(r[k].equals("0")) { for(int l=k+1;l<r.length;l++) { if(r[l].equals("1")) { Ocount++; } } if(Ocount>=1) { if(r[k].equals("0")) { count++; } } } else if(r[k].equals("1")) { break; } else if(k==r.length){ count=0; } q++; } } Ocount=0; } System.out.println(count); count=0; Ocount=0; } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
afb2422026d096ffc236890bc80225a5
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) { FastReader f = new FastReader(); int t = f.nextInt(); while (t-- > 0) { String s = f.next(); int first = 0; int cnt1 = 0; int last = 0; for(int i=0;i<s.length();i++) { if(s.charAt(i) == '1') { first = i; i++; last = i; cnt1++; for(;i<s.length();i++) { if(s.charAt(i) == '1') { cnt1++; last = Math.max(last, i); } } break; } } if(cnt1 < 2) { System.out.println(0); } else { System.out.println(last-first-cnt1+1); } } } //fast input reader 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
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
71828683b709ca2eab1ab99850a0c40d
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.Scanner; public class Erasing_Zeros { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String test = scanner.nextLine(); int t = Integer.parseInt(test); for (int i = 1; i <= t; i++) { String x = scanner.nextLine(); int start = 0, end = 0, result = 0; for (int j = 0; j< x.length(); j++) { if (x.charAt(j) == '1') {start = j; break;} } for (int j = x.length() - 1; j >= 0; j--) { if (x.charAt(j) == '1') {end = j; break;} } if (start == end) System.out.println(0); else { for (int j = start; j <= end; j++) if (x.charAt(j) == '0') result++; System.out.println(result); } } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
8062c5b214b3a07dbd3f581eeccd09e2
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.Scanner; public class erasing { public static void main(String args[]) { Scanner s=new Scanner(System.in); int test_size=s.nextInt(); for(int i=0;i<test_size;i++) { String temp=s.next(); erasing.solver(temp); } } private static void solver(String str) { int length_str=str.length(); Long count=0l; int pointer1=0; int pointer2=length_str-1; while(true) { if(str.charAt(pointer1)=='1' | pointer1==length_str-1) break; pointer1++; } while(true) { if(str.charAt(pointer2)=='1' | pointer2==0) break; pointer2--; } if(pointer1<pointer2) for(int i=pointer1;i<=pointer2;i++) { if(str.charAt(i)=='0') count++; } System.out.println(count); } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
c368947f1a76a2131add1ff038fb4ff0
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int testCase = scanner.nextInt(); scanner.nextLine(); while(testCase > 0) { String string = scanner.nextLine(); int len = 0; int firstI = 0; for(int i = 0; i < string.length(); i++) { if(string.charAt(i) == '1') { firstI = i; break; } } for(int i = 0; i < string.length(); i++) { if(string.charAt(i) == '1') { len = i; } } int counter = 0; for(int i = firstI; i < len; i++) { if(string.charAt(i) == '0') { counter++; } } System.out.println(counter); testCase--; } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
b4a332c095336c575e17ac42e75e5d3a
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.util.Scanner; public class ErasingZeros { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int tc = Integer.parseInt(scanner.nextLine()); while (tc-- > 0) { String input = scanner.nextLine(); System.out.println(findMinZeros(input)); } scanner.close(); } public static int findMinZeros(String s) { String ss = ""; int startIndex = -1, endIndex = -1; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == '1') { startIndex = i; break; } } for (int i = s.length() - 1; i >= 0; i--) { if (s.charAt(i) == '1') { endIndex = i; break; } } if (startIndex == endIndex) { return 0; } if (startIndex == -1 && endIndex == -1) { return 0; } ss = s.substring(startIndex, endIndex); int count = 0; for (int i = 0; i < ss.length(); i++) { if (ss.charAt(i) == '0') { count++; } } return count; } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
c3a86b942de2d90b88583a4668fab901
train_003.jsonl
1581518100
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
256 megabytes
import java.lang.*; import java.io.*; import java.util.*; public class Code{ public static void main(String args[]){ Scanner br=new Scanner(System.in); int t=br.nextInt(); while(t-->0){ String s=br.next(); int c=0; int k=0; int m=0; for(int i=0;i<s.length();i++){ if(s.charAt(i)=='1'){ k=i; break; } } for(int j=s.length()-1;j>=0;j--){ if(s.charAt(j)=='1'){ m=j; break; } } for(int h=k+1;h<m;h++){ if(s.charAt(h)=='0') c++; } System.out.println(c); } } }
Java
["3\n010011\n0\n1111000"]
1 second
["2\n0\n0"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
Java 11
standard input
[ "implementation", "strings" ]
5de66fbb594bb317654366fd2290c4d3
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
800
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
standard output
PASSED
95dfb0413090aa784b17f62d70283949
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.*; @SuppressWarnings("unchecked") public class P659B { public void run() throws Exception { int n = nextInt(); int m = nextInt(); TreeMap<Integer, List<String>> [] rof = new TreeMap [m]; while ((n--) > 0) { String f = next(); int r = nextInt() - 1; int o = nextInt(); TreeMap<Integer, List<String>> of = (rof[r] != null) ? rof[r] : new TreeMap(Comparator.reverseOrder()); List<String> fs = of.getOrDefault(o, new ArrayList()); fs.add(f); of.put(o, fs); if (of.size() > 2) { of.pollLastEntry(); } rof[r] = of; } for (int i = 0; i < m; i++) { List<String> f1 = rof[i].firstEntry().getValue(); if (f1.size() > 2) { println("?"); } else if (f1.size() == 2) { println(f1.get(0) + " " + f1.get(1)); } else { List<String> f2 = rof[i].lastEntry().getValue(); println((f2.size() > 1) ? "?" : (f1.get(0) + " " + f2.get(0))); } } } public static void main(String... args) throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedOutputStream(System.out)); new P659B().run(); br.close(); pw.close(); System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]"); } static long startTime = System.currentTimeMillis(); static BufferedReader br; static PrintWriter pw; StringTokenizer stok; String nextToken() throws IOException { while (stok == null || !stok.hasMoreTokens()) { String s = br.readLine(); if (s == null) { return null; } stok = new StringTokenizer(s); } return stok.nextToken(); } void print(byte b) { print("" + b); } void print(int i) { print("" + i); } void print(long l) { print("" + l); } void print(double d) { print("" + d); } void print(char c) { print("" + c); } void print(Object o) { if (o instanceof int[]) { print(Arrays.toString((int [])o)); } else if (o instanceof long[]) { print(Arrays.toString((long [])o)); } else if (o instanceof char[]) { print(Arrays.toString((char [])o)); } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o)); } else if (o instanceof short[]) { print(Arrays.toString((short [])o)); } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o)); } else if (o instanceof float[]) { print(Arrays.toString((float [])o)); } else if (o instanceof double[]) { print(Arrays.toString((double [])o)); } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o)); } else { print("" + o); } } void print(String s) { pw.print(s); } void println() { println(""); } void println(byte b) { println("" + b); } void println(int i) { println("" + i); } void println(long l) { println("" + l); } void println(double d) { println("" + d); } void println(char c) { println("" + c); } void println(Object o) { print(o); println(); } void println(String s) { pw.println(s); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } char nextChar() throws IOException { return (char) (br.read()); } String next() throws IOException { return nextToken(); } String nextLine() throws IOException { return br.readLine(); } int [] readInt(int size) throws IOException { int [] array = new int [size]; for (int i = 0; i < size; i++) { array[i] = nextInt(); } return array; } long [] readLong(int size) throws IOException { long [] array = new long [size]; for (int i = 0; i < size; i++) { array[i] = nextLong(); } return array; } double [] readDouble(int size) throws IOException { double [] array = new double [size]; for (int i = 0; i < size; i++) { array[i] = nextDouble(); } return array; } String [] readLines(int size) throws IOException { String [] array = new String [size]; for (int i = 0; i < size; i++) { array[i] = nextLine(); } return array; } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
ef157456279d9fe5174b4b5bd11041ee
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.*; @SuppressWarnings("unchecked") public class P659B { public void run() throws Exception { int n = nextInt(); int m = nextInt(); TreeMap<Integer, TreeMap<Integer, ArrayList<String>>> rof = new TreeMap(); for (int i = 0; i < n; i++) { String f = next(); int r = nextInt(); int o = nextInt(); TreeMap<Integer, ArrayList<String>> of = rof.getOrDefault(r, new TreeMap()); ArrayList<String> fs = of.getOrDefault(o, new ArrayList()); fs.add(f); of.put(o, fs); rof.put(r, of); } for (Iterator<TreeMap<Integer, ArrayList<String>>> i = rof.values().iterator(); i.hasNext();) { TreeMap<Integer, ArrayList<String>> of = i.next(); ArrayList<String> fs = of.pollLastEntry().getValue(); if (fs.size() > 2) { println("?"); } else if (fs.size() == 2) { println(fs.get(0) + " " + fs.get(1)); } else { String fn = fs.get(0); fs = of.pollLastEntry().getValue(); println((fs.size() > 1) ? "?" : (fn + " " + fs.get(0))); } } } public static void main(String... args) throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedOutputStream(System.out)); new P659B().run(); br.close(); pw.close(); System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]"); } static long startTime = System.currentTimeMillis(); static BufferedReader br; static PrintWriter pw; StringTokenizer stok; String nextToken() throws IOException { while (stok == null || !stok.hasMoreTokens()) { String s = br.readLine(); if (s == null) { return null; } stok = new StringTokenizer(s); } return stok.nextToken(); } void print(byte b) { print("" + b); } void print(int i) { print("" + i); } void print(long l) { print("" + l); } void print(double d) { print("" + d); } void print(char c) { print("" + c); } void print(Object o) { if (o instanceof int[]) { print(Arrays.toString((int [])o)); } else if (o instanceof long[]) { print(Arrays.toString((long [])o)); } else if (o instanceof char[]) { print(Arrays.toString((char [])o)); } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o)); } else if (o instanceof short[]) { print(Arrays.toString((short [])o)); } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o)); } else if (o instanceof float[]) { print(Arrays.toString((float [])o)); } else if (o instanceof double[]) { print(Arrays.toString((double [])o)); } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o)); } else { print("" + o); } } void print(String s) { pw.print(s); } void println() { println(""); } void println(byte b) { println("" + b); } void println(int i) { println("" + i); } void println(long l) { println("" + l); } void println(double d) { println("" + d); } void println(char c) { println("" + c); } void println(Object o) { print(o); println(); } void println(String s) { pw.println(s); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } char nextChar() throws IOException { return (char) (br.read()); } String next() throws IOException { return nextToken(); } String nextLine() throws IOException { return br.readLine(); } int [] readInt(int size) throws IOException { int [] array = new int [size]; for (int i = 0; i < size; i++) { array[i] = nextInt(); } return array; } long [] readLong(int size) throws IOException { long [] array = new long [size]; for (int i = 0; i < size; i++) { array[i] = nextLong(); } return array; } double [] readDouble(int size) throws IOException { double [] array = new double [size]; for (int i = 0; i < size; i++) { array[i] = nextDouble(); } return array; } String [] readLines(int size) throws IOException { String [] array = new String [size]; for (int i = 0; i < size; i++) { array[i] = nextLine(); } return array; } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
847deebc2babd29d1018134ed2d48b89
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; import java.io.BufferedReader; import java.util.Collections; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Nasko */ 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int N = in.nextInt(); int M = in.nextInt(); ArrayList<TaskB.Pair>[] p = new ArrayList[M]; for (int i = 0; i < M; ++i) p[i] = new ArrayList<TaskB.Pair>(); for (int i = 0; i < N; ++i) { StringTokenizer st = new StringTokenizer(in.nextLine()); String name = st.nextToken(); int teamId = Integer.parseInt(st.nextToken()); int pp = Integer.parseInt(st.nextToken()); p[teamId - 1].add(new TaskB.Pair(name, pp)); } for (int i = 0; i < M; ++i) Collections.sort(p[i]); for (int i = 0; i < M; ++i) { if (p[i].size() <= 2) { out.println(p[i].get(p[i].size() - 1).name + " " + p[i].get(p[i].size() - 2).name); } else { int firstPoint = p[i].get(p[i].size() - 2).points; int secondPoint = p[i].get(p[i].size() - 3).points; if (firstPoint == secondPoint) { out.println("?"); } else { out.println(p[i].get(p[i].size() - 1).name + " " + p[i].get(p[i].size() - 2).name); } } } } static class Pair implements Comparable<TaskB.Pair> { String name; int points; public Pair(String _name, int _points) { name = _name; points = _points; } public int compareTo(TaskB.Pair o) { return this.points - o.points; } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return null; } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
01e8105ce73ea4cec5a4bd4b4f42a819
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Objects; import javafx.util.Pair; public class B659 { static class Scanner { BufferedReader br; StringTokenizer tk=new StringTokenizer(""); public Scanner(InputStream is) { br=new BufferedReader(new InputStreamReader(is)); } public int nextInt() throws IOException { if(tk.hasMoreTokens()) return Integer.parseInt(tk.nextToken()); tk=new StringTokenizer(br.readLine()); return nextInt(); } public long nextLong() throws IOException { if(tk.hasMoreTokens()) return Long.parseLong(tk.nextToken()); tk=new StringTokenizer(br.readLine()); return nextLong(); } public String next() throws IOException { if(tk.hasMoreTokens()) return (tk.nextToken()); tk=new StringTokenizer(br.readLine()); return next(); } public String nextLine() throws IOException { tk=new StringTokenizer(""); return br.readLine(); } public double nextDouble() throws IOException { if(tk.hasMoreTokens()) return Double.parseDouble(tk.nextToken()); tk=new StringTokenizer(br.readLine()); return nextDouble(); } public char nextChar() throws IOException { if(tk.hasMoreTokens()) return (tk.nextToken().charAt(0)); tk=new StringTokenizer(br.readLine()); return nextChar(); } public int[] nextIntArray(int n) throws IOException { int a[]=new int[n]; for(int i=0;i<n;i++) a[i]=nextInt(); return a; } public long[] nextLongArray(int n) throws IOException { long a[]=new long[n]; for(int i=0;i<n;i++) a[i]=nextLong(); return a; } public int[] nextIntArrayOneBased(int n) throws IOException { int a[]=new int[n+1]; for(int i=1;i<=n;i++) a[i]=nextInt(); return a; } public long[] nextLongArrayOneBased(int n) throws IOException { long a[]=new long[n+1]; for(int i=1;i<=n;i++) a[i]=nextLong(); return a; } } public static void main(String args[]) throws IOException { Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int n=in.nextInt(); int m=in.nextInt(); ArrayList<Pair<String,Integer>> g[]=new ArrayList[m+1]; for(int i=1;i<=m;i++) g[i]=new ArrayList<>(); for(int i=0;i<n;i++) { String s=in.next(); int u=in.nextInt(); int v=in.nextInt(); g[u].add(new Pair(s,v)); } for(int i=1;i<=m;i++) { Collections.sort(g[i],(a,b)->Integer.compare(b.getValue(), a.getValue())); if(g[i].size()>2&&Objects.equals(g[i].get(1).getValue(), g[i].get(2).getValue())) { out.println("?"); } else out.println(g[i].get(0).getKey()+" "+g[i].get(1).getKey()); } out.close(); } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
90f0b5121fdde342a58b7fbeb81d95d3
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; /** * Created by Shurikat on 09.07.16. */ public class Codeforces { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(); int n = scanner.nextInt(), m = scanner.nextInt(); ArrayList<ArrayList<Person>> persons = new ArrayList<>(m); for (int i = 0; i < m; ++i) persons.add(new ArrayList<>()); for (int i = 0; i < n; ++i) { String name = scanner.nextString(); int reg = scanner.nextInt() - 1; int rate = scanner.nextInt(); persons.get(reg).add(new Person(name, rate)); } for (int i = 0; i < m; ++i) { persons.get(i).sort((p1, p2) -> p2.rate - p1.rate); } for (int i = 0; i < m; ++i) { ArrayList<Person> cur = persons.get(i); if (cur.size() >= 3 && cur.get(1).rate == cur.get(2).rate) System.out.println("?"); else System.out.println(cur.get(0).name + " " + cur.get(1).name); } } static class Person { public String name; public int rate; public Person(String name, int rate) { this.name = name; this.rate = rate; } } } class Scanner { final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; private boolean update() throws Exception { if (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); return true; } else return false; } public int nextInt() throws Exception { update(); return Integer.parseInt(st.nextToken()); } public String nextString() throws Exception { update(); return st.nextToken(); } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
33239914221a1e5cba791bf4f24f1212
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.util.*; public class XKSegments { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int total_reg = s.nextInt(); List<Data> list = new ArrayList<>(); HashMap<Integer, Integer> h = new HashMap<>(); for(int i=0; i<n; i++) { String name = s.next(); int reg = s.nextInt(); int pnt = s.nextInt(); list.add(new Data(name, reg, pnt)); if(h.containsKey(reg)) { int value = h.get(reg); h.put(reg, value+1); } else { h.put(reg,1); } } //System.out.println(list); //System.out.println("Hashmaap" + h); Collections.sort(list, new Mycomparator2()); //System.out.println("after sorting" +list); for(int i=0; i<n; ) { int x = (list.get(i)).region; int freq = h.get(x); if(freq ==2) { System.out.println((list.get(i+1)).name +" " + (list.get(i)).name ); i+=2; } else { int a = (list.get(i+freq-1)).point; int b = (list.get(i+freq-2)).point; int c = (list.get(i+freq-3)).point; if(b ==c) { System.out.println("?"); } else { System.out.println((list.get(i+freq-1)).name +" " + (list.get(i+freq-2)).name ); } i += (freq); } } } } class Mycomparator2 implements Comparator<Data> { public int compare(Data d1, Data d2) { if(d1.region != d2.region) { return d1.region - d2.region; } else{ return d1.point - d2.point; } } } class Data { String name; int region; int point; Data(String name, int region, int point) { this.name = name; this.region = region; this.point = point; } public String toString() { return this.name + " " + this.region + " " + this.point; } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
cff8234e602cf24c0aeca2273be539ad
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.*; import java.util.*; public class QualifyingContest{ public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] tmp = br.readLine().split(" "); int n = Integer.parseInt(tmp[0]); int m = Integer.parseInt(tmp[1]); String[][] std = new String[n][3]; for(int i=0; i<n; i++){ std[i]=br.readLine().split(" "); } Arrays.sort(std,new Comparator<String[]>(){ public int compare(String[] s1, String[] s2) { if (Integer.parseInt(s1[1]) > Integer.parseInt(s2[1])) return 1; // tells Arrays.sort() that s1 comes after s2 else if (Integer.parseInt(s1[1]) < Integer.parseInt(s2[1])) return -1; // tells Arrays.sort() that s1 comes before s2 else { if (Integer.parseInt(s1[2]) > Integer.parseInt(s2[2])) return -1; else if(Integer.parseInt(s1[2]) < Integer.parseInt(s2[2])) return 1; else return 0; } } }); /* for(int i=0; i<n; i++){ System.out.println(Arrays.toString(std[i])); }*/ String[] res = new String[m]; for(int i=0; i<n-1; i++){ if(i==0 || !std[i][1].equals(std[i-1][1])){ if(i!=(n-2) && std[i+1][1].equals(std[i+2][1]) && std[i+1][2].equals(std[i+2][2])) res[Integer.parseInt(std[i][1])-1]="?"; else{ res[Integer.parseInt(std[i][1])-1]=std[i][0]+" "+std[i+1][0]; } } } for(int i=0; i<m; i++){ System.out.println(res[i]); } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
c4f6646f4ab12cf085d227e189431a89
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.*; import java.util.*; public class QualifyingContest{ public static void main(String[] args){ Scanner scn = new Scanner(System.in); int n=scn.nextInt(); int m=scn.nextInt(); String[][] std = new String[n][3]; scn.nextLine(); for(int i=0; i<n; i++){ std[i]=scn.nextLine().split(" "); } Arrays.sort(std,new Comparator<String[]>(){ public int compare(String[] s1, String[] s2) { if (Integer.parseInt(s1[1]) > Integer.parseInt(s2[1])) return 1; // tells Arrays.sort() that s1 comes after s2 else if (Integer.parseInt(s1[1]) < Integer.parseInt(s2[1])) return -1; // tells Arrays.sort() that s1 comes before s2 else { if (Integer.parseInt(s1[2]) > Integer.parseInt(s2[2])) return -1; else if(Integer.parseInt(s1[2]) < Integer.parseInt(s2[2])) return 1; else return 0; } } }); /* for(int i=0; i<n; i++){ System.out.println(Arrays.toString(std[i])); }*/ String[] res = new String[m]; for(int i=0; i<n-1; i++){ if(i==0 || !std[i][1].equals(std[i-1][1])){ if(i!=(n-2) && std[i+1][1].equals(std[i+2][1]) && std[i+1][2].equals(std[i+2][2])) res[Integer.parseInt(std[i][1])-1]="?"; else{ res[Integer.parseInt(std[i][1])-1]=std[i][0]+" "+std[i+1][0]; } } } for(int i=0; i<m; i++){ System.out.println(res[i]); } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
2fc62b8ee5427174aa9cbf9f088a0d53
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.*; import java.util.*; public class QualifyingContest{ public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] tmp = br.readLine().split(" "); int n = Integer.parseInt(tmp[0]); int m = Integer.parseInt(tmp[1]); String[][] std = new String[n][3]; //scn.nextLine(); for(int i=0; i<n; i++){ std[i]=br.readLine().split(" "); } Arrays.sort(std,new Comparator<String[]>(){ public int compare(String[] s1, String[] s2) { if (Integer.parseInt(s1[1]) > Integer.parseInt(s2[1])) return 1; // tells Arrays.sort() that s1 comes after s2 else if (Integer.parseInt(s1[1]) < Integer.parseInt(s2[1])) return -1; // tells Arrays.sort() that s1 comes before s2 else { if (Integer.parseInt(s1[2]) > Integer.parseInt(s2[2])) return -1; else if(Integer.parseInt(s1[2]) < Integer.parseInt(s2[2])) return 1; else return 0; } } }); /* for(int i=0; i<n; i++){ System.out.println(Arrays.toString(std[i])); }*/ //String[] res = new String[m]; BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); for(int i=0; i<n-1; i++){ if(i==0 || !std[i][1].equals(std[i-1][1])){ if(i!=(n-2) && std[i+1][1].equals(std[i+2][1]) && std[i+1][2].equals(std[i+2][2])){ //res[Integer.parseInt(std[i][1])-1]="?"; out.write("?\n"); }else{ //res[Integer.parseInt(std[i][1])-1]=std[i][0]+" "+std[i+1][0]; out.write(std[i][0]+" "+std[i+1][0]+"\n"); } } } out.flush(); } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
ed7248e90b994dee4857ed6db4c884a9
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; import java.io.BufferedReader; import java.util.Comparator; import java.util.Collections; import java.io.InputStream; /** * Built using CHelper plug-in Actual solution is at the top * * @author MottoX */ 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); ArrayList<Person>[] region = new ArrayList[m]; for (int i = 0; i < region.length; i++) { region[i] = new ArrayList<>(); } for (int i = 0; i < n; i++) { String name = in.next(); int num = in.nextInt() - 1; int score = in.nextInt(); region[num].add(new Person(name, score)); } for (ArrayList<Person> reg : region) { Collections.sort(reg, new Comparator<Person>() { public int compare(Person o1, Person o2) { if (o1.score > o2.score) { return -1; } else if (o1.score == o2.score) { return 0; } else return 1; } }); if (reg.size() > 3) { reg.remove(3); } } for (int i = 0; i < region.length; i++) { ArrayList<Person> reg = region[i]; if (reg.size() == 2) { out.println(reg.get(0).name + " " + reg.get(1).name); } else if (reg.get(1).score != reg.get(2).score) { out.println(reg.get(0).name + " " + reg.get(1).name); } else out.println("?"); } } } static class Person { String name; int score; public Person(String name, int score) { this.name = name; this.score = score; } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
0f2f5714bb2848a9d12dddbd955e3682
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.util.*; public class A { static class Cons implements Comparator<Cons>, Comparable<Cons> { private String name; private int points; Cons() { } Cons(String n, int a) { name = n; points = a; } public int compareTo(Cons d) { return (this.name).compareTo(d.name); } public int compare(Cons fir, Cons sec) { return sec.points - fir.points; } } public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = Integer.parseInt(s.next()); int regions = Integer.parseInt(s.next()); TreeMap<Integer, ArrayList<Cons>> hm = new TreeMap<Integer, ArrayList<Cons>>(); for (int i = 0; i < n; i++) { String name = s.next(); int region = Integer.parseInt(s.next()); int points = Integer.parseInt(s.next()); if (hm.containsKey(region)) { hm.get(region).add(new Cons(name, points)); } else { ArrayList<Cons> ls = new ArrayList<Cons>(); ls.add(new Cons(name, points)); hm.put(region, ls); } } for (Integer myInt : hm.keySet()) { Collections.sort(hm.get(myInt), new Cons()); ArrayList<Cons> myls = hm.get(myInt); String fir = "?"; String sec = ""; String str = fir + sec; if (myls.size() > 2 && (myls.get(1).points == myls.get(2).points)) { } else { fir = myls.get(0).name; sec = myls.get(1).name; str = fir + " " + sec; } System.out.println(str); } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
e344b8c5534b78879d8b7d61befcc798
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; public class Shit { static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) {br = new BufferedReader(new InputStreamReader(system));} public Scanner(String file) throws Exception {br = new BufferedReader(new FileReader(file));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine()throws IOException{return br.readLine();} public int nextInt() throws IOException {return Integer.parseInt(next());} public double nextDouble() throws IOException {return Double.parseDouble(next());} public char nextChar()throws IOException{return next().charAt(0);} public Long nextLong()throws IOException{return Long.parseLong(next());} public boolean ready() throws IOException{return br.ready();} public void waitForInput() throws InterruptedException {Thread.sleep(3000);} } public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int n = sc.nextInt(); int m = sc.nextInt(); ArrayList<Integer>[] num = new ArrayList[m+1]; ArrayList<String>[] str = new ArrayList[m+1]; int[] arr = new int[m+1]; for(int i=0 ; i<n ; i++) { String a = sc.next(); int b = sc.nextInt(); int c = sc.nextInt(); if (num[b]==null) { num[b] = new ArrayList<Integer>(); str[b] = new ArrayList<String>(); } num[b].add(c); str[b].add(a); arr[b]++; } for(int i=1 ; i<m+1 ;i++) { int[] maxarr =new int[3]; String[] ans = new String[3]; int var=0; while(var!=3 && !num[i].isEmpty()) { int max=0; int index=0; for(int k=0 ; k<arr[i]-var ; k++) { if(num[i].get(k)>max) {max=num[i].get(k);index=k;} } num[i].remove(index); maxarr[var]=max; ans[var]=str[i].get(index); str[i].remove(index); var++; } if(maxarr[1]==maxarr[2] && maxarr[2]!=0 )out.println("?"); else out.println(ans[0]+" "+ans[1]); } out.flush(); } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
83ee94f3b5f194f78b07c6bd70e69b23
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; public class Shit { static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) {br = new BufferedReader(new InputStreamReader(system));} public Scanner(String file) throws Exception {br = new BufferedReader(new FileReader(file));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine()throws IOException{return br.readLine();} public int nextInt() throws IOException {return Integer.parseInt(next());} public double nextDouble() throws IOException {return Double.parseDouble(next());} public char nextChar()throws IOException{return next().charAt(0);} public Long nextLong()throws IOException{return Long.parseLong(next());} public boolean ready() throws IOException{return br.ready();} public void waitForInput() throws InterruptedException {Thread.sleep(3000);} } public static void main(String[] args)throws Exception { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int n = sc.nextInt(); int m = sc.nextInt(); ArrayList<Integer>[] num = new ArrayList[m+1]; ArrayList<String>[] str = new ArrayList[m+1]; int[] arr = new int[m+1]; for(int i=0 ; i<n ; i++) { String a = sc.next(); int b = sc.nextInt(); int c = sc.nextInt(); if (num[b]==null) { num[b] = new ArrayList<Integer>(); str[b] = new ArrayList<String>(); } num[b].add(c); str[b].add(a); arr[b]++; } // for(int i=1 ; i<m+1 ;i++) { int[] maxarr =new int[3]; String[] ans = new String[3]; int var=0; while(var!=3 && !num[i].isEmpty()) { int max=0; int index=0; for(int k=0 ; k<arr[i]-var ; k++) { if(num[i].get(k)>max) {max=num[i].get(k);index=k;} } num[i].remove(index); maxarr[var]=max; ans[var]=str[i].get(index); str[i].remove(index); var++; } if(maxarr[1]==maxarr[2] && maxarr[2]!=0 )out.println("?"); else out.println(ans[0]+" "+ans[1]); } out.flush(); } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
4fad52b955b06ca5b554a9af94beb14b
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.util.*; import java.io.*; public class Contest { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); P arr[]=new P[n]; for(int i=0;i<n;i++) { String s=sc.next(); int v=sc.nextInt(); int score1=sc.nextInt(); arr[i]=new P(s,v,score1); } Arrays.sort(arr,new Sort1()); Arrays.sort(arr,new Abb()); // for(int i=0;i<n;i++) // { // System.out.println(arr[i].name+" "+arr[i].num+" "+arr[i].score); // } String ans[]=new String[2]; int p=0; for(int i=0;i<n-1;i++) { if(p==0) { ans[p++]=arr[i].name; } else { if(arr[i].num!=arr[i+1].num) { ans[p++]=arr[i].name; System.out.println(ans[0]+" "+ans[1]); p=0; } else { if(arr[i].score==arr[i+1].score) { System.out.println("?"); int q=arr[i].num; while(i<arr.length && arr[i].num==q) { i++; } i-=1; p=0; } else { ans[p]=arr[i].name; System.out.println(ans[0]+" "+ans[1]); p=0; int q=arr[i].num; while(i<arr.length && arr[i].num==q) { i++; } i-=1; } } } } if(p==1) System.out.println(ans[0]+" "+arr[n-1].name); } } class Abb implements Comparator<P> { public int compare(P a,P b) { return a.num-b.num; } } class Sort1 implements Comparator<P> { public int compare(P a,P b) { return b.score-a.score; } } class P { String name; int num; int score; public P(String name,int num,int score) { this.name=name; this.num=num; this.score=score; } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
9e8ad07131e30affe4b972be4d713a1d
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.util.*; public class QualifyingContest { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int m = scan.nextInt(); Triplet[] arr = new Triplet[n]; for(int i=0;i<n;i++){ Triplet t = new Triplet(); t.name = scan.next(); t.region = scan.nextInt(); t.marks = scan.nextInt(); arr[i] = t; } Arrays.sort(arr, new Compar()); Map<Integer, List<Triplet>> map = new HashMap<>(); for(int i=0;i<n;i++){ Triplet t = arr[i]; if(!map.containsKey(t.region)){ List<Triplet> list = new ArrayList<>(); list.add(t); map.put(t.region, list); }else{ List<Triplet> list = map.get(t.region); list.add(t); map.put(t.region, list); } } for(int i=1;i<=m;i++){ List<Triplet> list = map.get(i); if(list.size() == 2){ System.out.println(list.get(0).name + " " + list.get(1).name); }else{ if(list.get(1).marks == list.get(2).marks){ System.out.println("?"); }else{ System.out.println(list.get(0).name + " " + list.get(1).name); } } } } } class Triplet{ String name; int region; int marks; } class Compar implements Comparator<Triplet>{ @Override public int compare(Triplet t1, Triplet t2){ int result = 0; if(t1.region < t2.region){ result = -1; }else if(t1.region > t2.region){ result = 1; }else{ if(t1.marks > t2.marks){ result = -1; }else if(t1.marks < t2.marks){ result = 1; } } return result; } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
568afff59959ea7c7be964eed64aa5a5
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
/** * @author kunal05 */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.Arrays; public class B { public static void main(String[] args) { InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out); final long start = System.currentTimeMillis(); new Task1().solve(in, out); @SuppressWarnings("unused") final long duration = System.currentTimeMillis()-start; out.close(); } static class Member implements Comparable<Member> { Integer team, score; String name; public Member(String name, int team, int score){ this.name = name; this.team = team; this.score = score; } public int compareTo(Member x){ if (team>x.team) { return 1; } else if (team<x.team) { return -1; } else { return (x.score).compareTo(score); } } } static class Task1{ public void solve(InputReader in, PrintWriter out){ int n = in.nextInt(), m = in.nextInt(); Member[] a = new Member[n]; for(int i=0; i<n; i++){ a[i] = new Member(in.next(), in.nextInt(), in.nextInt()); } Arrays.sort(a); /*for(Member i: a){ out.println(i.name); } out.println();*/ String ans[] = new String[m]; int prev_team = 1, prev_score = a[0].score, count = 1; ans[prev_team-1] = a[prev_team-1].name+" "; for(int i=1; i<n; i++){ if(ans[a[i].team-1] == "?"){ continue; } if(prev_team == a[i].team) { if (count == 1) { count++; ans[a[i].team - 1] += a[i].name; prev_score = a[i].score; } else if (count == 2) { if (prev_score == a[i].score) { ans[a[i].team-1] = "?"; } } } else { count = 1; ans[a[i].team - 1] = a[i].name+" "; prev_team = a[i].team; prev_score = a[i].score; } } for(int i=0; i<m; i++){ out.println(ans[i]); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader() { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { String s=null; try{ s = reader.readLine(); } catch(IOException e){ throw new RuntimeException(e); } return s; } public String nextParagraph() { String line=null; String ans = ""; try{ while ((line = reader.readLine()) != null) { ans += line; } } catch(IOException e){ throw new RuntimeException(e); } return ans; } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
e350b184684cf467348753cbb6e02137
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { FastReader input = new FastReader(); int n = input.nextInt(); int m = input.nextInt(); StringBuilder out = new StringBuilder(); Map<Integer, ArrayList<Student>> teams = new HashMap<Integer, ArrayList<Student>>(); for (int i = 0; i < m; i++) { teams.put(i, new ArrayList<Student>()); } for (int i = 0; i < n; i++) { String name = input.next(); int re = input.nextInt() - 1; int sc = input.nextInt(); teams.get(re).add(new Student(name, sc, re)); } for (int i = 0; i < m; i++) { List<Student> reg = teams.get(i); Collections.sort(reg); if (reg.size() == 2) { out.append(reg.get(0).name).append(" ").append(reg.get(1).name).append('\n'); } else if (reg.get(1).score == reg.get(2).score) { out.append("?\n"); } else { out.append(reg.get(0).name).append(" ").append(reg.get(1).name).append('\n'); } } System.out.print(out.toString()); } } class Student implements Comparable<Student> { String name; int score; int region; public Student(String n, int s, int r) { name = n; score = s; region = r; } public int compareTo(Student t) { if (score < t.score) { return 1; } else if (score > t.score) { return -1; } else { if (region < t.region) { return 1; } else if (region > t.region) { return -1; } else { return 0; } } } } /* Fast Reader */ class FastReader { BufferedReader br; StringTokenizer st; FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } String nextLine() throws IOException { return br.readLine(); } int nextInt() throws IOException { return Integer.parseInt(next()); } boolean hasNext() throws IOException { String pp = br.readLine(); if (pp == null) { return false; } st = new StringTokenizer(pp); return true; } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
a6c7650b94bb7f1fdfcbf98a25c9d24f
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Writer; import java.io.OutputStreamWriter; 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); OutputWriter out = new OutputWriter(outputStream); BQualifyingContest solver = new BQualifyingContest(); solver.solve(1, in, out); out.close(); } static class BQualifyingContest { public void solve(int testNumber, InputReader sc, OutputWriter out) { int n = sc.nextInt(); int m = sc.nextInt(); BQualifyingContest.student ar[] = new BQualifyingContest.student[n]; for (int i = 0; i < n; i++) { String s = sc.nextString(); int mm = sc.nextInt(); int score = sc.nextInt(); ar[i] = new BQualifyingContest.student(s, mm, score); } Arrays.sort(ar); StringBuilder sb = new StringBuilder(); int c = 1; for (int i = 0; i < n; i++) { if (ar[i].m == c) { c++; if (i < n - 2 && ar[i + 1].m == ar[i + 2].m && ar[i + 1].score == ar[i + 2].score) sb.append("?"); else sb.append(ar[i].name + " " + ar[i + 1].name); sb.append("\n"); } } out.println(sb.toString()); } static class student implements Comparable<BQualifyingContest.student> { String name; int m; int score; public student(String n, int mm, int s) { name = n; m = mm; score = s; } public int compareTo(BQualifyingContest.student s) { if (m > s.m) return 1; else if (m < s.m) return -1; else if (score > s.score) return -1; else if (score < s.score) return 1; else return 0; } } } static 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 println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.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 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 String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
2c90720f089edfce5dcbd6c85ad626e1
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeMap; public class Main9 { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { class P { String name; int score; P(String name , int score) { this.name = name; this.score = score; } } public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); List<List<P>> rp = new ArrayList<>(m); for (int i = 0; i < m; i++) rp.add(new ArrayList<>()); for (int i = 0; i < n; i++) { String name = in.next(); int region = in.nextInt(); int score = in.nextInt(); List<P> par = rp.get(--region); par.add(new P(name, score)); } for (int i = 0; i < m; i++) { List<P> region = rp.get(i); Collections.sort(region, (x, y) -> (y.score - x.score)); if (region.size() > 2 && region.get(1).score == region.get(2).score) { out.println("?"); } else { out.println(region.get(0).name + " " + region.get(1).name); } } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
6ef9268dd727f9b9bd6262e78d075b1c
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeMap; 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); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { class P { String name; int score; P(String name , int score) { this.name = name; this.score = score; } } public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); Map<Integer, List<P>> mm = new TreeMap<>(); for (int i = 0; i < n; i++) { String name = in.next(); int region = in.nextInt(); int score = in.nextInt(); List<P> par = mm.get(region); if (par == null) { par = new ArrayList<>(); mm.put(region, par); } par.add(new P(name, score)); } for (Integer region : mm.keySet()) { List<P> par = mm.get(region); Collections.sort(par, new Comparator<P>() { @Override public int compare(P o1, P o2) { return o1.score - o2.score; } }); boolean can = true; if (par.size() > 2) { int ss = par.size(); if (par.get(ss - 2).score == par.get(ss - 3).score) can = false; } if (can) { for (int i = 0; i < 2; i++) { out.print(par.get(par.size() - 1 - i).name + (i == 0 ? " " : "")); } out.println(); } else { out.println("?"); } } } } static class E { int id; long like; E(int id, long like) { this.id = id; this.like = like; } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
832c8ebf8f44af4f64060ddbb92c02e8
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; //run time public class QualifyingContest659 { public static void main(String[] args) throws IOException{ BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); String a=r.readLine(); String[] info=a.split(" "); int numPeople=Integer.parseInt(info[0]); int regions=Integer.parseInt(info[1]); ArrayList<Person> s=new ArrayList<Person>(); for(int z=0; z<numPeople; z++){ a=r.readLine(); info=a.split(" "); String name=info[0]; int region=Integer.parseInt(info[1])-1; int score=Integer.parseInt(info[2]); Person p=new Person(name,region,score); s.add(p); } Collections.sort(s); int counter=0; int pos=0; while(pos<s.size() && counter<regions){ String pr=""; while(pos<s.size() && s.get(pos).region<counter) pos++; if(pos<s.size() && s.get(pos).region==counter){ pr=s.get(pos).name+" "+s.get(pos+1).name; if(pos+2<s.size() && s.get(pos+1).region==s.get(pos+2).region && s.get(pos+1).score==s.get(pos+2).score) pr="?"; } System.out.println(pr); counter++; } } } class Person implements Comparable{ String name; int region, score; public Person(String a, int b, int c){ name=a; region=b; score=c; } public int compareTo(Object o) { Person p=(Person)o; if(region<p.region) return -1; else if(region>p.region) return 1; else if(score>p.score) return -1; else if(score<p.score) return 1; return 0; } public String toString(){ return name+" "+score+" "+region; } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
dfd217373368d3a55a2c1f3419f14749
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class B { public static void main(String args[]) { try { InputReader in = new InputReader(System.in); int n = in.readInt(); int m = in.readInt(); Vector<Participant> res[] = new Vector[m]; for (int i = 0; i < m; i++) { res[i] = new Vector<Participant>(); } for (int i = 0; i < n; i++) { String par[] = (in.readLine()).split(" "); Participant p = new Participant(par[0], Integer.parseInt(par[1]), Integer.parseInt(par[2])); res[Integer.parseInt(par[1]) - 1].add(p); } for (int i = 0; i < m; i++) { Collections.sort(res[i]); } for (int i = 0; i < m; i++) { if (res[i].size() >= 3 && res[i].get(1).score == res[i].get(2).score) { System.out.println("?"); } else System.out.println(res[i].get(0).name + " " + res[i].get(1).name); } } catch (Exception e) { e.printStackTrace(); } } } class Participant implements Comparable<Participant>{ String name; int region; int score; public Participant(String n, int r, int s){ this.name = n; this.region = r; this.score = s; } public int compareTo(Participant that) { return - this.score + that.score; } } class InputReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; 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 peek() { if (numChars == -1) return -1; if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } 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 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 String readString() { int length = readInt(); if (length < 0) return null; byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) bytes[i] = (byte) read(); try { return new String(bytes, "UTF-8"); } catch (UnsupportedEncodingException e) { return new String(bytes); } } public static boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuffer buf = new StringBuffer(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') buf.appendCodePoint(c); c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) return readLine(); else return readLine0(); } public BigInteger readBigInteger() { try { return new BigInteger(readString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char readCharacter() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } 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 boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) read(); return value == -1; } public String next() { return readString(); } public boolean readBoolean() { return readInt() == 1; } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
de6c3d2ed626ac251445b99a9e6c8b31
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.*; import java.util.*; /* * CodeForces Round 346 Div 2 Qualifying Contest * @derrick20 */ public class QualifyingContest { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); ArrayList<Pair>[] scores = new ArrayList[M+1]; for (int i = 1; i <= M; i++) { scores[i] = new ArrayList<>(); } for (int i = 0; i < N; i++) { String name = sc.next(); int group = sc.nextInt(); int score = sc.nextInt(); scores[group].add(new Pair(name, score)); } for (int i = 1; i <= M; i++) { Collections.sort(scores[i], Comparator.reverseOrder()); if (scores[i].size() > 2 && scores[i].get(1).compareTo(scores[i].get(2)) == 0) { System.out.println("?"); } else { System.out.println(scores[i].get(0).name + " " + scores[i].get(1).name); } } /*ArrayList<String>[][] scores = new ArrayList[M+1][801]; for (int i = 1; i <= M; i++) { for (int j = 0; j <= 800; j++) { scores[i][j] = new ArrayList<>(); } } for (int i = 0; i < N; i++) { String name = sc.next(); int group = sc.nextInt(); int score = sc.nextInt(); scores[group][score].add(name); } for (int i = 1; i <= M; i++) { ArrayList<String> ans = new ArrayList<>(); for (int s = 800; s >= 0; s--) { int len = scores[i][s].size(); int myLen = ans.size(); if (len == 0) continue; else if (myLen == 0 && len == 2) { ans = scores[i][s]; System.out.println(ans.get(0) + " " + ans.get(1)); break; } else if (myLen == 0 && len == 1) { // get the 1st place ans.add(scores[i][s].get(0)); } else if (myLen == 1) { if (len == 1) { // found the second place, exit! ans.add(scores[i][s].get(0)); System.out.println(ans.get(0) + " " + ans.get(1)); break; } else if (len >= 2) { // it's a tie for 2nd place System.out.println("?"); break; } } else if (len >= 3) { // it's a tie for 1st place System.out.println("?"); break; } } } */ } static class Pair implements Comparable<Pair> { String name; int score; public Pair(String name, int score) { this.name = name; this.score = score; } public int compareTo(Pair p2) { return this.score - p2.score; } } static class Scanner { BufferedReader br; StringTokenizer st; Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } Scanner(FileReader s) { br = new BufferedReader(s); } 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
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
64b0146d782de5826de6efa95bc54d67
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.util.*; import java.io.*; /** * * @author umang */ public class B659 { public static int mod = 1000000007; public static long gcd(long x,long y){ if(x%y==0) return y; else return gcd(y,x%y); } public static int gcd(int x,int y){ if(x%y==0) return y; else return gcd(y,x%y); } public static int abs(int a,int b){ return (int)Math.abs(a-b); } public static long abs(long a,long b){ return (long)Math.abs(a-b); } public static int max(int a,int b){ if(a>b) return a; else return b; } public static int min(int a,int b){ if(a>b) return b; else return a; } public static long max(long a,long b){ if(a>b) return a; else return b; } public static long min(long a,long b){ if(a>b) return b; else return a; } public static long pow(long n,long p,long m){ long result = 1; if(p==0) return 1; if (p==1) return n; while(p!=0) { if(p%2==1) result *= n; if(result>=m) result%=m; p >>=1; n*=n; if(n>=m) n%=m; } return result; } public static long pow(long n,long p){ long result = 1; if(p==0) return 1; if (p==1) return n; while(p!=0) { if(p%2==1) result *= n; p >>=1; n*=n; } return result; } public static void main(String[] args) { // TODO code application logic here InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); int i; Region[] region = new Region[m]; for(i=0;i<m;i++){ region[i] = new Region(); } for(i=0;i<n;i++){ String str = in.readString(); int r = in.nextInt(); int s = in.nextInt(); Student st = new Student(); st.score=s; st.surname=str; region[r-1].students.add(st); } for(i=0;i<m;i++){ Collections.sort(region[i].students, new ScoreCompare()); if(region[i].students.size()>2){ if((region[i].students.get(1).score==region[i].students.get(2).score)) w.println("?"); else{ w.println(region[i].students.get(0).surname+" "+region[i].students.get(1).surname); } } else{ w.println(region[i].students.get(0).surname+" "+region[i].students.get(1).surname); } } w.close(); } static class Student{ public String surname; public int score; } static class Region extends Student{ ArrayList<Student> students = new ArrayList<>(); } static class ScoreCompare implements Comparator{ @Override public int compare(Object o1, Object o2) { Student s1=(Student)o1; Student s2=(Student)o2; if(s1.score>s2.score) return -1; else if(s1.score<s2.score) return 1; else return 0; } } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(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; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
614f37d56682efd67bdb5e68d163dca0
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.PriorityQueue; import java.util.stream.IntStream; /** * Created by andrei on 30.03.2016. */ public class CodeforcesB { public static class Participant implements Comparable{ private String name; private int id, score; public String getName() { return name; } public Participant( String name, int id, int score ) { this.name = name; this.id = id; this.score = score; } public int getScore() { return score; } @Override public int compareTo( Object o ) { Participant p = (Participant) o; if ( this.getScore() < p.getScore()) { return 1; } else if ( this.getScore() == p.getScore() ) { return 0; } return -1; } } public static void main( String[] args ) { java.util.Scanner sc = new java.util.Scanner(System.in); int n, m; n = sc.nextInt(); m = sc.nextInt(); List<List<Participant>> regions = new ArrayList<>( ); for (int i = 0; i <= m; ++i) { regions.add( new ArrayList<>( ) ); } for (int i = 0; i < n; ++i) { String name = sc.next(); int region = sc.nextInt(); int score = sc.nextInt(); regions.get( region ).add( new Participant( name, region, score ) ); } for (int i = 1; i <= m; ++i) { List<Participant> region = regions.get( i ); Collections.sort( region ); if (region.size() > 2 && region.get( 1 ).getScore() == region.get( 2 ).getScore()) { System.out.println('?'); } else { System.out.println(region.get( 0 ).getName() + " " + region.get( 1 ).getName()); } } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
d3f23b9c0d18ac646b291399ca520cd6
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.util.*; import java.util.stream.Stream; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // int brr[] = {6, 5}; // // for(int i = 0; i < brr.length; i++){ // if(i - 1 >= 0 && i + 1 < brr.length){ // if(brr[i - 1] != brr[i] && brr[i + 1] != brr[i]){ // System.out.println("unique: " + brr[i]); // } // // } // else if(i - 1 >= 0){ // if(brr[i - 1] != brr[i]){ // System.out.println("unique: " + brr[i]); // } // } // else if(i + 1 < brr.length){ // if(brr[i + 1] != brr[i]){ // System.out.println("unique: " + brr[i]); // } // } // // } int n = sc.nextInt(); int m = sc.nextInt(); List<Player> all = new ArrayList<>(); int max = 10005; String[][] str = new String[max][850]; int arr[] = new int[max]; for(int i = 0; i < n; i++){ String name = sc.next(); int region = sc.nextInt(); int points = sc.nextInt(); all.add(new Player(name, region, points)); arr[region]++; str[region][points] = name; } Collections.sort(all); // for(Player p : all){ // System.out.println(p); // } for(int i = 0; i < n;){ Player first = all.get(i); if(arr[first.region] > 2){ Player second = all.get(i + 1); Player third = all.get(i + 2); if(second.points == third.points){ System.out.println("?"); } else{ System.out.println(first.name + " " + second.name); } } else{ // if(first.points == all.get(i + 1).points){ // System.out.println("?"); // } // else{ System.out.println(first.name + " " + all.get(i + 1).name); // } } i += arr[first.region]; } sc.close(); } private static class Player implements Comparable<Player>{ String name; int region; int points; Player(String name, int region, int points){ this.name = name; this.region = region; this.points = points; } @Override public int compareTo(Player o) { int val = Long.compare(this.region, o.region); if(val == 0){ return Long.compare(o.points, this.points); } return val; } @Override public String toString() { return this.name + " " + this.points + " " + this.region; } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
92aa12e47aa8925a2421230ec7b6741d
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.util.*; import java.util.stream.Stream; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // int brr[] = {6, 5}; // // for(int i = 0; i < brr.length; i++){ // if(i - 1 >= 0 && i + 1 < brr.length){ // if(brr[i - 1] != brr[i] && brr[i + 1] != brr[i]){ // System.out.println("unique: " + brr[i]); // } // // } // else if(i - 1 >= 0){ // if(brr[i - 1] != brr[i]){ // System.out.println("unique: " + brr[i]); // } // } // else if(i + 1 < brr.length){ // if(brr[i + 1] != brr[i]){ // System.out.println("unique: " + brr[i]); // } // } // // } int n = sc.nextInt(); int m = sc.nextInt(); List<Player> all = new ArrayList<>(); int max = 10005; String[][] str = new String[max][850]; int arr[] = new int[max]; for(int i = 0; i < n; i++){ String name = sc.next(); int region = sc.nextInt(); int points = sc.nextInt(); all.add(new Player(name, region, points)); arr[region]++; str[region][points] = name; } // Collections.sort(regions); Collections.sort(all); // for(Player p : all){ // System.out.println(p); // } for(int i = 0; i < n;){ Player first = all.get(i); if(arr[first.region] > 2){ Player second = all.get(i + 1); Player third = all.get(i + 2); if(second.points == third.points){ System.out.println("?"); } else{ System.out.println(first.name + " " + second.name); } // int start = i + 1; // int end = i + arr[first.region]; // // // Player unique = null; // for(int k = start; k < end; k++){ // if(k - 1 >= start && k + 1 < end){ // if(all.get(k - 1).points != all.get(k).points && all.get(k + 1).points != all.get(k).points){ // // unique = all.get(k); //// System.out.println("unique: " + unique.name); // break; // } // // } // else if(k - 1 >= start){ // if(all.get(k - 1).points != all.get(k).points){ // unique = all.get(k); //// System.out.println("unique: " + unique.name); // break; // } // } // else if(k + 1 < end){ // if(all.get(k + 1).points != all.get(k).points){ // unique = all.get(k); //// System.out.println("unique: " + unique.name); // break; // } // } // } // // if(unique == null){ // System.out.println("?"); // } // else{ // System.out.println(first.name + " " + unique.name); // } } else{ // if(first.points == all.get(i + 1).points){ // System.out.println("?"); // } // else{ System.out.println(first.name + " " + all.get(i + 1).name); // } } i += arr[first.region]; } sc.close(); } private static class Player implements Comparable<Player>{ String name; int region; int points; Player(String name, int region, int points){ this.name = name; this.region = region; this.points = points; } @Override public int compareTo(Player o) { int val = Long.compare(this.region, o.region); if(val == 0){ return Long.compare(o.points, this.points); } return val; } @Override public String toString() { return this.name + " " + this.points + " " + this.region; } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
1237d7082b991ceeeebe454f44bedf24
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class QualifyingContest { public static void main(String[] args) throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer str=new StringTokenizer(reader.readLine()); int n=Integer.parseInt(str.nextToken()); int m=Integer.parseInt(str.nextToken()); ArrayList<description>[] arr=new ArrayList[m]; for(int i=0;i<m;i++) { arr[i]=new ArrayList<>(); } while(n-- >0){ str=new StringTokenizer(reader.readLine()); String name=str.nextToken(); int region=Integer.parseInt(str.nextToken()); int points=Integer.parseInt(str.nextToken()); arr[region-1].add(new description(name, points)); } for(int i=0;i<m;i++) { Collections.sort(arr[i]); if(arr[i].size()>2 && arr[i].get(1).points==arr[i].get(2).points){ System.out.println("?"); } else{ System.out.println(arr[i].get(0).name+" "+arr[i].get(1).name); } } } static class description implements Comparable<description>{ String name; int points; description(String name, int points) { this.name=name; this.points=points; } @Override public int compareTo(description o) { return o.points-this.points; } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
8127e2e2e76f48ee53ff596ef5b03f0c
train_003.jsonl
1459353900
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
256 megabytes
import java.io.*; import java.util.*; public class CodeF659B { public static void main(String args[]) throws IOException { InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n=in.nextInt(); ArrayList<Triplet> ar=new ArrayList<Triplet>(); int m=in.nextInt(); for(int i=0;i<n;i++) { ar.add(new Triplet(in.readString(),in.nextInt(),in.nextInt())); } Collections.sort(ar); int l=1; for(int i=0;i<n-1;i++) { while(ar.get(i).x==l&&ar.get(i+1).x==l) { if(i<n-2&&ar.get(i+1).y==ar.get(i+2).y&&ar.get(i+2).x==l) { w.println("?"); i+=2; l++; break; } else { w.println(ar.get(i).str+" "+ar.get(i+1).str); i++; l++; break; } } } w.close(); } static public class Triplet implements Comparator<Triplet>, Comparable<Triplet>{ String str; int x,y; Triplet(){} Triplet(String str,int l, int r) { this.str=str; this.x=l; this.y=r; } @Override public int compare(Triplet pr1, Triplet pr2) { if (pr1.x < pr2.x) return -1; else if (pr1.x > pr2.x) return 1; else { if (pr1.y > pr2.y) return -1; else if (pr1.y < pr2.y) return 1; else return 0; } } @Override public int compareTo(Triplet p) { if(this.x>p.x) { return 1; } else if(this.x<p.x) { return -1; } else { if(this.y<p.y) { return 1; } else if(this.y>p.y) { return -1; } else { return 0; } } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } 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 interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503"]
1 second
["Sidorov Ivanov\nAndreev Semenov", "?\nAndreev Semenov"]
NoteIn the first sample region teams are uniquely determined.In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
Java 8
standard input
[ "constructive algorithms", "sortings" ]
a1ea9eb8db25289958a6f730c555362f
The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m)Β β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
1,300
Print m lines. On the i-th line print the team of the i-th regionΒ β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
standard output
PASSED
d4a88bd487d6411aa51c0db3da93f1f4
train_003.jsonl
1606633500
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.
256 megabytes
import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; import java.util.List; import java.util.*; public class realfast implements Runnable { private static final int INF = (int) 1e9; long in= 998244353; long fac[]= new long[3000]; public void solve() throws IOException { int n = readInt(); int arr[]=new int[n+1]; for(int i =1;i<=n;i++) arr[i]= readInt(); for(int i=2;i<=n;i++) arr[i]= (arr[i]^arr[i-1]); if(n>60) out.println(1); else { //out.println("helloo"); int ans =-1; int dp[][][]=new int[n+1][n+1][n+1]; for(int i=0;i<=n;i++) for(int j =0;j<=n;j++) for(int k =0;k<=n;k++) dp[i][j][k]=-1; for(int i=1;i<=n-1;i++) { if(dp(arr,0,0,1,i,n,dp)) { ans=i; break; } } out.println(ans); } } public boolean dp(int xor[] , int l , int r , int i , int count , int n, int dp[][][]) { if(i>n) return false; if(dp[i][l][count]!=-1) { if(dp[i][l][count]==0) return false; else return true; } dp[i][l][count]= 0; int prev= xor[r]^xor[l]; for(int j =i;j<=n&&j<=i+count;j++) { int gal = xor[j]^xor[i-1]; if(gal<prev) { // out.println(i+" "); dp[i][l][count]=1; return true; } if(dp(xor,i-1,j,j+1,count-j+i,n,dp)) { dp[i][l][count]=1; return true; } } return false; } public int value (int seg[], int left , int right ,int index, int l, int r) { if(left>right) { return -100000000; } if(right<l||left>r) return -100000000; if(left>=l&&right<=r) return seg[index]; int mid = left+(right-left)/2; int val = value(seg,left,mid,2*index+1,l,r); int val2 = value(seg,mid+1,right,2*index+2,l,r); return Math.max(val,val2); } public int gcd(int a , int b ) { if(a<b) { int t =a; a=b; b=t; } if(a%b==0) return b ; return gcd(b,a%b); } public long pow(long n , long p,long m) { if(p==0) return 1; long val = pow(n,p/2,m);; val= (val*val)%m; if(p%2==0) return val; else return (val*n)%m; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void main(String[] args) { new Thread(null, new realfast(), "", 128 * (1L << 20)).start(); } private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; private BufferedReader reader; private StringTokenizer tokenizer; private PrintWriter out; @Override public void run() { try { if (ONLINE_JUDGE || !new File("input.txt").exists()) { reader = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else { reader = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } solve(); } catch (IOException e) { throw new RuntimeException(e); } finally { try { reader.close(); } catch (IOException e) { // nothing } out.close(); } } private String readString() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } @SuppressWarnings("unused") private int readInt() throws IOException { return Integer.parseInt(readString()); } @SuppressWarnings("unused") private long readLong() throws IOException { return Long.parseLong(readString()); } @SuppressWarnings("unused") private double readDouble() throws IOException { return Double.parseDouble(readString()); } } class edge implements Comparable<edge>{ int u ; int v; edge(int u, int v) { this.u=u; this.v=v; } public int compareTo(edge e) { return this.v-e.v; } }
Java
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
2 seconds
["1", "-1", "2"]
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.
Java 8
standard input
[ "constructive algorithms", "bitmasks", "brute force", "math" ]
51ad613842de8eff6226c97812118b61
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
null
Print a single integerΒ β€” the minimum number of steps needed. If there is no solution, print $$$-1$$$.
standard output
PASSED
fe7de2cc938cfc5464bafc059337d669
train_003.jsonl
1606633500
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.
256 megabytes
import java.util.*; import java.io.*; public class B1456 { static int[] xor; public static int getxor(int i, int j) { return xor[j] ^ (i == 0 ? 0 : xor[i - 1]); } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int n = sc.nextInt(); int[] arr = sc.nextIntArr(n); for (int i = 0; i < n - 1; i++) { int x = arr[i] ^ arr[i + 1]; if (i != 0 && arr[i - 1] > x) { pw.println(1); pw.close(); return; } if (i != n - 2 && x > arr[i + 2]) { pw.println(1); pw.close(); return; } } xor = new int[n]; xor[0] = arr[0]; for (int i = 1; i < n; i++) { xor[i] = xor[i - 1] ^ arr[i]; } int ans = (int) 1e9; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { for (int k = j + 1; k < n; k++) { if (getxor(i, j) > getxor(j + 1, k)) { ans = Math.min(ans, (j - i) + (k - (j + 1))); } } } } pw.println(ans == (int) 1e9 ? -1 : ans); pw.close(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } 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 double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } }
Java
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
2 seconds
["1", "-1", "2"]
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.
Java 8
standard input
[ "constructive algorithms", "bitmasks", "brute force", "math" ]
51ad613842de8eff6226c97812118b61
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
null
Print a single integerΒ β€” the minimum number of steps needed. If there is no solution, print $$$-1$$$.
standard output
PASSED
04cbc14acc4e85ccb20328454d85a864
train_003.jsonl
1606633500
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Momo { static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < arr.length; i++) { arr[i] = sc.nextInt(); } if (n > 65) { pw.println(1); } else { int ans = (int) 1e9; for (int i = 0; i < arr.length; i++) { for (int j = i + 1; j < arr.length; j++) { for (int k = j; k < arr.length; k++) { int x = 0, y = 0; for (int l = i; l < j; l++) { x ^= arr[l]; } for (int l = j; l <= k; l++) { y ^= arr[l]; } // pw.println(x+" "+y); if (x > y) { ans = Math.min(ans, k - i - 1); } } } } pw.println(ans == (int) 1e9 ? -1 : ans); } pw.close(); } public static class pair implements Comparable<pair> { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Double(x).hashCode() * 31 + new Double(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } public static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) return this.z - other.z; return this.y - other.y; } else { return this.x - other.x; } } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public boolean hasNext() { // TODO Auto-generated method stub return false; } 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
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
2 seconds
["1", "-1", "2"]
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.
Java 8
standard input
[ "constructive algorithms", "bitmasks", "brute force", "math" ]
51ad613842de8eff6226c97812118b61
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
null
Print a single integerΒ β€” the minimum number of steps needed. If there is no solution, print $$$-1$$$.
standard output
PASSED
2a372d5d9f47c276f41aeb981a518f15
train_003.jsonl
1606633500
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.
256 megabytes
import java.util.*; import java.io.*; public class B { public static void main(String[] args) { FastScanner sc = new FastScanner(); int n = sc.nextInt(); int[] arr = new int[n]; int[] acc = new int[n]; for(int i = 0; i < n; i++){ arr[i] = sc.nextInt(); acc[i] = arr[i]; if(i > 0) acc[i] ^= acc[i-1]; } for(int i = 0; i < n-2; i++){ if(Integer.highestOneBit(arr[i]) == Integer.highestOneBit(arr[i+1]) && Integer.highestOneBit(arr[i+1]) == Integer.highestOneBit(arr[i+2])) { System.out.println(1); return; } } int min = n+1; for(int i = 0; i < n; i++){ for(int j = i+1; j < n; j++){ for(int k = j+1; k <= n; k++){ int a = acc[j-1]; if(i > 0) a ^= acc[i-1]; int b = acc[k-1] ^ acc[j-1]; if(b < a) { min = Math.min(min, k-i-2); } } } } if(min > n) System.out.println(-1); else System.out.println(min); } static class FastScanner { public BufferedReader reader; public StringTokenizer tokenizer; public FastScanner() { reader = new BufferedReader(new InputStreamReader(System.in), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return reader.readLine(); } catch(IOException e) { throw new RuntimeException(e); } } } }
Java
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
2 seconds
["1", "-1", "2"]
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.
Java 8
standard input
[ "constructive algorithms", "bitmasks", "brute force", "math" ]
51ad613842de8eff6226c97812118b61
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
null
Print a single integerΒ β€” the minimum number of steps needed. If there is no solution, print $$$-1$$$.
standard output
PASSED
259df864410666be81adfbb7fbebf5c5
train_003.jsonl
1606633500
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.io.UncheckedIOException; import java.io.Closeable; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) throws Exception { Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29); thread.start(); thread.join(); } static class TaskAdapter implements Runnable { @Override public void run() { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastInput in = new FastInput(inputStream); FastOutput out = new FastOutput(outputStream); BXORGun solver = new BXORGun(); solver.solve(1, in, out); out.close(); } } static class BXORGun { int inf = (int) 1e9; public void solve(int testNumber, FastInput in, FastOutput out) { int n = in.ri(); int[] a = new int[n]; in.populate(a); if (n > 100) { out.println(1); return; } int ans = inf; PreXor xor = new PreXor(a); for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { for (int t = j + 1; t < n; t++) { for (int k = t; k < n; k++) { if (xor.intervalSum(i, j) > xor.intervalSum(t, k)) { ans = Math.min(ans, j - i + k - t); } } } } } out.println(ans == inf ? -1 : ans); } } static class PreXor { private long[] pre; private int n; public PreXor(int n) { pre = new long[n]; } public void populate(long[] a, int n) { this.n = n; pre[0] = a[0]; for (int i = 1; i < n; i++) { pre[i] = pre[i - 1] ^ a[i]; } } public void populate(int[] a, int n) { this.n = a.length; pre[0] = a[0]; for (int i = 1; i < n; i++) { pre[i] = pre[i - 1] ^ a[i]; } } public PreXor(long[] a) { this(a.length); populate(a, a.length); } public PreXor(int[] a) { this(a.length); populate(a, a.length); } public long intervalSum(int l, int r) { return prefix(r) ^ prefix(l - 1); } public long prefix(int i) { i = Math.min(i, n - 1); if (i < 0) { return 0; } return pre[i]; } } static class FastOutput implements AutoCloseable, Closeable, Appendable { private static final int THRESHOLD = 1 << 13; private final Writer os; private StringBuilder cache = new StringBuilder(THRESHOLD * 2); public FastOutput append(CharSequence csq) { cache.append(csq); return this; } public FastOutput append(CharSequence csq, int start, int end) { cache.append(csq, start, end); return this; } private void afterWrite() { if (cache.length() < THRESHOLD) { return; } flush(); } public FastOutput(Writer os) { this.os = os; } public FastOutput(OutputStream os) { this(new OutputStreamWriter(os)); } public FastOutput append(char c) { cache.append(c); afterWrite(); return this; } public FastOutput append(int c) { cache.append(c); afterWrite(); return this; } public FastOutput append(String c) { cache.append(c); afterWrite(); return this; } public FastOutput println(int c) { return append(c).println(); } public FastOutput println() { return append(System.lineSeparator()); } public FastOutput flush() { try { os.append(cache); os.flush(); cache.setLength(0); } catch (IOException e) { throw new UncheckedIOException(e); } return this; } public void close() { flush(); try { os.close(); } catch (IOException e) { throw new UncheckedIOException(e); } } public String toString() { return cache.toString(); } } static class FastInput { private final InputStream is; private byte[] buf = new byte[1 << 13]; private int bufLen; private int bufOffset; private int next; public FastInput(InputStream is) { this.is = is; } public void populate(int[] data) { for (int i = 0; i < data.length; i++) { data[i] = readInt(); } } private int read() { while (bufLen == bufOffset) { bufOffset = 0; try { bufLen = is.read(buf); } catch (IOException e) { bufLen = -1; } if (bufLen == -1) { return -1; } } return buf[bufOffset++]; } public void skipBlank() { while (next >= 0 && next <= 32) { next = read(); } } public int ri() { return readInt(); } public int readInt() { int sign = 1; skipBlank(); if (next == '+' || next == '-') { sign = next == '+' ? 1 : -1; next = read(); } int val = 0; if (sign == 1) { while (next >= '0' && next <= '9') { val = val * 10 + next - '0'; next = read(); } } else { while (next >= '0' && next <= '9') { val = val * 10 - next + '0'; next = read(); } } return val; } } }
Java
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
2 seconds
["1", "-1", "2"]
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.
Java 8
standard input
[ "constructive algorithms", "bitmasks", "brute force", "math" ]
51ad613842de8eff6226c97812118b61
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
null
Print a single integerΒ β€” the minimum number of steps needed. If there is no solution, print $$$-1$$$.
standard output
PASSED
7118d2027045894890411024104cb060
train_003.jsonl
1606633500
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { static PrintWriter out; static Reader in; public static void main(String[] args) throws IOException { //in = new Reader(new FileInputStream(args[0])); // for test. input_output(); Main solver = new Main(); solver.solve(); out.close(); // remove when testing. out.flush(); // remove when testing. } static int INF = (int)2e9; static int maxn = (int)2e5+5; static int mod = 998244353; static int n, m, q, t, k; void solve() throws IOException{ n = in.nextInt(); int[] arr = new int[n]; int[] hsb = new int[n]; for (int i = 0 ; i < n; i++) { arr[i] = in.nextInt(); hsb[i] = Integer.highestOneBit(arr[i]); } for (int i = 0; i < n-2; i++) { if (hsb[i] == hsb[i+1] && hsb[i] == hsb[i+2]) { out.println(1); return; } } long[] pre = new long[n]; pre[0] = arr[0]; for (int i = 1; i < n; i++) pre[i] = pre[i-1]^arr[i]; int ans = INF; for (int i = 0; i < n-2; i++) { for (int j = i+2; j < n; j++) { for (int z = i; z < j; z++) { long first = pre[z]^(i!= 0 ? pre[i-1] : 0), second = pre[j]^pre[z]; if (first > second) ans = Math.min(ans, j-i-1); } } } if (ans == INF) out.println(-1); else out.println(ans); } //<> 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; } } static void input_output() throws IOException { File f = new File("in.txt"); if(f.exists() && !f.isDirectory()) { in = new Reader(new FileInputStream("in.txt")); } else in = new Reader(); f = new File("out.txt"); if(f.exists() && !f.isDirectory()) { out = new PrintWriter(new File("out.txt")); } else out = new PrintWriter(System.out); } }
Java
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
2 seconds
["1", "-1", "2"]
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.
Java 8
standard input
[ "constructive algorithms", "bitmasks", "brute force", "math" ]
51ad613842de8eff6226c97812118b61
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
null
Print a single integerΒ β€” the minimum number of steps needed. If there is no solution, print $$$-1$$$.
standard output
PASSED
b9b91c5324259a8279a1571ced5f1786
train_003.jsonl
1606633500
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.
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 * * @author xwchen */ 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int[] a = in.nextIntArray(n); int[] posOfSig = new int[n]; for (int i = 0; i < n; ++i) { for (int j = 31; j >= 0; --j) { if (BitUtil.testBit(a[i], j)) { posOfSig[i] = j; break; } } //Utils.pf("posOfsig[%d] = %d",i,posOfSig[i]); } boolean three = false; for (int i = 0; i < n; ++i) { if (i + 2 < n && posOfSig[i] == posOfSig[i + 1] && posOfSig[i + 1] == posOfSig[i + 2]) { three = true; break; } } if (three) { out.println(1); } else { int best = 1 << 30; int[] sum = new int[n + 1]; for (int i = 1; i <= n; ++i) { sum[i] = sum[i - 1] ^ a[i - 1]; } for (int i = 0; i < n; ++i) { if (i + 1 < n && posOfSig[i] == posOfSig[i + 1]) { for (int j = i - 1; j >= 0; --j) { boolean found = false; for (int mid = j; mid <= i; ++mid) { if (getSubSum(sum, j, mid + 1) > getSubSum(sum, mid + 1, i + 2)) { //Utils.pf("%d,%d",i,j); found = true; break; } } if (found) { //Utils.pf("%d,%d",i,j); best = Math.min(best, i - j); break; } } } } if (best < (1 << 30)) { out.println(best); } else { out.println(-1); } } } int getSubSum(int[] sum, int left, int right) { return sum[right] ^ sum[left]; } } static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer = new StringTokenizer(""); public InputReader(InputStream inputStream) { this.reader = new BufferedReader( new InputStreamReader(inputStream)); } public String next() { while (!tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { e.printStackTrace(); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } static class BitUtil { public static boolean testBit(long mask, int pos) { return (mask & (1L << pos)) != 0; } } }
Java
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
2 seconds
["1", "-1", "2"]
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.
Java 8
standard input
[ "constructive algorithms", "bitmasks", "brute force", "math" ]
51ad613842de8eff6226c97812118b61
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
null
Print a single integerΒ β€” the minimum number of steps needed. If there is no solution, print $$$-1$$$.
standard output
PASSED
11374b9109f169cd0151e1cb7cdedf1e
train_003.jsonl
1606633500
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.
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 * * @author xwchen */ 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int[] a = in.nextIntArray(n); int[] posOfSig = new int[n]; for (int i = 0; i < n; ++i) { for (int j = 31; j >= 0; --j) { if (BitUtil.testBit(a[i], j)) { posOfSig[i] = j; break; } } //Utils.pf("posOfsig[%d] = %d",i,posOfSig[i]); } boolean three = false; for (int i = 0; i < n; ++i) { if (i + 2 < n && posOfSig[i] == posOfSig[i + 1] && posOfSig[i + 1] == posOfSig[i + 2]) { three = true; break; } } if (three) { out.println(1); } else { int best = 1 << 30; int[] sum = new int[n + 1]; for (int i = 1; i <= n; ++i) { sum[i] = sum[i] ^ a[i - 1]; } for (int i = 0; i < n; ++i) { if (i + 1 < n && posOfSig[i] == posOfSig[i + 1]) { for (int j = i - 1; j >= 0; --j) { boolean found = false; for (int mid = j; mid <= i; ++mid) { int v1 = 0; for (int k = j; k <= mid; ++k) { v1 ^= a[k]; } int v2 = 0; for (int k = mid + 1; k <= i + 1; ++k) { v2 ^= a[k]; } if (v1 > v2) { //Utils.pf("%d,%d",i,j); found = true; break; } } if (found) { //Utils.pf("%d,%d",i,j); best = Math.min(best, i - j); break; } } } } if (best < (1 << 30)) { out.println(best); } else { out.println(-1); } } } } static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer = new StringTokenizer(""); public InputReader(InputStream inputStream) { this.reader = new BufferedReader( new InputStreamReader(inputStream)); } public String next() { while (!tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { e.printStackTrace(); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } static class BitUtil { public static boolean testBit(long mask, int pos) { return (mask & (1L << pos)) != 0; } } }
Java
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
2 seconds
["1", "-1", "2"]
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.
Java 8
standard input
[ "constructive algorithms", "bitmasks", "brute force", "math" ]
51ad613842de8eff6226c97812118b61
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
null
Print a single integerΒ β€” the minimum number of steps needed. If there is no solution, print $$$-1$$$.
standard output
PASSED
d642459a7bb175846ee678d4ba2288f7
train_003.jsonl
1606633500
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class B { public static void main(String hi[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int N = Integer.parseInt(st.nextToken()); int[] arr = readArr(N, infile, st); if(N <= 2) { System.out.println(-1); return; } for(int i=0; i < N-3; i+=4) { int a = msb(arr[i]); int b = msb(arr[i+1]); int c = msb(arr[i+2]); int d = msb(arr[i+3]); if(a == b && a == c && a == d) { System.out.println(1); return; } } int[] pref = new int[N]; pref[0] = arr[0]; for(int i=1; i < N; i++) pref[i] = arr[i]^pref[i-1]; int res = Integer.MAX_VALUE; for(int a=0; a < N; a++) for(int b=a+1; b < N; b++) for(int c=b; c < N; c++) { int left = 0; if(a > 0) left = arr[a-1]; int x = xor(pref, a, b-1); int y = xor(pref, b, c); int right = Integer.MAX_VALUE; if(c+1 < N) right = arr[c+1]; if(left <= x && x <= y && y <= right); else res = min(res, c-b+b-a-1); } for(int a=0; a < N; a++) for(int b=a+1; b < N; b++) { ArrayList<Integer> ls = new ArrayList<Integer>(); for(int i=0; i < a; i++) ls.add(arr[i]); int xor = arr[a]; for(int i=a+1; i <= b; i++) xor ^= arr[i]; ls.add(xor); for(int i=b+1; i < N; i++) ls.add(arr[i]); boolean works = false; for(int i=1; i < ls.size(); i++) if(ls.get(i)-ls.get(i-1) < 0) works = true; if(works) res = min(res, b-a); } if(res == Integer.MAX_VALUE) res = -1; System.out.println(res); } public static int xor(int[] pref, int l, int r) { int res = pref[r]; if(l > 0) res ^= pref[l-1]; return res; } public static int msb(int x) { for(int b=29; b >= 0; b--) if((x&(1<<b)) > 0) return b; return -1; } public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } }
Java
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
2 seconds
["1", "-1", "2"]
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.
Java 8
standard input
[ "constructive algorithms", "bitmasks", "brute force", "math" ]
51ad613842de8eff6226c97812118b61
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
null
Print a single integerΒ β€” the minimum number of steps needed. If there is no solution, print $$$-1$$$.
standard output
PASSED
677c94a4b7a471f6684dbdf12dd09c1d
train_003.jsonl
1606633500
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class B { public static void main(String hi[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int N = Integer.parseInt(st.nextToken()); int[] arr = readArr(N, infile, st); if(N <= 2) { System.out.println(-1); return; } for(int i=0; i < N-3; i+=4) { int a = msb(arr[i]); int b = msb(arr[i+1]); int c = msb(arr[i+2]); int d = msb(arr[i+3]); if(a == b && a == c && a == d) { System.out.println(1); return; } } int[] pref = new int[N]; pref[0] = arr[0]; for(int i=1; i < N; i++) pref[i] = arr[i]^pref[i-1]; int res = Integer.MAX_VALUE; for(int a=0; a < N; a++) for(int b=a+1; b < N; b++) for(int c=b; c < N; c++) { int left = 0; if(a > 0) left = arr[a-1]; int x = xor(pref, a, b-1); int y = xor(pref, b, c); int right = Integer.MAX_VALUE; if(c+1 < N) right = arr[c+1]; if(left <= x && x <= y && y <= right); else res = min(res, c-b+b-a-1); } if(res == Integer.MAX_VALUE) res = -1; System.out.println(res); } public static int xor(int[] pref, int l, int r) { int res = pref[r]; if(l > 0) res ^= pref[l-1]; return res; } public static int msb(int x) { for(int b=29; b >= 0; b--) if((x&(1<<b)) > 0) return b; return -1; } public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } }
Java
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
2 seconds
["1", "-1", "2"]
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.
Java 8
standard input
[ "constructive algorithms", "bitmasks", "brute force", "math" ]
51ad613842de8eff6226c97812118b61
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
null
Print a single integerΒ β€” the minimum number of steps needed. If there is no solution, print $$$-1$$$.
standard output
PASSED
6a29ac86a2a45411ffba36fdf23dcc46
train_003.jsonl
1606633500
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static int MOD = 1000000007; // After writing solution, quick scan for: // array out of bounds // special cases e.g. n=1? // // Big numbers arithmetic bugs: // int overflow // sorting, or taking max, after MOD void solve() throws IOException { int n = ri(); int[] a = ril(n); // Check if possible in one operations for (int i = 0; i < n-1; i++) { int num = a[i] ^ a[i+1]; int prev = i-1 >= 0 ? a[i-1] : Integer.MIN_VALUE; int next = i+2 < n ? a[i+2] : Integer.MAX_VALUE; if (num < prev || num > next) { pw.println("1"); return; } } int ans = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { int total = 0; for (int k = i; k <= j; k++) total ^= a[k]; int leftxor = 0; for (int k = i; k <= j-1; k++) { leftxor ^= a[k]; if (leftxor > (total ^ leftxor)) { ans = Math.min(ans, k-i + j-k-1); } } } } pw.println(ans == Integer.MAX_VALUE ? "-1" : ans); } // Template code below BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException { Main m = new Main(); m.solve(); m.close(); } void close() throws IOException { pw.flush(); pw.close(); br.close(); } int ri() throws IOException { return Integer.parseInt(br.readLine().trim()); } long rl() throws IOException { return Long.parseLong(br.readLine().trim()); } int[] ril(int n) throws IOException { int[] nums = new int[n]; int c = 0; for (int i = 0; i < n; i++) { int sign = 1; c = br.read(); int x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } nums[i] = x * sign; } while (c != '\n' && c != -1) c = br.read(); return nums; } long[] rll(int n) throws IOException { long[] nums = new long[n]; int c = 0; for (int i = 0; i < n; i++) { int sign = 1; c = br.read(); long x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } nums[i] = x * sign; } while (c != '\n' && c != -1) c = br.read(); return nums; } int[] rkil() throws IOException { int sign = 1; int c = br.read(); int x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } return ril(x); } long[] rkll() throws IOException { int sign = 1; int c = br.read(); int x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } return rll(x); } char[] rs() throws IOException { return br.readLine().toCharArray(); } void sort(int[] A) { Random r = new Random(); for (int i = A.length-1; i > 0; i--) { int j = r.nextInt(i+1); int temp = A[i]; A[i] = A[j]; A[j] = temp; } Arrays.sort(A); } void printDouble(double d) { pw.printf("%.16f", d); } }
Java
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
2 seconds
["1", "-1", "2"]
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.
Java 8
standard input
[ "constructive algorithms", "bitmasks", "brute force", "math" ]
51ad613842de8eff6226c97812118b61
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
null
Print a single integerΒ β€” the minimum number of steps needed. If there is no solution, print $$$-1$$$.
standard output
PASSED
4f710c3aaa3ad35aed65569e58d97df2
train_003.jsonl
1329750000
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≀ i &lt; j ≀ n, 1 ≀ k ≀ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
256 megabytes
import java.io.*; import java.util.*; public class C { public static void main(String[] args)throws IOException { BufferedReader ob = new BufferedReader(new InputStreamReader(System.in)); StringBuffer sb = new StringBuffer(); String s[]=ob.readLine().split(" "); int n=Integer.parseInt(s[0]); long mod = 1000000007L; int m=Integer.parseInt(s[1]); long ans = 1; HashSet<Character> set[] = new HashSet[m]; for(int i = 0;i < m;i++) set[i] = new HashSet<>(); for(int i = 0;i < n;i++) { String str=ob.readLine(); for(int j = 0;j < m;j++) set[j].add(str.charAt(j)); } for(int i = 0;i < m;i++) { // System.out.println("size = "+set[i].size()); ans*=set[i].size(); ans%=mod; } System.out.println(ans); } }
Java
["2 3\nAAB\nBAA", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA"]
2 seconds
["4", "216"]
NoteIn the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Java 8
standard input
[ "combinatorics" ]
a37df9b239a40473516d1525d56a0da7
The first input line contains two integers n and m (1 ≀ n, m ≀ 100) β€” the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
1,400
Print the single number β€” the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
standard output
PASSED
baf1683fcd6377d7046b4ba6d34a4792
train_003.jsonl
1329750000
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≀ i &lt; j ≀ n, 1 ≀ k ≀ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
256 megabytes
import java.io.*; import java.util.*; public class C { public static void main(String[] args)throws IOException { BufferedReader ob = new BufferedReader(new InputStreamReader(System.in)); StringBuffer sb = new StringBuffer(); String s[]=ob.readLine().split(" "); int n=Integer.parseInt(s[0]); long mod = 1000000007L; int m=Integer.parseInt(s[1]); long ans=1; HashSet<Character> set[]=new HashSet[m]; for(int i=0;i<m;i++) set[i]=new HashSet<>(); for(int i=0;i<n;i++) { String str=ob.readLine(); for(int j=0;j<m;j++) set[j].add(str.charAt(j)); } for(int i=0;i<m;i++) { // System.out.println("size = "+set[i].size()); ans*=set[i].size(); ans%=mod; } System.out.println(ans); } }
Java
["2 3\nAAB\nBAA", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA"]
2 seconds
["4", "216"]
NoteIn the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Java 8
standard input
[ "combinatorics" ]
a37df9b239a40473516d1525d56a0da7
The first input line contains two integers n and m (1 ≀ n, m ≀ 100) β€” the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
1,400
Print the single number β€” the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
standard output
PASSED
21c58d5c5c3dba3e8ce322b89443537b
train_003.jsonl
1329750000
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≀ i &lt; j ≀ n, 1 ≀ k ≀ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
256 megabytes
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; /** * @author johnny16 * */ public class PocketBook { static int mod = 1000000007; 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[128]; // 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 static void main(String[] args) throws IOException { Reader in = new Reader(); int i, j, t, n, m; // t = in.nextInt(); long ans; n = in.nextInt(); m = in.nextInt(); in.readLine(); String s; boolean unq[][] = new boolean[m][26]; ans = 1; for (i = 0; i < n; i++) { s = in.readLine(); for (j = 0; j < m; j++) { int c = (int) s.charAt(j) - 65; unq[j][c] = true; } } for (i = 0; i < m; i++) { int x = 0; for (j = 0; j < 26; j++) { if (unq[i][j]) x++; } ans = ((ans % mod) * x) % mod; } System.out.println(ans); } }
Java
["2 3\nAAB\nBAA", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA"]
2 seconds
["4", "216"]
NoteIn the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Java 8
standard input
[ "combinatorics" ]
a37df9b239a40473516d1525d56a0da7
The first input line contains two integers n and m (1 ≀ n, m ≀ 100) β€” the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
1,400
Print the single number β€” the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
standard output
PASSED
e4472c484008bc56e4f8d4000a853b4f
train_003.jsonl
1329750000
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≀ i &lt; j ≀ n, 1 ≀ k ≀ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
256 megabytes
import java.util.*; public class PocketBook { static final int MODULO = 1000000007; public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); char[][] book = new char[n][m]; for (int i = 0; i < n; i++) { book[i] = in.next().toCharArray(); } long ans = 1; for (int col = 0; col < m; col++) { Set<Character> unique = new HashSet<>(); for (int row = 0; row < n; row++) { unique.add(book[row][col]); } ans *= unique.size(); ans %= MODULO; } System.out.println(ans); in.close(); System.exit(0); } }
Java
["2 3\nAAB\nBAA", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA"]
2 seconds
["4", "216"]
NoteIn the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Java 8
standard input
[ "combinatorics" ]
a37df9b239a40473516d1525d56a0da7
The first input line contains two integers n and m (1 ≀ n, m ≀ 100) β€” the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
1,400
Print the single number β€” the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
standard output
PASSED
a7ee840276cb94bea23a120182766415
train_003.jsonl
1329750000
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≀ i &lt; j ≀ n, 1 ≀ k ≀ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.util.StringTokenizer; public class Main { public static void main(String[] args)throws IOException, URISyntaxException { Reader.init(System.in); StringBuilder s=new StringBuilder(); int n = Reader.nextInt(), m = Reader.nextInt(), i, j; boolean[][] visited = new boolean[m][26]; String str; long sum = 1, cnt; for(i = 0; i < n; i++) { str = Reader.nextLine(); for(j = 0; j < m; j++) visited[j][str.charAt(j) - 'A'] = true; } for(i = 0; i < m; i++) { cnt = 0; for(j = 0; j < 26; j++) if(visited[i][j]) cnt++; if(cnt > 0) { sum *= cnt; sum %= 1000000007; } } s.append(sum).append('\n'); System.out.print(s); } } class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) throws UnsupportedEncodingException { reader = new BufferedReader( new InputStreamReader(input, "UTF-8") ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static String nextLine() throws IOException { return reader.readLine(); } static int nextInt() throws IOException { return Integer.parseInt( next() ); } static double nextDouble() throws IOException { return Double.parseDouble( next() ); } static long nextLong() throws IOException { return Long.parseLong( next() ); } }
Java
["2 3\nAAB\nBAA", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA"]
2 seconds
["4", "216"]
NoteIn the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Java 8
standard input
[ "combinatorics" ]
a37df9b239a40473516d1525d56a0da7
The first input line contains two integers n and m (1 ≀ n, m ≀ 100) β€” the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
1,400
Print the single number β€” the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
standard output
PASSED
9800b4bb3552df81c391a99227ac5100
train_003.jsonl
1329750000
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≀ i &lt; j ≀ n, 1 ≀ k ≀ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
256 megabytes
import java.util.Arrays; import java.util.Scanner; import java.util.stream.IntStream; public class Main { static final int MODULUS = 1_000_000_007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); String[] names = new String[n]; for (int i = 0; i < names.length; i++) { names[i] = sc.next(); } System.out.println(solve(names, m)); sc.close(); } static int solve(String[] names, int m) { return IntStream.range(0, m).reduce(1, (result, i) -> multiplyMod(result, (int) Arrays.stream(names).map(name -> name.charAt(i)).distinct().count())); } static int multiplyMod(int x, int y) { return (int) ((long) x * y % MODULUS); } }
Java
["2 3\nAAB\nBAA", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA"]
2 seconds
["4", "216"]
NoteIn the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Java 8
standard input
[ "combinatorics" ]
a37df9b239a40473516d1525d56a0da7
The first input line contains two integers n and m (1 ≀ n, m ≀ 100) β€” the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
1,400
Print the single number β€” the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
standard output
PASSED
8df19847964e078fc57cdab3f150d8d8
train_003.jsonl
1329750000
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≀ i &lt; j ≀ n, 1 ≀ k ≀ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
256 megabytes
/** * ******* Created on 5/12/19 7:57 PM******* */ import java.io.*; import java.util.*; public class C152 implements Runnable { private static final int MAX = (int) (1E5 + 5); private static final int MOD = (int) (1E9 + 7); private static final int Inf = (int) (1E9 + 10); private void solve() throws IOException { int n = reader.nextInt(); int m = reader.nextInt(); Set<Character> set[] = new Set[105]; for(int i =0;i<105;i++) set[i] = new HashSet<>(); for(int i=0;i<n;i++){ String s = reader.next(); for(int j=0;j<m;j++){ set[j].add(s.charAt(j)); } } long res =1; for(int i=0;i<m;i++){ res = (res* set[i].size()) %MOD; } writer.println(res); } public static void main(String[] args) throws IOException { try (Input reader = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) { new C152().run(); } } StandardInput reader; PrintWriter writer; @Override public void run() { try { reader = new StandardInput(); writer = new PrintWriter(System.out); solve(); reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } interface Input extends Closeable { String next() throws IOException; default int nextInt() throws IOException { return Integer.parseInt(next()); } default long nextLong() throws IOException { return Long.parseLong(next()); } default double nextDouble() throws IOException { return Double.parseDouble(next()); } default int[] readIntArray() throws IOException { return readIntArray(nextInt()); } default int[] readIntArray(int size) throws IOException { int[] array = new int[size]; for (int i = 0; i < array.length; i++) { array[i] = nextInt(); } return array; } default long[] readLongArray(int size) throws IOException { long[] array = new long[size]; for (int i = 0; i < array.length; i++) { array[i] = nextLong(); } return array; } } private static class StandardInput implements Input { private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private StringTokenizer stringTokenizer; @Override public void close() throws IOException { reader.close(); } @Override public String next() throws IOException { if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) { stringTokenizer = new StringTokenizer(reader.readLine()); } return stringTokenizer.nextToken(); } } }
Java
["2 3\nAAB\nBAA", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA"]
2 seconds
["4", "216"]
NoteIn the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Java 8
standard input
[ "combinatorics" ]
a37df9b239a40473516d1525d56a0da7
The first input line contains two integers n and m (1 ≀ n, m ≀ 100) β€” the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
1,400
Print the single number β€” the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
standard output