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
70619bc0be9791155759395303ecfcdb
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.*; public class CF_1354_C1 { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0) { int n=sc.nextInt(); n=n*2; int ts=(2*n-4)*90; double ang=ts*1.0/n; int p=n/4; double a=0; for(int i=1;i<2*p;++i) { a+=Math.abs(Math.cos(Math.toRadians(i*ang-90))); } System.out.println(a); } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
6d3948cb8381169142430bfe8023d593
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.io.*; import java.math.BigDecimal; import java.util.*; public class Main { public static void main(String[] args) throws FileNotFoundException { FastReader fr = new FastReader(); int tc = fr.nextInt(); BigDecimal err = new BigDecimal("0.41421356237309510"); while (tc-- > 0) { int n = fr.nextInt(); double ans = 1 / ( Math.tan(Math.PI / (2 * n))); System.out.println(ans); } } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() throws FileNotFoundException { 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\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
f82392d8931fd2793a4476d0de74c85b
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import sun.awt.image.IntegerComponentRaster; import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.util.*; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Manan Patel */ public class Main{ public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter w = new PrintWriter(outputStream); Solution solver = new Solution(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(1 , in, w); w.close(); } static class Solution { public void solve(int tc, InputReader sc, PrintWriter w) { int n = sc.nextInt(); double pie = 3.141592653589793238; double ans = Math.tan(pie / (2 * n)); w.printf("%.9f", 1 / ans); w.println(); } } static class f{ public static long power(long x, int y){ long res = 1; while (y > 0) { if ((y & 1) == 1) res = (res*x); y = y >> 1; x = x * x; } return res; } public static void sort(int[] arr) { int n = arr.length, mid, h, s, l, i, j, k; int[] res = new int[n]; for (s = 1; s < n; s <<= 1) { for (l = 0; l < n - 1; l += (s << 1)) { h = Math.min(l + (s << 1) - 1, n - 1); mid = Math.min(l + s - 1, n - 1); i = l; j = mid + 1; k = l; while (i <= mid && j <= h) res[k++] = (arr[i] <= arr[j] ? arr[i++] : arr[j++]); while (i <= mid) res[k++] = arr[i++]; while (j <= h) res[k++] = arr[j++]; for (k = l; k <= h; k++) arr[k] = res[k]; } } } } 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 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 String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
1798bc2b156515d2af202e0668394eec
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.*; import java.io.*; public class Solution{ static PrintWriter out=new PrintWriter(System.out); public static void main (String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] input=br.readLine().trim().split(" "); int numTestCases=Integer.parseInt(input[0]); while(numTestCases-->0) { input=br.readLine().trim().split(" "); int n=Integer.parseInt(input[0]); out.println(getSide(n)); } out.flush(); out.close(); } public static double getSide(int n) { n*=2; double ans=Math.tan( (Math.PI*(n-2)) / (2*n) ); return ans; } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
a8dc18815e9bdf14ef3a29218c68d668
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.*; import java.io.*; public class Solution{ static PrintWriter out=new PrintWriter(System.out); public static void main (String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] input=br.readLine().trim().split(" "); int numTestCases=Integer.parseInt(input[0]); while(numTestCases-->0) { input=br.readLine().trim().split(" "); int n=Integer.parseInt(input[0]); out.println(getSide(n)); } out.flush(); out.close(); } public static double getSide(int n) { double ans=1/(Math.tan(Math.PI/(2*n))); return ans; } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
e42c54b59afdb307e69b8da9524e925f
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
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.Comparator; import java.util.Objects; import java.util.StringTokenizer; import java.util.function.BiFunction; import java.util.function.Function; public class Main { static BiFunction<Integer, Integer, Integer> ADD = (x, y) -> (x + y); static Function<Pair<Integer, Integer>, Integer> GET_FIRST = (x) -> (x.first); static Function<Pair<Integer, Integer>, Integer> GET_SECOND = (x) -> (x.second); static Comparator<Pair<Integer, Integer>> C = Comparator.comparing(GET_FIRST).thenComparing(GET_SECOND); public static void main(String[] args) throws Exception { long startTime = System.nanoTime(); int t = in.nextInt(); while (t-- > 0) { solve(); } long endTime = System.nanoTime(); err.println("Execution Time : +" + (endTime - startTime) / 1000000 + " ms"); exit(0); } static void solve() { int n = in.nextInt(); out.println(1 / Math.tan(Math.PI / (2 * n))); } static void debug(Object... args) { for (Object a : args) { out.println(a); } } static void y() { out.println("YES"); } static void n() { out.println("NO"); } static void fail() { out.println("-1"); exit(0); } static class Pair<T, R> { public T first; public R second; public Pair(T first, R second) { this.first = first; this.second = second; } @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final Pair<?, ?> pair = (Pair<?, ?>) o; return Objects.equals(first, pair.first) && Objects.equals(second, pair.second); } @Override public int hashCode() { return Objects.hash(first, second); } @Override public String toString() { return "Pair{" + "a=" + first + ", b=" + second + '}'; } public T getFirst() { return first; } public R getSecond() { return second; } } static <T, R> Pair<T, R> make_pair(T a, R b) { return new Pair<>(a, b); } static class ArrayUtils { static void swap(int[] a, int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } static int[] reverse(int[] data) { int[] p = new int[data.length]; for (int i = 0, j = data.length - 1; i < data.length; i++, j--) { p[i] = data[j]; } return p; } static void prefixSum(long[] data) { for (int i = 1; i < data.length; i++) { data[i] += data[i - 1]; } } static void prefixSum(int[] data) { for (int i = 1; i < data.length; i++) { data[i] += data[i - 1]; } } static long[] reverse(long[] data) { long[] p = new long[data.length]; for (int i = 0, j = data.length - 1; i < data.length; i++, j--) { p[i] = data[j]; } return p; } static char[] reverse(char[] data) { char[] p = new char[data.length]; for (int i = 0, j = data.length - 1; i < data.length; i++, j--) { p[i] = data[j]; } return p; } static int[] MergeSort(int[] A) { if (A.length > 1) { int q = A.length / 2; int[] left = new int[q]; int[] right = new int[A.length - q]; System.arraycopy(A, 0, left, 0, q); System.arraycopy(A, q, right, 0, A.length - q); int[] left_sorted = MergeSort(left); int[] right_sorted = MergeSort(right); return Merge(left_sorted, right_sorted); } else { return A; } } static int[] Merge(int[] left, int[] right) { int[] A = new int[left.length + right.length]; int i = 0; int j = 0; for (int k = 0; k < A.length; k++) { // To handle left becoming empty if (i == left.length && j < right.length) { A[k] = right[j]; j++; continue; } // To handle right becoming empty if (j == right.length && i < left.length) { A[k] = left[i]; i++; continue; } if (left[i] <= right[j]) { A[k] = left[i]; i++; } else { A[k] = right[j]; j++; } } return A; } static long[] MergeSort(long[] A) { if (A.length > 1) { int q = A.length / 2; long[] left = new long[q]; long[] right = new long[A.length - q]; System.arraycopy(A, 0, left, 0, q); System.arraycopy(A, q, right, 0, A.length - q); long[] left_sorted = MergeSort(left); long[] right_sorted = MergeSort(right); return Merge(left_sorted, right_sorted); } else { return A; } } static long[] Merge(long[] left, long[] right) { long[] A = new long[left.length + right.length]; int i = 0; int j = 0; for (int k = 0; k < A.length; k++) { // To handle left becoming empty if (i == left.length && j < right.length) { A[k] = right[j]; j++; continue; } // To handle right becoming empty if (j == right.length && i < left.length) { A[k] = left[i]; i++; continue; } if (left[i] <= right[j]) { A[k] = left[i]; i++; } else { A[k] = right[j]; j++; } } return A; } } 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 long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public int[] readAllInts(int n) { int[] p = new int[n]; for (int i = 0; i < n; i++) { p[i] = in.nextInt(); } return p; } public int[] readAllInts(int n, int s) { int[] p = new int[n + s]; for (int i = s; i < n + s; i++) { p[i] = in.nextInt(); } return p; } public long[] readAllLongs(int n) { long[] p = new long[n]; for (int i = 0; i < n; i++) { p[i] = in.nextLong(); } return p; } public long[] readAllLongs(int n, int s) { long[] p = new long[n + s]; for (int i = s; i < n + s; i++) { p[i] = in.nextLong(); } return p; } public double nextDouble() { return Double.parseDouble(next()); } } static void exit(int a) { out.close(); err.close(); System.exit(a); } static InputStream inputStream = System.in; static OutputStream outputStream = System.out; static OutputStream errStream = System.err; static InputReader in = new InputReader(inputStream); static PrintWriter out = new PrintWriter(outputStream); static PrintWriter err = new PrintWriter(errStream); static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
d0a944d85c75fa35eb441f52446fef59
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int tc=Integer.parseInt(br.readLine()); for(int i=0;i<tc;i++){ int n=Integer.parseInt(br.readLine()); System.out.println(String.format("%.9f",(1/Math.tan(Math.PI/(2*n))))); } // your code goes here } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
fd0f2e9d979e114b6278757e29d0e45e
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { private static FastReader fastReader = new FastReader(); public static void main(String[] args) { Task solver = new Task(); solver.solve(); } static class Task { private static StringBuilder result = new StringBuilder(); public void solve() { int nt = fastReader.nextInt(); while (nt-- > 0) { long n = fastReader.nextLong() * 2; double ans = 1/Math.tan(Math.PI/n); result.append(ans+"\n"); } fastReader.print(result.toString()); } } static class FastReader { public BufferedReader reader; public StringTokenizer tokenizer; private static PrintWriter pw; public FastReader() { reader = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(System.out); 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 String readLine() { try { return reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return null; } public void print(String str) { pw.print(str); pw.flush(); } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
f9b5fbe2d58baabf4c65547ddd1a8a0e
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { private static FastReader fastReader = new FastReader(); public static void main(String[] args) { Task solver = new Task(); solver.solve(); } static class Task { private static StringBuilder result = new StringBuilder(); public void solve() { int nt = fastReader.nextInt(); while (nt-- > 0) result.append(1/Math.tan(Math.PI/(fastReader.nextLong()*2))+"\n"); fastReader.print(result.toString()); } } static class FastReader { public BufferedReader reader; public StringTokenizer tokenizer; private static PrintWriter pw; public FastReader() { reader = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(System.out); 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 String readLine() { try { return reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return null; } public void print(String str) { pw.print(str); pw.flush(); } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
fa1922f777e1eb704c6b82a635b61e01
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int t = Integer.parseInt(br.readLine().trim()); while (t--!=0) { // StringTokenizer st = new StringTokenizer(br.readLine().trim()); int n = 2*Integer.parseInt(br.readLine().trim()); double ans=Math.tan((Math.PI*(n-2))/(2*n)); out.println(ans); } out.close(); } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
9a171de7249de649eedefdebbb56c2cb
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main(String args[]) throws IOException { InOut inout = new InOut(); Resolver resolver = new Resolver(inout); resolver.solve(); inout.flush(); } private static class Resolver { final long LONG_INF = (long) 1e18; final int INF = 1000000007; final int MOD = 998244353; long f[]; InOut inout; Resolver(InOut inout) { this.inout = inout; } void initF(int n) { f = new long[n + 1]; f[1] = 1; for (int i = 2; i <= n; i++) { f[i] = (f[i - 1] * i) % MOD; } } int lowbit(int x) { return x & -x; } void add(long C[], int x, long val) { int n = C.length - 1; while (x <= n) { C[x] += val; x += lowbit(x); } } long getSum(long C[], int x) { long res = 0; while (x > 0) { res += C[x]; x -= lowbit(x); } return res; } void solve() throws IOException { int tt = 1; boolean hvt = true; if (hvt) { tt = nextInt(); } for (int cs = 1; cs <= tt; cs++) { int n = nextInt(); double res = 1.0 / Math.tan(Math.PI / 2 / n); format("%f\n", res); } } String next(int n) throws IOException { return inout.next(n); } int nextInt() throws IOException { return inout.nextInt(); } long nextLong(int n) throws IOException { return inout.nextLong(n); } void print(String s, boolean nextLine) { inout.print(s, nextLine); } void format(String format, Object... obj) { inout.format(format, obj); } void flush() { inout.flush(); } void swap(int a[], int i, int j) { a[i] ^= a[j]; a[j] ^= a[i]; a[i] ^= a[j]; } boolean topSort() { int n = edges.length - 1; int d[] = new int[n + 1]; for (int i = 1; i <= n; i++) { for (int j = 0; j < edges[i].size(); j++) { d[edges[i].get(j)[0]]++; } } List<Integer> list = new ArrayList<>(); for (int i = 1; i <= n; i++) { if (d[i] == 0) { list.add(i); } } for (int i = 0; i < list.size(); i++) { for (int j = 0; j < edges[list.get(i)].size(); j++) { int t = edges[list.get(i)].get(j)[0]; d[t]--; if (d[t] == 0) { list.add(t); } } } return list.size() == n; } //Binary tree class TreeNode { int val; int tier = -1; TreeNode parent; TreeNode left; TreeNode right; TreeNode(int val) { this.val = val; } } //binary tree dfs void tierTree(TreeNode root) { if (null == root) { return; } if (null != root.parent) { root.tier = root.parent.tier + 1; } else { root.tier = 0; } tierTree(root.left); tierTree(root.right); } //LCA start TreeNode[][] lca; TreeNode[] tree; void lcaDfsTree(TreeNode root) { if (null == root) { return; } tree[root.val] = root; TreeNode nxt = root.parent; int idx = 0; while (null != nxt) { lca[root.val][idx] = nxt; nxt = lca[nxt.val][idx]; idx++; } lcaDfsTree(root.left); lcaDfsTree(root.right); } TreeNode lcaTree(TreeNode root, int n, TreeNode x, TreeNode y) { if (null == root) { return null; } if (-1 == root.tier) { tree = new TreeNode[n + 1]; tierTree(root); } if (null == lca) { lca = new TreeNode[n + 1][31]; lcaDfsTree(root); } int z = Math.abs(x.tier - y.tier); int xx = x.tier > y.tier ? x.val : y.val; while (z > 0) { final int zz = z; int l = (int) binSearch(0, 31 , k -> zz < (1 << k)); xx = lca[xx][l].val; z -= 1 << l; } int yy = y.val; if (x.tier <= y.tier) { yy = x.val; } while (xx != yy) { final int xxx = xx; final int yyy = yy; int l = (int) binSearch(0, 31 , k -> (1 << k) <= tree[xxx].tier && lca[xxx][(int) k] != lca[yyy][(int) k]); xx = lca[xx][l].val; yy = lca[yy][l].val; } return tree[xx]; } //LCA end //graph List<int[]> edges[]; void initGraph(int n, int m, boolean hasW, boolean directed) throws IOException { edges = new List[n + 1]; for (int i = 1; i <= n; i++) { edges[i] = new ArrayList<>(); } for (int i = 0; i < m; i++) { int f = nextInt(); int t = nextInt(); int w = hasW ? nextInt() : 0; edges[f].add(new int[]{t, w}); if (!directed) { edges[t].add(new int[]{f, w}); } } } long binSearch(long l, long r, BinSearch sort) { while (l < r) { long m = l + (r - l) / 2; if (sort.binSearchCmp(m)) { l = m + 1; } else { r = m; } } return l; } void getDiv(Map<Integer, Integer> map, int n) { int sqrt = (int) Math.sqrt(n); for (int i = sqrt; i >= 2; i--) { if (n % i == 0) { getDiv(map, i); getDiv(map, n / i); return; } } map.put(n, map.getOrDefault(n, 0) + 1); } boolean[] generatePrime(int n) { boolean p[] = new boolean[n + 1]; p[2] = true; for (int i = 3; i <= n; i += 2) { p[i] = true; } for (int i = 3; i <= Math.sqrt(n); i += 2) { if (!p[i]) { continue; } for (int j = i * i; j <= n; j += i << 1) { p[j] = false; } } return p; } boolean isPrime(long n) { //determines if n is a prime number int p[] = {2, 3, 5, 233, 331}; int pn = p.length; long s = 0, t = n - 1;//n - 1 = 2^s * t while ((t & 1) == 0) { t >>= 1; ++s; } for (int i = 0; i < pn; ++i) { if (n == p[i]) { return true; } long pt = pow(p[i], t, n); for (int j = 0; j < s; ++j) { long cur = llMod(pt, pt, n); if (cur == 1 && pt != 1 && pt != n - 1) { return false; } pt = cur; } if (pt != 1) { return false; } } return true; } long llMod(long a, long b, long mod) { return (a * b - (long) ((double) a / mod * b + 0.5) * mod + mod) % mod; // long r = 0; // a %= mod; // b %= mod; // while (b > 0) { // if ((b & 1) == 1) { // r = (r + a) % mod; // } // b >>= 1; // a = (a << 1) % mod; // } // return r; } long pow(long a, long n) { long ans = 1; while (n > 0) { if ((n & 1) == 1) { ans = ans * a; } a = a * a; n >>= 1; } return ans; } long pow(long a, long n, long mod) { long ans = 1; while (n > 0) { if ((n & 1) == 1) { ans = llMod(ans, a, mod); } a = llMod(a, a, mod); n >>= 1; } return ans; } private long[][] initC(int n) { long c[][] = new long[n][n]; for (int i = 0; i < n; i++) { c[i][0] = 1; } for (int i = 1; i < n; i++) { for (int j = 1; j <= i; j++) { c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; } } return c; } /** * ps: n >= m, choose m from n; */ private int cmn(long n, long m) { if (m > n) { n ^= m; m ^= n; n ^= m; } m = Math.min(m, n - m); long top = 1; long bot = 1; for (long i = n - m + 1; i <= n; i++) { top = (top * i) % MOD; } for (int i = 1; i <= m; i++) { bot = (bot * i) % MOD; } return (int) ((top * pow(bot, MOD - 2, MOD)) % MOD); } long gcd(long a, long b) { if (a < b) { return gcd(b, a); } while (b != 0) { long tmp = a % b; a = b; b = tmp; } return a; } boolean isEven(long n) { return (n & 1) == 0; } interface BinSearch { boolean binSearchCmp(long k); } } private static class InOut { private BufferedReader br; private StreamTokenizer st; private PrintWriter pw; InOut() { br = new BufferedReader(new InputStreamReader(System.in)); st = new StreamTokenizer(br); pw = new PrintWriter(new OutputStreamWriter(System.out)); st.ordinaryChar('\''); st.ordinaryChar('\"'); st.ordinaryChar('/'); } private long[] anLong(int n) throws IOException { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } private String next(int len) throws IOException { char ch[] = new char[len]; int cur = 0; char c; while ((c = (char) br.read()) == '\n' || c == '\r' || c == ' ' || c == '\t') ; do { ch[cur++] = c; } while (!((c = (char) br.read()) == '\n' || c == '\r' || c == ' ' || c == '\t')); return String.valueOf(ch, 0, cur); } private int nextInt() throws IOException { st.nextToken(); return (int) st.nval; } private long nextLong(int n) throws IOException { return Long.parseLong(next(n)); } private double nextDouble() throws IOException { st.nextToken(); return st.nval; } private String[] nextSS(String reg) throws IOException { return br.readLine().split(reg); } private String nextLine() throws IOException { return br.readLine(); } private void print(String s, boolean newLine) { if (null != s) { pw.print(s); } if (newLine) { pw.println(); } } private void format(String format, Object... obj) { pw.format(format, obj); } private void flush() { pw.flush(); } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
571b0b33a9f8e0e3f008eded0ca3713b
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.*; import java.io.*; public class CF1354C1 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int i = 0; i < t; i++) System.out.println(1 / Math.tan(Math.PI / (2 * in.nextInt()))); } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
fcd121e9f0e1947bfa7eef02767eb330
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.io.*; import java.util.*; /** * User :- sudhakar * Date :- 19/05/20 * Time :- 1:25 PM */ public class SimplePolygonEmbedding { static final int MOD = 1000000007; /*Inner class for fast input*/ static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public String nextString() throws IOException { byte c = read(); while (Character.isWhitespace(c)) { c = read(); } StringBuilder builder = new StringBuilder(); builder.append((char) c); c = read(); while (!Character.isWhitespace(c)) { builder.append((char) c); c = read(); } return builder.toString(); } public char nextChar() throws IOException { byte c = read(); while (Character.isWhitespace(c)) { c = read(); } return (char) c; } 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; } public int[] nextIntArray(Reader r, int size) throws IOException { int[] arr = new int[size + 1]; for (int i = 1; i <= size; i++) arr[i] = r.nextInt(); return arr; } public long[] nextLongArray(Reader r, int size) throws IOException { long[] arr = new long[size + 1]; for (int i = 1; i <= size; i++) arr[i] = r.nextLong(); return arr; } 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(); } } private static double min(double a, double b) { return Math.min(a, b); } private static double max(double a, double b) { return Math.max(a, b); } public static void main(String[] args) throws IOException { Reader r = new Reader(); int T = r.nextInt(); while (T-- > 0) { double n = 2 * r.nextInt(); double ia = ((n-2)/n)*180; double ea = 180-ia; double temp=0; double tea = ea; while (tea<90){ temp+= Math.cos(Math.toRadians(tea)); tea += ea; } System.out.println(2*temp +1); } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
4e1b02bb98169d8cb4a68467be2d782d
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); C1SimplePolygonEmbedding solver = new C1SimplePolygonEmbedding(); solver.solve(1, in, out); out.close(); } static class C1SimplePolygonEmbedding { public void solve(int testNumber, InputReader in, PrintWriter out) { int t = in.nextInt(); for (int i = 0; i < t; i++) { solve(in, out); } } private void solve(InputReader in, PrintWriter out) { double n = in.nextInt(); double angle = Math.PI / (2 * n); double answer = 1 / Math.tan(angle); out.println(Util.formatDouble(answer)); } } static class InputReader { public final 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()); } } static class Util { public static String formatDouble(double x) { return String.format("%.15f", x); } private Util() { } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
049dd699d7219f5296ee17c78d8cdbea
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.SortedSet; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; /** * # * * @author pttrung */ public class C1_Edu_Round_87 { public static long MOD = 1000000007; public static void main(String[] args) throws FileNotFoundException { // PrintWriter out = new PrintWriter(new FileOutputStream(new File( // "output.txt"))); PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(); int T = in.nextInt(); for(int z = 0; z < T; z++){ int n = in.nextInt(); double degree = Math.PI/(2*n); //System.out.println(Math.toDegrees(degree)); double l = 1/Math.tan(degree); out.println(l); } out.close(); } public static int[] KMP(String val) { int i = 0; int j = -1; int[] result = new int[val.length() + 1]; result[0] = -1; while (i < val.length()) { while (j >= 0 && val.charAt(j) != val.charAt(i)) { j = result[j]; } j++; i++; result[i] = j; } return result; } public static boolean nextPer(int[] data) { int i = data.length - 1; while (i > 0 && data[i] < data[i - 1]) { i--; } if (i == 0) { return false; } int j = data.length - 1; while (data[j] < data[i - 1]) { j--; } int temp = data[i - 1]; data[i - 1] = data[j]; data[j] = temp; Arrays.sort(data, i, data.length); return true; } public static int digit(long n) { int result = 0; while (n > 0) { n /= 10; result++; } return result; } public static double dist(long a, long b, long x, long y) { double val = (b - a) * (b - a) + (x - y) * (x - y); val = Math.sqrt(val); double other = x * x + a * a; other = Math.sqrt(other); return val + other; } public static class Point implements Comparable<Point> { int x, y; public Point(int start, int end) { this.x = start; this.y = end; } @Override public int hashCode() { int hash = 5; hash = 47 * hash + this.x; hash = 47 * hash + this.y; return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Point other = (Point) obj; if (this.x != other.x) { return false; } if (this.y != other.y) { return false; } return true; } @Override public int compareTo(Point o) { return Integer.compare(x, o.x); } } public static class FT { long[] data; FT(int n) { data = new long[n]; } public void update(int index, long value) { while (index < data.length) { data[index] += value; index += (index & (-index)); } } public long get(int index) { long result = 0; while (index > 0) { result += data[index]; index -= (index & (-index)); } return result; } } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } public static long pow(long a, int b) { if (b == 0) { return 1; } if (b == 1) { return a; } long val = pow(a, b / 2); if (b % 2 == 0) { return val * val; } else { return val * (val * a); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() throws FileNotFoundException { // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true)); br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { st = null; try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(); } } public boolean endLine() { try { String next = br.readLine(); while (next != null && next.trim().isEmpty()) { next = br.readLine(); } if (next == null) { return true; } st = new StringTokenizer(next); return st.hasMoreTokens(); } catch (Exception e) { throw new RuntimeException(); } } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
c3b0b9f36e88a8b23d8cc54402becb0c
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.*; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.util.Scanner; import java.util.StringTokenizer; import java.util.TreeMap; public class temp { void solve() throws IOException { FastReader sc=new FastReader(); int t = sc.nextInt(); while(t-->0) { int n = 2*sc.nextInt(); double ans = 1.0/Math.tan(Math.PI/n); System.out.println(ans); } } public static void main(String[] args) throws IOException { // TODO Auto-generated method stub new temp().solve(); } 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\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
d49e75ce27198cde19a8d59069dd480c
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Polygon { int n; public Polygon(int n) { this.n = n; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); for (int i = 0; i < N; i++) { int n = scan.nextInt(); Polygon p = new Polygon(n); System.out.println(p.solve()); } } public double solve() { if (n == 2) { return 1.00; } int c = n / 2 - 1; double l = 1.00; for (int i = 1; i <= c; i++) { l += Math.cos((Math.PI / 2.0 /(c+1)) * i) * 2; } return l; } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
444fd1c7250a58060d24721f4e9bff9a
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Solution{ 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 ni() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t>0) { double n=s.nextDouble(); double l=4*n; double k=360/l; k=Math.toRadians(k); double ans=Math.tan(k); System.out.println(1/ans); t--; } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
f701004988112f8dae917cdb9cf36f40
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class C { public static class pair implements Comparable<pair> { int id; int ans; pair(int x, int y) { id = x; ans = y; } public pair() { } public int compareTo(pair o) { // TODO Auto-generated method stub return this.ans - o.ans; } } // static int mod = (int) 998244353.; static int mod=(int)1e9+7; static ArrayList<Integer> gr[]; static int ar[]; static Scanner sc = new Scanner(System.in); static int pri[] = new int[(int) 1e6 + 5]; static StringBuilder out = new StringBuilder(); static int[] dp; public static void main(String[] args) throws IOException { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); double x = Math.PI / (2 * n); double ans = Math.sin(x); ans = 1 / ans; double s = (Math.sqrt(ans * ans - 1.0)); out.append(s+"\n"); } System.out.println(out); } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
d5e397671389a81a0c13a11919429a24
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.Scanner; public class C1354 { public static void main(String[] args) throws IOException{ Scanner scanner = new Scanner(System.in); int cases = scanner.nextInt(); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); for(int i = 0; i< cases; i++) { double sides = scanner.nextInt() * 2; double ans = 1d / Math.tan(Math.PI / sides); log.write("" + ans + "\n"); } log.flush(); } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
e5123a3e337f1eb544da1fc14d6f6306
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
/* ⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿ ⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿ ⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿ ⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿ ⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿ ⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿ ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿ ⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿ ⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿ ⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺ ⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘ ⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆ ⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇ ⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇ ⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇ ⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇ ⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇ ⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀ ⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀ ⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸ ⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼ ⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿ ⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿ ⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿ ⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿ */ import java.awt.List; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int ie=0;ie<t;ie++) { double n=s.nextDouble(); n=2d* n; System.out.println(1d/(Math.tan(Math.toRadians(((360d/(2*n))))))); } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
eaa843dc3e57282209d5bfa4ccc7f0df
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
/* ⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿ ⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿ ⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿ ⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿ ⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿ ⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿ ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿ ⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿ ⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿ ⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺ ⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘ ⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆ ⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇ ⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇ ⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇ ⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇ ⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇ ⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀ ⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀ ⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸ ⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼ ⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿ ⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿ ⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿ ⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿ */ import java.awt.List; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int ie=0;ie<t;ie++) { double n=s.nextDouble(); n=2d* n; System.out.println((Math.tan(Math.toRadians((180d-(360d/n))/2d)))); } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
8baa83df3434c6d1e018dbc107a0109c
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.Locale; import java.util.Scanner; public class C1354 { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int t=0; t<T; t++) { int n = in.nextInt(); int sides = 2*n; double answer; if (sides%4 == 0) { answer = squareSize(sides, Math.PI/sides); } else { answer = squareSize(sides, Math.PI/2 + Math.PI/sides); } System.out.println(answer); } } static double squareSize(int sides, double rotation) { double r = 1/(2*Math.sin(Math.PI/sides)); double minx = Double.MAX_VALUE; double maxx = Double.MIN_VALUE; double miny = Double.MAX_VALUE; double maxy = Double.MIN_VALUE; for (int n=0; n<sides; n++) { double alpha = rotation + n*2*Math.PI/sides; double x = r*Math.cos(alpha); double y = r*Math.sin(alpha); minx = Math.min(minx, x); maxx = Math.max(maxx, x); miny = Math.min(miny, y); maxy = Math.max(maxy, y); } double side = Math.max(maxy-miny, maxx-minx); return side; } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
be0294b6d8e3f01880e177e4d28955d6
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.Locale; import java.util.Scanner; public class C1354 { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int t=0; t<T; t++) { int n = in.nextInt(); int sides = 2*n; double answer; if (n%2 == 0) { answer = squareSize(sides, Math.PI/sides); } else { answer = squareSize(sides, Math.PI/4); } System.out.println(answer); } } static double squareSize(int sides, double rotation) { double r = 1/(2*Math.sin(Math.PI/sides)); double minx = Double.MAX_VALUE; double maxx = Double.MIN_VALUE; double miny = Double.MAX_VALUE; double maxy = Double.MIN_VALUE; for (int n=0; n<sides; n++) { double alpha = rotation + n*2*Math.PI/sides; double x = r*Math.cos(alpha); double y = r*Math.sin(alpha); minx = Math.min(minx, x); maxx = Math.max(maxx, x); miny = Math.min(miny, y); maxy = Math.max(maxy, y); } double side = Math.max(maxy-miny, maxx-minx); return side; } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
b2a04bda136946304c6cea15902989a5
train_001.jsonl
1589707200
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.
256 megabytes
import java.util.*; import java.io.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int tc=sc.nextInt(); while(tc-->0){ int n=sc.nextInt(); double d=1.0/Math.tan(Math.PI/(2.0*n)); System.out.printf("%.9f",d); System.out.println(); } } }
Java
["3\n2\n4\n200"]
2 seconds
["1.000000000\n2.414213562\n127.321336469"]
null
Java 8
standard input
[ "binary search", "geometry", "ternary search", "math" ]
0c7a476716445c535a61f4e81edc7f75
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
1,400
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
standard output
PASSED
ab06199d35005de44eb3914c57fb1f26
train_001.jsonl
1492356900
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; public class C801{ void solve() { int n = ni(), p = ni(); int[] a = new int[n]; int[] b = new int[n]; for(int i=0;i<n;i++) { a[i] = ni(); b[i] = ni(); } long sum = 0; for(int k : a) sum += k; if(sum <= p) { out.println(-1); return; } double l = 0, r = 1e18; for(int rep=0;rep<500;rep++) { double mid = (l + r)/2; double req = 0; long sum1 = 0, sum2 = 0; for(int i=0;i<n;i++) { if(mid*a[i] - b[i] > 0) { sum1 += a[i]; sum2 += b[i]; } } req = (mid * sum1 - sum2)/mid; if(req < p) l = mid; else r = mid; } out.printf("%.12f", l); } public static void main(String[] args){new C801().run();} private byte[] bufferArray = new byte[1024]; private int bufLength = 0; private int bufCurrent = 0; InputStream inputStream; PrintWriter out; public void run() { inputStream = System.in; out = new PrintWriter(System.out); solve(); out.flush(); } int nextByte() { if(bufLength==-1) throw new InputMismatchException(); if(bufCurrent>=bufLength) { bufCurrent = 0; try {bufLength = inputStream.read(bufferArray);} catch(IOException e) { throw new InputMismatchException();} if(bufLength<=0) return -1; } return bufferArray[bufCurrent++]; } boolean isSpaceChar(int x) {return (x<33 || x>126);} boolean isDigit(int x) {return (x>='0' && x<='9');} int nextNonSpace() { int x; while((x=nextByte())!=-1 && isSpaceChar(x)); return x; } int ni() { long ans = nl(); if ( Integer.MIN_VALUE <= ans && ans <= Integer.MAX_VALUE ) return (int)ans; throw new InputMismatchException(); } long nl() { long ans = 0; boolean neg = false; int x = nextNonSpace(); if(x=='-') { neg = true; x = nextByte(); } while(!isSpaceChar(x)) { if(isDigit(x)) { ans = ans*10 + x -'0'; x = nextByte(); } else throw new InputMismatchException(); } return neg ? -ans:ans; } String ns() { StringBuilder sb = new StringBuilder(); int x = nextNonSpace(); while(!isSpaceChar(x)) { sb.append((char)x); x = nextByte(); } return sb.toString(); } char nc() { return (char)nextNonSpace();} double nd() { return (double)Double.parseDouble(ns()); } char[] ca() { return ns().toCharArray();} char[] ca(int n) { char[] ans = new char[n]; int p =0; int x = nextNonSpace(); while(p<n) { ans[p++] = (char)x; x = nextByte(); } return ans; } int[] ia(int n) { int[] ans = new int[n]; for(int i=0;i<n;i++) ans[i]=ni(); return ans; } }
Java
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
2 seconds
["2.0000000000", "-1", "0.5000000000"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
Java 8
standard input
[ "binary search", "greedy" ]
1c2fc9449989d14d9eb02a390f36b7a6
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
1,800
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
standard output
PASSED
777ac960e1d3d645300cbf926ea54124
train_001.jsonl
1492356900
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.stream.IntStream; import java.io.OutputStream; import java.util.Arrays; import java.util.stream.LongStream; import java.io.IOException; import java.util.stream.DoubleStream; import java.io.UncheckedIOException; import java.math.BigDecimal; 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 << 27); 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); AVoltageKeepsake solver = new AVoltageKeepsake(); solver.solve(1, in, out); out.close(); } } static class AVoltageKeepsake { public void solve(int testNumber, FastInput in, FastOutput out) { int n = in.readInt(); int p = in.readInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.readInt(); b[i] = in.readInt(); } long sum = Arrays.stream(a).mapToLong(Long::valueOf).sum(); if (sum <= p) { out.println(-1); return; } double[] cost = new double[n]; DoubleBinarySearch dbs = new DoubleBinarySearch(1e-12, 1e-12) { public boolean check(double mid) { for (int i = 0; i < n; i++) { cost[i] = Math.max(0, a[i] - b[i] / mid); } double req = Arrays.stream(cost).sum(); return req >= p; } }; double ans = dbs.binarySearch(0, 1e20); out.println(ans); } } static class FastOutput implements AutoCloseable, Closeable, Appendable { private StringBuilder cache = new StringBuilder(10 << 20); private final Writer os; 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; } public FastOutput(Writer os) { this.os = os; } public FastOutput(OutputStream os) { this(new OutputStreamWriter(os)); } public FastOutput append(char c) { cache.append(c); return this; } public FastOutput append(int c) { cache.append(c); return this; } public FastOutput append(double c) { cache.append(new BigDecimal(c).toPlainString()); return this; } public FastOutput println(int c) { return append(c).println(); } public FastOutput println(double c) { return append(c).println(); } public FastOutput println() { cache.append(System.lineSeparator()); return this; } 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 abstract class DoubleBinarySearch { private final double relativeErrorTolerance; private final double absoluteErrorTolerance; public DoubleBinarySearch(double relativeErrorTolerance, double absoluteErrorTolerance) { this.relativeErrorTolerance = relativeErrorTolerance; this.absoluteErrorTolerance = absoluteErrorTolerance; } public abstract boolean check(double mid); public double binarySearch(double l, double r) { if (l > r) { throw new IllegalArgumentException(); } while (r - l > absoluteErrorTolerance) { if ((r < 0 && (r - l) < -r * relativeErrorTolerance) || (l > 0 && (r - l) < l * relativeErrorTolerance)) { break; } double mid = (l + r) / 2; if (check(mid)) { r = mid; } else { l = mid; } } return (l + r) / 2; } } 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; } 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 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
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
2 seconds
["2.0000000000", "-1", "0.5000000000"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
Java 8
standard input
[ "binary search", "greedy" ]
1c2fc9449989d14d9eb02a390f36b7a6
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
1,800
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
standard output
PASSED
d05c37129e74d35aade39bab47d62afd
train_001.jsonl
1492356900
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.stream.IntStream; import java.io.OutputStream; import java.util.Arrays; import java.util.stream.LongStream; import java.io.IOException; import java.io.UncheckedIOException; import java.math.BigDecimal; 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 << 27); 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); AVoltageKeepsake solver = new AVoltageKeepsake(); solver.solve(1, in, out); out.close(); } } static class AVoltageKeepsake { public void solve(int testNumber, FastInput in, FastOutput out) { int n = in.readInt(); int p = in.readInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.readInt(); b[i] = in.readInt(); } long sum = Arrays.stream(a).mapToLong(Long::valueOf).sum(); if (sum <= p) { out.println(-1); return; } double[] cost = new double[n]; DoubleBinarySearch dbs = new DoubleBinarySearch(1e-12, 1e-12) { public boolean check(double mid) { for (int i = 0; i < n; i++) { cost[i] = Math.max(0, a[i] - b[i] / mid); } double req = DigitUtils.sum(i -> cost[i], 0, n - 1); return req >= p; } }; double ans = dbs.binarySearch(0, 1e20); out.println(ans); } } static interface IntToDoubleFunction { double apply(int x); } static class FastOutput implements AutoCloseable, Closeable, Appendable { private StringBuilder cache = new StringBuilder(10 << 20); private final Writer os; 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; } public FastOutput(Writer os) { this.os = os; } public FastOutput(OutputStream os) { this(new OutputStreamWriter(os)); } public FastOutput append(char c) { cache.append(c); return this; } public FastOutput append(int c) { cache.append(c); return this; } public FastOutput append(double c) { cache.append(new BigDecimal(c).toPlainString()); return this; } public FastOutput println(int c) { return append(c).println(); } public FastOutput println(double c) { return append(c).println(); } public FastOutput println() { cache.append(System.lineSeparator()); return this; } 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 DigitUtils { private DigitUtils() { } public static double sum(IntToDoubleFunction func, int l, int r) { double sum = 0; double err = 0; for (int i = l; i <= r; i++) { double x = func.apply(i) - err; double t = sum + x; err = (t - sum) - x; sum = t; } return sum; } } static abstract class DoubleBinarySearch { private final double relativeErrorTolerance; private final double absoluteErrorTolerance; public DoubleBinarySearch(double relativeErrorTolerance, double absoluteErrorTolerance) { this.relativeErrorTolerance = relativeErrorTolerance; this.absoluteErrorTolerance = absoluteErrorTolerance; } public abstract boolean check(double mid); public double binarySearch(double l, double r) { if (l > r) { throw new IllegalArgumentException(); } while (r - l > absoluteErrorTolerance) { if ((r < 0 && (r - l) < -r * relativeErrorTolerance) || (l > 0 && (r - l) < l * relativeErrorTolerance)) { break; } double mid = (l + r) / 2; if (check(mid)) { r = mid; } else { l = mid; } } return (l + r) / 2; } } 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; } 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 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
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
2 seconds
["2.0000000000", "-1", "0.5000000000"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
Java 8
standard input
[ "binary search", "greedy" ]
1c2fc9449989d14d9eb02a390f36b7a6
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
1,800
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
standard output
PASSED
eb86f11196020e5049c8c8ded47ab227
train_001.jsonl
1492356900
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; import java.util.stream.LongStream; import java.io.IOException; import java.io.UncheckedIOException; import java.math.BigDecimal; import java.util.stream.Stream; 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 << 27); 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); AVoltageKeepsake solver = new AVoltageKeepsake(); solver.solve(1, in, out); out.close(); } } static class AVoltageKeepsake { public void solve(int testNumber, FastInput in, FastOutput out) { int n = in.readInt(); int p = in.readInt(); Point[] pts = new Point[n]; for (int i = 0; i < n; i++) { pts[i] = new Point(); pts[i].a = in.readInt(); pts[i].b = in.readInt(); pts[i].threshold = pts[i].b / (double) pts[i].a; } long sum = Arrays.stream(pts).mapToLong(x -> x.a).sum(); if (sum <= p) { out.println(-1); return; } Arrays.sort(pts, (a, b) -> Double.compare(a.threshold, b.threshold)); long sumA = 0; long sumB = 0; double ans = pts[0].threshold; for (int i = 0; i < n; i++) { sumA += pts[i].a; sumB += pts[i].b; if (sumA <= p) { ans = Math.max(ans, pts[i + 1].threshold); } else { double local = (double) sumB / (sumA - p); if (i + 1 < n) { local = Math.min(local, pts[i + 1].threshold); } if (local >= pts[i].threshold) { ans = Math.max(ans, local); } } } out.println(ans); } } static class FastOutput implements AutoCloseable, Closeable, Appendable { private StringBuilder cache = new StringBuilder(10 << 20); private final Writer os; 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; } public FastOutput(Writer os) { this.os = os; } public FastOutput(OutputStream os) { this(new OutputStreamWriter(os)); } public FastOutput append(char c) { cache.append(c); return this; } public FastOutput append(int c) { cache.append(c); return this; } public FastOutput append(double c) { cache.append(new BigDecimal(c).toPlainString()); return this; } public FastOutput println(int c) { return append(c).println(); } public FastOutput println(double c) { return append(c).println(); } public FastOutput println() { cache.append(System.lineSeparator()); return this; } 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 Point { int a; int b; double threshold; } 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; } 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 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
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
2 seconds
["2.0000000000", "-1", "0.5000000000"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
Java 8
standard input
[ "binary search", "greedy" ]
1c2fc9449989d14d9eb02a390f36b7a6
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
1,800
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
standard output
PASSED
d4ca1eb8f578374d5f6155a06c7d3223
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); ProblemAMindTheGap solver = new ProblemAMindTheGap(); solver.solve(1, in, out); out.close(); } static class ProblemAMindTheGap { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(), g = in.nextInt(); int sh = 0, sm = 0, eh = 0, em = 0; for (int i = 0; i < n; i++) { eh = in.nextInt(); em = in.nextInt(); if (i == 0) { if (eh * 60 + em >= g + 1) { out.println(0 + " " + 0); return; } } else { if (eh * 60 + em >= sh * 60 + sm + 2 + 2 * g) { int ans = sh * 60 + sm + 1 + g; out.println(ans / 60 + " " + ans % 60); return; } } sh = eh; sm = em; } int ans = eh * 60 + em + 1 + g; out.println(ans / 60 + " " + ans % 60); } } 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 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
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
931513469da7311377bb03eb3e320b9f
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.util.*; public class problem967A { private static Scanner in = new Scanner(System.in); private static int n = 0, s = 0; private static ArrayList<Time> schedule = new ArrayList<Time>(); public static void main(String[] args) { n = in.nextInt(); s = in.nextInt(); for (int i = 0; i < n; i++) { Time time = new Time(in.nextInt(), in.nextInt()); schedule.add(time); } schedule.add(new Time(0, 0)); Collections.sort(schedule, new SortByTime()); // for (int i = 0; i < n + 1; i++) { // System.out.println(schedule.get(i).hour + " " + schedule.get(i).minute); // } if (insertInBeginning(schedule, s)) System.out.println(0 + " " + 0); else { for (int i = 0; i < n; i++) { // FIXME Time current = schedule.get(i); Time next = schedule.get(i + 1); int landingComplete = (current.hour * 60) + current.minute + 1; int nextLandingStart = (next.hour * 60) + next.minute; // System.out.println("LANDING COMPLETE: " + landingComplete); // System.out.println("NEXT LANDING START: " + nextLandingStart); if (((float)nextLandingStart - (float)landingComplete) / 2.0 > s) { // System.out.println((float)nextLandingStart - (float)landingComplete / 2.0 + "IS GREATER THAN" + s); // System.out.println("OPTIMAL TIME FOUND"); int optimalTime = landingComplete + s; System.out.print(optimalTime / 60); System.out.println(" " + optimalTime % 60); return; } } Time lastTime = schedule.get(n); // FIXME int landingComplete = (lastTime.hour * 60) + lastTime.minute + 1; int optimalTime = landingComplete + s; System.out.print(optimalTime / 60); System.out.println(" " + optimalTime % 60); } } public static boolean insertInBeginning(ArrayList<Time> time, int s) { int timeOfQuestion = (time.get(0).hour * 60) + time.get(0).minute + s; int nextTime = (time.get(1).hour * 60) + time.get(1).minute; return nextTime > timeOfQuestion; } } class Time { int hour; int minute; Time(int hour, int minute) { this.hour = hour; this.minute = minute; } } class SortByTime implements Comparator<Time> { public int compare(Time o1, Time o2) { if (o1.hour == o2.hour) { return o1.minute - o2.minute; } else return o1.hour - o2.hour; } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
8647a6a2dcd4f1cd02a56ce81ac00ce7
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.util.*; public class ContestA { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int diff = m+1; int a = 0; for(int i=0;i<n;i++){ int s = in.nextInt()*60+in.nextInt(); if(s-a>=diff){ break; }else{ a = s+m+1; } } System.out.println((a/60) +" "+(a%60)); in.close(); } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
592284735b0145aa0f177242739c0a17
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; public class JavaApplication6 { public static void main(String[] args) throws IOException { in.init(System.in); StringTokenizer st=new StringTokenizer(in.nextLine()); int n=Integer.parseInt(st.nextToken()); int s=Integer.parseInt(st.nextToken()); ArrayList<Integer> a1=new ArrayList<>(); while(n>0){ st=new StringTokenizer(in.nextLine()); int z=Integer.parseInt(st.nextToken()); int w=z*60; int y=Integer.parseInt(st.nextToken()); a1.add(y+w); n--; } boolean ww=false; int sol=0;int q=0; for (int i = 0; i <a1.size(); i++) {//80 //201 s=60 if(i!=0){ if(i!=a1.size()-1){//7 100 115 q=a1.get(i)+s+1; //q 141 if(q<a1.get(i+1) && a1.get(i+1)-q>s) {;sol=q;break;} } else{ q=a1.get(a1.size()-2)+s+1; if(q<a1.get(a1.size()-1) && a1.get(a1.size()-1)-q>s) sol=q; } } else{ q=s+1; if(a1.get(i)>=q) {;sol=0; ww=true; break;} else if(a1.size()!=1){ q=a1.get(i)+s+1; if(q<a1.get(i+1) && a1.get(i+1)-q>s) {;sol=q;break;} } } } if(sol!=0 || ww==true){ System.out.println(sol/60+" "+sol%60); } else{ int u=a1.get(a1.size()-1)+s+1; System.out.println(u/60+" "+u%60);} }} class in { public static BufferedReader br; public static StringTokenizer st; static void init(InputStream input){ br=new BufferedReader(new InputStreamReader(input)); st=new StringTokenizer(" "); } static String nextLine() throws IOException{ return br.readLine(); } static String next() throws IOException{ while(!st.hasMoreTokens()){ st=new StringTokenizer(br.readLine()); }return st.nextToken(); } static boolean hasNext(){ return st.hasMoreTokens(); } static int nextInt() throws IOException{ return Integer.parseInt(next()); } static double nextDouble() throws IOException{ return Double.parseDouble(next()); } static float nextfloat() throws IOException{ return Float.parseFloat(next()); } static long nextlong() throws IOException{ return Long.parseLong(next()); } static short nextShort() throws IOException{ return Short.parseShort(next()); } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
f7f877c8d4c1bd6bfa27fe5a36f6ac57
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class MainClass { public static void main(String[] args) throws IOException { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int n=in.nextInt(); int s=in.nextInt(); int oh=0,om=0; boolean flag=false; int ansm=0; int ansh=0; int nh=in.nextInt(); int nm=in.nextInt(); int gap = nm + (nh)*60; if(gap>=s+1) { flag=true; } oh=nh; om=nm; for(int i=1;i<n;i++) { nh=in.nextInt(); nm=in.nextInt(); gap = nm+ (60-om)+ (nh-oh-1)*60; if(!flag && gap>=s+s+2) { ansm= (om + 1 + s)%60; ansh= oh + (om + 1 + s)/60; flag=true; } oh=nh; om=nm; } if(!flag) { ansm= (om + 1 + s)%60; ansh= oh + (om + 1 + s)/60; } out.println(ansh+" "+ansm); out.flush(); out.close(); } } class InputReader{ private final InputStream stream; private final byte[] buf=new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream){this.stream=stream;} public int read()throws IOException{ if(curChar>=numChars){ curChar=0; numChars=stream.read(buf); if(numChars<=0) return -1; } return buf[curChar++]; } public final int nextInt()throws IOException{return (int)nextLong();} public final long nextLong()throws IOException{ int c=read(); while(isSpaceChar(c)){ c=read(); if(c==-1) throw new IOException(); } boolean negative=false; if(c=='-'){ negative=true; 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 negative?(-res):(res); } public final int[] readIntBrray(int size)throws IOException{ int[] arr=new int[size]; for(int i=0;i<size;i++)arr[i]=nextInt(); return arr; } public final String next()throws IOException{ int c=read(); while(isSpaceChar(c))c=read(); StringBuilder res=new StringBuilder(); do{ res.append((char)c); c=read(); }while(!isSpaceChar(c)); return res.toString(); } public final String nextLine()throws IOException{ int c=read(); while(isSpaceChar(c))c=read(); StringBuilder res=new StringBuilder(); do{ res.append((char)c); c=read(); }while(c!='\n'&&c!=-1); return res.toString(); } private boolean isSpaceChar(int c){ return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1; } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
39b4fc1a5e1d43ee0bdaa9344f990621
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
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 Jeong Juhyeon */ 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) { int curHour = 0; int curMin = 0; int nextHour, nextMin; int noLandings, minGap; noLandings = in.nextInt(); minGap = in.nextInt(); nextHour = in.nextInt(); nextMin = in.nextInt(); if (nextHour * 60 + nextMin >= minGap + 1) { out.println("0 0"); return; } curHour = nextHour; curMin = nextMin; for (int i = 0; i < noLandings - 1; i++) { nextHour = in.nextInt(); nextMin = in.nextInt(); if (nextHour * 60 + nextMin - curHour * 60 - curMin >= 2 * minGap + 2) { int takeoffMin = curHour * 60 + curMin + minGap + 1; out.printf("%d %d", takeoffMin / 60, takeoffMin % 60); return; } curHour = nextHour; curMin = nextMin; } int takeoffMin = curHour * 60 + curMin + minGap + 1; out.printf("%d %d", takeoffMin / 60, takeoffMin % 60); } } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
a43f5297becd119c5a86aa3d2fc63e97
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; /** * * @author Simone Vuotto */ public class A { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int s = scanner.nextInt(); int[] time = new int[n]; for(int i = 0; i < n; ++i) { int h = scanner.nextInt(); int m = scanner.nextInt(); time[i] = h * 60 + m; } int currentTime = time[0]; if(currentTime >= s + 1) { printTime(0); System.exit(0); } for(int i = 1; i < n; ++i) { int diff = time[i] - currentTime; if(diff >= 2*(s + 1)) { break; } else { currentTime = time[i]; } } printTime(currentTime + s + 1); } public static void printTime(int minutes) { int h = minutes / 60; int m = minutes % 60; System.out.println(h + " " + m); } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
65dd9878d908a86031a524890b286ff3
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.util.Scanner; public class Solution1 { int N; int S; public static void main(String[] args) { Scanner sc = new Scanner(System.in); Solution1 tr = new Solution1(); tr.test(sc); sc.close(); } void test(Scanner sc){ N = sc.nextInt(); S = sc.nextInt(); int input[] = new int[N]; for (int i = 0; i < input.length; i++) { int hr = sc.nextInt(); int min =sc.nextInt(); input[i] = hr*60+min; } if(input[0] >= S+1){ System.out.println(0 +" "+ 0); return; } for (int i = 1; i < input.length; i++) { int diff = input[i] - input[i-1]; if(diff >= 2 * S + 2){ int ansmin = input[i-1] + 1+S; System.out.println(ansmin/60 +" " +ansmin%60); return; } } int ansmin = input[N-1]+1+S; System.out.println(ansmin/60 +" " +ansmin%60); } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
1b1d4425038ec7e04ee426fe33e73684
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.util.Scanner; public class Solution { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int s = sc.nextInt(); int time=0; int ans=-1; for(int i=0;i<n;i++) { int h = sc.nextInt(); int m = sc.nextInt(); int value = h*60 + m; if(i==0) { if(value>=(s+1)) { ans = time; break; } } else { if((value-time)>=(2+2*s)) { ans=(time+s+1); break; } } time = value; } if(ans==-1) { ans = (time+s+1); } System.out.println(ans/60 + " " + ans%60); sc.close(); } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
bb081a158d69913d2ec4170c9ebaa3b5
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.io.*; import java.util.*; public class MindTheGap { public static void main (String[] args) throws Exception { Scanner in = new Scanner(System.in); int n = in.nextInt(); int s = in.nextInt(); int[] time = new int[n]; for (int i = 0; i < n; i++) { int h = in.nextInt(); int m = in.nextInt(); time[i] = h * 60 + m; } int ans = -1; int last = -s - 1; for (int i = 0; i < n; i++) { if (last + 2 * s + 1 < time[i]) { ans = last + s + 1; break; } last = time[i]; } if (ans == -1) { ans = last + s + 1; } System.out.println(ans / 60 + " " + ans % 60); } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
65aa8a226533a2a1dbb2d5996d63adb1
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.io.*; public class CFR477A { static int n, s, h[] = new int[101], m[] = new int[101], t[] = new int[101], ans = -1; static String ins[]; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); ins = br.readLine().split(" "); n = Integer.parseInt(ins[0]); s = Integer.parseInt(ins[1]); for (int i = 0; i < n; i++) { ins = br.readLine().split(" "); h[i] = Integer.parseInt(ins[0]); m[i] = Integer.parseInt(ins[1]); t[i] = timeToMin(h[i], m[i]); } for (int i = 0; i < n - 1; i++) { if (t[i + 1] - t[i] >= (s << 1) + 2) { ans = t[i] + s + 1;break; } } ans = (ans == -1) ? t[n - 1] + s + 1 : ans; ans = (t[0] > s) ? 0 : ans; bw.write(minToTime(ans)); bw.flush();bw.close(); } private static String minToTime(int m) { return (m / 60) + " " + (m % 60) + "\n"; } private static int timeToMin(int h, int m) { return h * 60 + m; } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
95039ba40e22003487abb23af6924750
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.text.DecimalFormat; import java.io.*; import java.util.*; import java.math.*; public class Main{ static InputReader in=new InputReader(System.in); static Scanner inn = new Scanner(System.in); static PrintWriter out=new PrintWriter(System.out); static int m=0,n=0; static int[] hour=new int[110]; static int[] min=new int[110]; static int[] time=new int[110]; static boolean cxz=false; public static void main(String[] args)throws IOException{ n=in.nextInt(); m=in.nextInt(); hour[0]=0; min[0]=-1; hour[1]=in.nextInt(); min[1]=in.nextInt(); time[1]=hour[1]*60+min[1]; if(time[1]>=m+1) { System.out.println(0+" "+0); cxz=true; } for(int i=2;i<=n;++i) { hour[i]=in.nextInt(); min[i]=in.nextInt(); time[i]=60*hour[i]+min[i]; if(!cxz&&time[i]-time[i-1]>=2*m+2) { int ansh=(time[i-1]+m+1)/60; int ansm=(time[i-1]+m+1)%60; System.out.println(ansh+" "+ansm); cxz=true; } } if(!cxz) { int ansh=(time[n]+m+1)/60; int ansm=(time[n]+m+1)%60; System.out.println(ansh+" "+ansm); } } static int min(int a,int b) { return a<b? a:b; } static int max(int a,int b) { return a>b? a:b; } static class InputReader { BufferedReader br; public InputReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); } public String nextLine() throws IOException{ String c = null; c=br.readLine(); return c; } public int nextInt() throws IOException { int c = br.read(); while (c <= 32) { c = br.read(); } boolean negative = false; if (c == '-') { negative = true; c = br.read(); } int x = 0; while (c > 32) { x = x * 10 + c - '0'; c = br.read(); } return negative ? -x : x; } public long nextLong() throws IOException { int c = br.read(); while (c <= 32) { c = br.read(); } boolean negative = false; if (c == '-') { negative = true; c = br.read(); } long x = 0; while (c > 32) { x = x * 10 + c - '0'; c = br.read(); } return negative ? -x : x; } public String next() throws IOException { int c = br.read(); while (c <= 32) { c = br.read(); } StringBuilder sb = new StringBuilder(); while (c > 32) { sb.append((char) c); c = br.read(); } return sb.toString(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
2ee6f83a24c52e5999fbbaf2945c5d07
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.util.*; public class A967_MindTheGap { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt(); int s = sc.nextInt(); int[] arr = new int[n]; for (int i=0; i<n; i++) { int hour = sc.nextInt(); int min = sc.nextInt(); arr[i] = hour*60+min; } int result = 0; result = check(arr, n, s); System.out.println(result/60 + " " + result%60); } static public int check(int[] arr, int n, int s) { if (arr[0]>s) return 0; for (int i=1; i<n; i++) { // System.out.println(arr[i]-arr[i-1]); if (arr[i]-arr[i-1]>=2*s+2) return arr[i-1]+s+1; } if (24*60-arr[n-1] >= s) return arr[n-1]+s+1; return arr[n-1]+s+1; } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
7bdea1315cdbe8b0b5be2300fec5d8f5
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.PriorityQueue; import java.util.StringTokenizer; public class B{ public static void main(String args[]) throws IOException { Scanner sc=new Scanner (System.in); int n=sc.nextInt(); int arr[]=new int [n]; int min=sc.nextInt()*2; for(int i=0;i<n;i++) { arr[i]=sc.nextInt()*60+sc.nextInt(); } // Arrays.sort(arr); if(min/2+1<=arr[0] ) { System.out.println("0"+" "+"0"); return; } for(int i=0;i<n-1;i++) { int m=arr[i+1]-arr[i]; // System.out.println(arr[i]); if(m>=min+2) { int res=arr[i]+(min/2)+1; System.out.println(res/60+" "+res%60); return; } } int res=arr[n-1]+min/2+1; System.out.println(res/60+" "+res%60); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine(), ",| "); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public boolean ready() throws IOException {return br.ready();} 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); } } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
4dfd6dd7212b70affb458be17a2b466a
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; public class test{ public static void main(String[] args) throws IOException{ //Scanner in = new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int [] arr = new int[n+1]; int [] brr = new int[n+1]; for(int i =1;i<=n;i++){ st = new StringTokenizer(br.readLine()); int h = Integer.parseInt(st.nextToken()); int mm = Integer.parseInt(st.nextToken()); arr[i] = (h*60) + mm; brr[i] = arr[i] - arr[i-1]; if(i == 1 && brr[i]>=s+1){ System.out.println(0 + " " + 0); return; } else if(brr[i] >= 2*(s+1)){ int x = arr[i-1] + s+1; System.out.println((x/60) + " " + (x%60)); return; } } int x = arr[n] + s + 1; System.out.println((x/60) + " " + (x%60)); } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
f01ee1fa5b4207dbe5e59af9b479e8ca
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.util.*; public class Main{ static Scanner sc = new Scanner(System.in); public static void main(String[] args){ int n = sc.nextInt(), s = sc.nextInt(); int arr[] = new int[n+2]; arr[0] = -s-1; for(int i = 1; i<=n; i++){ arr[i] = sc.nextInt()*60+sc.nextInt(); } arr[n+1] = 100000; for(int i = 1;i<=(n+1);i++){ if((arr[i]-arr[i-1])>=2*(s+1)){ int val = arr[i-1]+1+s; System.out.println(val/60 +" "+ val%60); break; } } } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
75846280ded04509e88957a1865ee6fd
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.util.*; import java.io.*; // Main public class Main { public static void main (String[] argv) { new Main(); } boolean test = false; public Main() { FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in))); //FastReader in = new FastReader(new BufferedReader(new FileReader("Main.in"))); int n = in.nextInt(); int s = in.nextInt() + 1; int[] a = new int[n]; for (int i = 0; i < n; i++) { int h = in.nextInt(); int m = in.nextInt(); a[i] = h * 60 + m; } //Arrays.sort(a); //try add before the first one, and after each one if (a[0] - s >= 0) { System.out.println("0 0"); return; } for (int i = 0; i < n - 1; i++) { int start = a[i] + s; if (start + s <= a[i+1]) { System.out.println(f(start)); return; } } int start = a[n-1] + s; System.out.println(f(start)); } private String f(int v) { int h = v / 60; int m = v - 60 * h; return (h + " " + m); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(BufferedReader in) { br = in; } String next() { while (st == null || !st.hasMoreElements()) { try { String line = br.readLine(); if (line == null || line.length() == 0) return ""; st = new StringTokenizer(line); } catch (IOException e) { return ""; //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) { return ""; //e.printStackTrace(); } return str; } } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
04f6be61a55291da0864b33629d9b72b
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.io.*; import java.util.*; public class div477A { BufferedReader in; PrintWriter ob; StringTokenizer st; public static void main(String[] args) throws IOException { new div477A().run(); } void run() throws IOException { //in=new BufferedReader(new FileReader("input.txt")); in=new BufferedReader(new InputStreamReader(System.in)); ob=new PrintWriter(System.out); solve(); ob.flush(); } void solve() throws IOException { int n = ni(); int s = ni(); int a[][] = new int[n][2]; for(int i=0 ; i<n ; i++) { a[i][0] = ni(); a[i][1] = ni(); } for(int i=0 ; i<=27 ; i++) { for(int j=0 ; j<=59 ; j++) { if( check(i , j , a , n , s) ) { ob.println(i+" "+j); return; } } } } boolean check(int h , int m , int a[][] , int n , int s) { int res = Integer.MAX_VALUE; int time = h*60 + m; for(int i=0 ; i<n ; i++) { int seconds = a[i][0]*60 + a[i][1]; int difference = Math.abs( seconds - time ); res = Math.min( res , difference ); } return res>s?true:false; } int check( int a , int b , int c , int d ) { return (c-a)*60 + d-b; } String ns() throws IOException { return nextToken(); } long nl() throws IOException { return Long.parseLong(nextToken()); } int ni() throws IOException { return Integer.parseInt(nextToken()); } double nd() throws IOException { return Double.parseDouble(nextToken()); } String nextToken() throws IOException { if(st==null || !st.hasMoreTokens()) st=new StringTokenizer(in.readLine()); return st.nextToken(); } int[] nia(int start,int b) throws IOException { int a[]=new int[b]; for(int i=start;i<b;i++) a[i]=ni(); return a; } long[] nla(int start,int n) throws IOException { long a[]=new long[n]; for (int i=start; i<n ;i++ ) { a[i]=nl(); } return a; } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
570d78bd8d454e209133a0e989f83b0f
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; /** * MindGap * create by chenshihang on 2018/5/26 */ public class Main { public static void main(String[] args) throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); int n,s,h,m,rh=0,rm=0; boolean isOk = false; in.nextToken(); n=(int)in.nval; in.nextToken(); s=(int)in.nval; int data[][] = new int[n][2]; for (int i = 0; i < n; i++) { in.nextToken(); h=(int)in.nval; in.nextToken(); m=(int)in.nval; data[i][0]=h; data[i][1]=m; } if(data[0][0]*60 + data[0][1] > s){ isOk = true; } for(int i=0;i<n-1;i++){ if(isOk){ break; }else { int ch = data[i+1][0]-data[i][0]; int cm = data[i+1][1]-data[i][1]; int a = ch*60 + cm; if(a > 2*s+1){ isOk=true; int b = s+1+data[i][1]; rh = data[i][0]+b/60; rm = b%60; break; }else { continue; } } } if(!isOk){ int b = s+1+data[n-1][1]; rh = data[n-1][0]+b/60; rm = b%60; } System.out.println(rh+" "+rm); } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
bb11dcbd2400857f0c021fd9efa6ee56
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.util.Scanner; public class Main{ public static void main(String []args){ int n,m; Scanner sc = new Scanner(System.in); while(sc.hasNext()){ n = sc.nextInt(); m = sc.nextInt(); int [] a = new int[1001]; int [] b = new int[1001]; for(int i=0; i<n; i++){ a[i] = sc.nextInt(); b[i] = sc.nextInt(); } Boolean pan =false; int ans1,ans2; int x1=0,y1=0; int x2=0,y2=0; if(((a[0]-0)*60+(b[0]-0))>= m + 1){ System.out.println("0 0"); continue; } for(int i=0; i<n; i++){ // x1 = (a[i]-a[i-1])*60 + (b[i]-b[i]-1); x2 = (a[i+1]-a[i])*60 + (b[i+1]-b[i]); y1 = m*2+2; if(x2 >= y1){ pan = true; y2 = a[i]*60 + b[i] + m + 1; break; } } if(!pan){ int ans = a[n-1]*60 + b[n-1] + m + 1; ans1 = ans/60; ans2 = ans%60; System.out.println(ans1+" "+ans2); continue; } ans1 = y2 / 60; ans2 = y2 % 60; System.out.println(ans1+" "+ans2); } } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
ac74ad1c8c7d0a45454d55188ef75709
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import java.io.*; import java.util.*; import javax.swing.plaf.synth.SynthSeparatorUI; public class Main { private static Scanner in=new Scanner(new BufferedInputStream(System.in)); public static void main(String[] args) { // TODO Auto-generated method stub int n=in.nextInt(),s=in.nextInt()+1; int t; int k=in.nextInt()*60+in.nextInt(); t=k+24*60; if(k>=s) { System.out.println(0+" "+0); return; }else { for(int c=1;c<n;c++) { int r=in.nextInt()*60+in.nextInt(); if((r-k)>=s*2) { k+=s; System.out.println(k/60+" "+k%60); return; } k=r; } } k+=s; System.out.println(k/60+" "+k%60); } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
12a72aebd74345e074d339449bdb5237
train_001.jsonl
1525007700
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.
256 megabytes
import javax.jws.soap.SOAPBinding; import java.util.Scanner; public class A_MindTheGap { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int s = scanner.nextInt(); int[] landings = new int[n+1]; // int last; for(int i=0 ; i<n ; i++){ int h = scanner.nextInt(); int m = scanner.nextInt(); landings[i] = h*60+m; } if(landings[0]>=s+1){ System.out.println("0 0"); return; } for(int i=1 ; i<n ; i++){ if(landings[i]-landings[i-1]>=2*s+2){ int h = landings[i-1]+s+1; int m = h%60; h/=60; System.out.println(h + " " + m); return; } } int h = landings[n-1]+s+1; int m = h%60; h/=60; System.out.println(h + " " + m); } }
Java
["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"]
1 second
["6 1", "24 50", "0 0"]
NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.
Java 8
standard input
[ "implementation" ]
dcca7c58ba7111125608f659a577c3a2
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.
1,100
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
standard output
PASSED
acc0e1d36e67216639a0dd194cd6a591
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
import java.io.*; import java.util.*; public class C1111 { static long a,b; static int k,arr[]; static long find(int lo,int hi,int left,int right) { int num=right-left+1; if(num==0) return a; if(lo==hi) return b*num; int mid=(lo+hi)/2; int ind=index(mid,left,right); long energ=b*(num)*(hi-lo+1); long val=find(lo,mid,left,ind)+find(mid+1,hi,ind+1,right); return Math.min(energ,val); } static int index(int val,int lo,int hi) { if(hi<=lo) { if(arr[hi]>val) return hi-1; else return hi; } int mid=(lo+hi)/2; if(arr[mid]>val) return index(val,lo,mid); else return index(val,mid+1,hi); } public static void main(String args[])throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); k=sc.nextInt(); a=sc.nextLong(); b=sc.nextLong(); arr=new int[k]; for(int i=0;i<k;i++) { arr[i]=sc.nextInt(); } Arrays.sort(arr); int st=1,end=1<<n; long res=find(st,end,0,k-1); System.out.println(res); } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
e4cbe747adda0001780d612d9969c582
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
import java.io.*; import java.util.*; public class C1111 { static long a,b; static int k,arr[]; static long find(int lo,int hi,int left,int right) { int num=right-left+1; if(num==0) return a; if(lo==hi) return b*num; int mid=(lo+hi)/2; int ind=index(mid,left,right); long energ=b*(num)*(hi-lo+1); long val=find(lo,mid,left,ind)+find(mid+1,hi,ind+1,right); return Math.min(energ,val); } static int index(int val,int lo,int hi) { if(hi==lo) { if(arr[hi]>val) return hi-1; else return hi; } int mid=(lo+hi)/2; if(arr[mid]>val) return index(val,lo,mid); else return index(val,mid+1,hi); } public static void main(String args[])throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); k=sc.nextInt(); a=sc.nextLong(); b=sc.nextLong(); arr=new int[k]; for(int i=0;i<k;i++) { arr[i]=sc.nextInt(); } Arrays.sort(arr); int st=1,end=1<<n; long res=find(st,end,0,k-1); System.out.println(res); } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
9dae28481fef8314dd0b488b534ee52c
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
import java.io.IOException; import java.util.HashMap; import java.util.NoSuchElementException; public class Main{ static HashMap<Long,Integer>[] map; static int n; static int k; static int A; static int B; static long[] pow; @SuppressWarnings("unchecked") public static void main(String args[])throws Exception{ FastScanner sc= new FastScanner(); n = sc.nextInt(); k = sc.nextInt(); A = sc.nextInt(); B = sc.nextInt(); pow = new long[n]; long base = 1; for(int i=0;i<n;i++){ pow[i] = base; base *= 2; } long l = 0; long[][] a = new long[n+1][k]; for(int i=0;i<k;i++){ a[0][i] = sc.nextLong()-1; for(int j=1;j<n;j++){ a[j][i] = a[j-1][i]/2; } } map = new HashMap[n]; for(int i=0;i<n;i++){ map[i] = new HashMap<Long,Integer>(); } for(int j=0;j<n;j++){ for(int i=0;i<k;i++){ if(map[j].containsKey(a[j][i])){ map[j].put(a[j][i], map[j].get(a[j][i])+1); }else{ map[j].put(a[j][i], 1); } } } System.out.println(dfs(n-1,0)); } private static long dfs(int i, long j) { if(i==-1){ if(map[0].containsKey(j)){ return map[0].get(j) * B; }else{ return A; } } if(map[i].containsKey(j*2)&&map[i].containsKey(j*2+1)){ return dfs(i-1,j*2) + dfs(i-1,j*2+1); }else if(!map[i].containsKey(j*2)&&!map[i].containsKey(j*2+1)){ return A; }else{ if(map[i].containsKey(j*2)){ int n = map[i].get(j*2); return Math.min(n * B * pow[i] * 2,A + dfs(i-1,j*2)); }else{ int n = map[i].get(j*2+1); return Math.min(n * B * pow[i] * 2,A + dfs(i-1,j*2+1)); } } } } class FastScanner { private final java.io.InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;} public boolean hasNext() { skipUnprintable(); return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return (minus ? -n : n); }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return (int) (minus ? -n : n); }else{ throw new NumberFormatException(); } b = readByte(); } } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
59d5c313e8485177099d7f0ca92d408c
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
import java.io.*; import java.util.*; public class C1111 { static int n,k,A,B; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] ss = br.readLine().trim().split("\\s+"); n = Integer.parseInt(ss[0]); k = Integer.parseInt(ss[1]); A = Integer.parseInt(ss[2]); B = Integer.parseInt(ss[3]); ss = br.readLine().trim().split("\\s+"); TreeMap<Integer, Integer> map1 = new TreeMap<>(); for (int i=0; i<k; i++) { int xx = Integer.parseInt(ss[i]); map1.put(xx-1, map1.getOrDefault(xx-1, 0)+1); } TreeMap<Integer, Integer> map2 = new TreeMap<>(); map2.put(-1, 0); int total = 0; for (int key : map1.keySet()) { total += map1.get(key); map2.put(key, total); } System.out.println(func(0, (int)Math.pow(2, n)-1, map2)); } static long func(int start, int end, TreeMap<Integer, Integer> map) { long a = map.floorEntry(end).getValue() - map.floorEntry(start-1).getValue(); if (a == 0) return A; if (start == end) return B*a; return Math.min(B*a*(end-start+1), func(start, (start+end)/2, map) + func((start+end)/2+1, end, map)); } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
40562be177aba0c43c0bb1c4786b99ff
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String args[]) {new Main().run();} Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); void run(){ out.println(work()); out.flush(); } Integer[] count; long A,B; int n,k; long work() { n=in.nextInt(); k=in.nextInt(); A=in.nextLong(); B=in.nextLong(); count=new Integer[k]; for(int i=0;i<k;i++){ count[i]=in.nextInt(); } Arrays.sort(count); return dfs(1,1<<n); } long dfs(int s,int e){ int m=(s+e)/2; int a=search(s); int b=search(e+1); // out.println(s+",,"+e+",,,"+a+"..."+b); long r=0L; if(a==b){ r=A; }else{ r=(e-s+1)*B*(b-a); if(s!=e)r=Math.min(dfs(s,m)+dfs(m+1,e),r); } return r; } int search(int num){ int l=0,r=count.length; while(l<r){ int m=(l+r)/2; if(count[m]<num){ l=m+1; }else{ r=m; } } return l; } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
e244b1cbef2be85ba46e41d101a4a2a7
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Solver { private static int[] p; private static long a; private static long b; private static int k; public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); k = s.nextInt(); a = s.nextInt(); b = s.nextInt(); p = new int[k]; for (int i = 0; i < k; i++) { p[i] = s.nextInt(); } // int n = 29; int n2 = (int)Math.pow(2,n); // k = 29221; // a = 5; // b = 2089; // p = new int[k]; // for (int i = 0; i < k; i++) { // p[i] = n2 / k * i; // //p[i] = 2; // } Arrays.sort(p); for (int i = 0; i < k; i++) { p[i]--; } long result = solve(0, n2 - 1, 0, k - 1); System.out.println(result); } private static long solve(int start, int end, int indStart, int indEnd) { long variant1; if (indEnd < indStart) { return a; } variant1 = b * (indEnd - indStart + 1) * (end - start + 1); long variant2 = Long.MAX_VALUE; if (end - start > 0) { int middle = (end + start) / 2; int left = indStart; int right = indEnd; while (right - left > 1) { int indMiddle = (left + right) / 2; if (p[indMiddle] < middle) { left = indMiddle; } else { right = indMiddle; } } while (left < k - 1 && p[left] <= middle) { left++; } while (left >= 0 && left < k && p[left] > middle) { left--; } long solve1 = solve(start, middle, indStart, left); long solve2 = solve(middle + 1, end, left + 1, indEnd); variant2 = solve1 + solve2; } return Math.min(variant1, variant2); } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
b80efb134877d19ca861611fd5097824
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { public static void main(String[] args) throws IOException { PrintWriter out = new PrintWriter(System.out); //Scanner sc = new Scanner(); Reader in = new Reader(); Main solver = new Main(); solver.solve(out, in); out.flush(); out.close(); } //<> static int maxn = (int)1e5*2; static long mod=(int)1e9+7; static int n,t,m,k; static ArrayList<Long> arr; static long a,b; void solve(PrintWriter out, Reader in) throws IOException{ n = in.nextInt(); k = in.nextInt(); a = in.nextLong(); b = in.nextLong(); arr = new ArrayList<Long>(); arr.add(0L); for(int i=0;i<k;i++) arr.add(in.nextLong()); Collections.sort(arr); arr.add(2000000000L); long answer = recurse(1,1<<n); out.println(answer); } static long recurse(long l,long r){ int x = bsmax(l); int y = bsmin(r); long temp=0; if(x+1!=y) temp = y-1-x; if(l==r && temp==0) return a; else if(l==r && temp!=0) return b*temp; if(temp==0L) return a; else return Math.min((r-l+1)*b*temp,recurse(l,(r+l)/2)+recurse(((r+l)/2)+1,r)); } static int bsmin(long v){ int lo=0,hi=k+1; int mid,res=-1; while(lo<=hi){ mid = (hi+lo)/2; if(arr.get(mid)>v){ hi = mid-1; res = mid; }else lo = mid+1; } return res; } static int bsmax(long v){ int lo=0,hi=k+1; int mid,res=-1; while(lo<=hi){ mid = (hi+lo)/2; if(arr.get(mid)<v){ lo = mid+1; res = mid; }else hi = mid-1; } return res; } static class Edge implements Comparable<Edge> { int d,w; Edge(int d,int w){ this.d = d; this.w = w; } public int compareTo(Edge o){ return this.w - o.w; } } static class Reader { private InputStream mIs; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public Reader() { this(System.in); } public Reader(InputStream is) { mIs = is; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = mIs.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String next() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
f500d92907970c602292b6c6e2bfef11
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
import java.io.*; import java.math.*; import java.text.*; import java.util.*; import java.util.regex.*; public class Solution { static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { 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 = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } 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 = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } 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 boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } static long modInverse(long a,long m) { long m0 = m; long y = 0, x = 1; if (m == 1) return 0; while (a > 1) { long q = a / m; long t = m; m = a % m; a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } public static long power(long a,long b,long mod) { if(b==0) return 1; else if(b==1) return a; else { if(b%2==1) { long p=power(a,b/2,mod); return((p*p*a)%mod); } else { long p1=power(a,b/2,mod); return((p1*p1)%mod); } } } static class node { int v; ArrayList<node> ar; node(int a1) { v=a1; ar=new ArrayList<node>(); } } public static long mod=998244353; static class pair implements Comparable<pair> { int x,y,ix; pair(int a1,int a2,int a3) { x=a1; y=a2; ix=a3; } public int compareTo(pair p1) { return(((this.y-this.x)-(p1.y-p1.x))); } } static class cm implements Comparator<Long> { public int compare(Long i1,Long i2) { long dif=i2.longValue()-i1.longValue(); if(dif<0) { return -1; } else if(dif>0) { return 1; } return 0; } } public static ArrayList<Long> ar; public static long build(long l,long r,long A,long B) { int ix1=Collections.binarySearch(ar,2*l-1); int ix2=Collections.binarySearch(ar,2*r+1); int num=0; if(ix1<0) ix1=(-1)*(ix1+1); num-=ix1; if(ix2<0) { ix2=(-1)*(ix2+1); num+=ix2; } else num+=ix2+1; if(num==0) return A; if(l==r) { if(num==0) return(A); return(B*num*(r-l+1)); } long cost=0; if(num==0) cost=A; else cost=B*num*(r-l+1); long mid=l+((r-l)/2L); long an1=build(l,mid,A,B); long an2=build(mid+1,r,A,B); //System.out.println(l+" "+r+" "+((long)Math.min((an1+an2),cost))); return((long)Math.min((an1+an2),cost)); } public static void main(String[] args) throws IOException { InputReader in=new InputReader(System.in); PrintWriter w=new PrintWriter(System.out); int n=in.nextInt(); int k=in.nextInt(); int a=in.nextInt(); int b=in.nextInt(); ar=new ArrayList<Long>(); for(int i=0;i<k;i++) { ar.add((2L*in.nextLong())); } Collections.sort(ar); w.println(build((long)1,(long)Math.pow(2,n),(long)a,(long)b)); w.close(); } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
882dd85013d27d3fb4004009c535eb01
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.TreeMap; import java.util.StringTokenizer; import java.util.Map; 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 Liavontsi Brechka */ 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); CIzobretatelniiShelchok solver = new CIzobretatelniiShelchok(); solver.solve(1, in, out); out.close(); } static class CIzobretatelniiShelchok { int n; int k; int a; int b; TreeMap<Integer, Integer> locations; public void solve(int testNumber, InputReader in, PrintWriter out) { n = in.nextInt(); k = in.nextInt(); a = in.nextInt(); b = in.nextInt(); locations = new TreeMap<>(); for (int i = 0; i < k; i++) { int next = in.nextInt(); locations.put(next, locations.getOrDefault(next, 0) + 1); } CIzobretatelniiShelchok.DestRes res = check(1, (int) Math.pow(2, n)); out.print(res.minEnergy); } CIzobretatelniiShelchok.DestRes check(int l, int r) { if (l > r) throw new RuntimeException(); if (l == r) { int count = locations.getOrDefault(l, 0); long energy = count == 0 ? a : 1L * b * count; return new CIzobretatelniiShelchok.DestRes(energy, count); } Integer currentLoc = locations.ceilingKey(l); if (currentLoc != null && currentLoc <= r) { CIzobretatelniiShelchok.DestRes left = check(l, (l + r) >>> 1); CIzobretatelniiShelchok.DestRes right = check(((l + r) >>> 1) + 1, r); long minEnergy = Math.min(left.minEnergy + right.minEnergy, 1L * b * (left.count + right.count) * (r - l + 1)); return new CIzobretatelniiShelchok.DestRes(minEnergy, left.count + right.count); } else { return new CIzobretatelniiShelchok.DestRes(a, 0); } } static class DestRes { long minEnergy; int count; public DestRes(long minEnergy, int count) { this.minEnergy = minEnergy; this.count = count; } } } static class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); } public int nextInt() { return Integer.parseInt(next()); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(readLine()); } return tokenizer.nextToken(); } public String readLine() { String line; try { line = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return line; } } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
3b6fba6e3b419242e685018627fb901b
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
import java.lang.*; import java.math.*; import java.util.*; import java.io.*; public class Main { void solve() { n=ni(); k=ni(); A=ni(); B=ni(); a=new int[k+1]; for(int i=1;i<=k;i++) a[i]=ni(); Arrays.sort(a,1,k+1); long ans=go(1,1<<n); pw.println(ans); } long go(int i,int j){ if((j-i+1)==1) { int x=get(j)-get(i-1); if(x>0) return B*1L*x; else return A; } int l=j-i+1; int mid=l/2; mid=mid+i-1; long mn=Long.MAX_VALUE; int x=get(mid)-get(i-1),y=get(j)-get(mid); if(x==0 && y==0){ mn=A; }else if(x!=0 && y!=0){ mn=go(i,mid)+go(mid+1,j); mn=Math.min(mn,B*1L*(x+y)*l); }else if(x==0){ mn=A+go(mid+1,j); mn=Math.min(mn,B*1L*(x+y)*l); }else if(y==0){ mn=A+go(i,mid); mn=Math.min(mn,B*1L*(x+y)*l); } return mn; } int a[]; int n,k,A,B; int get(int x){ int l=1,r=k; int ans=0; while(l<=r){ int mid=(l+r)>>1; if(a[mid]<=x){ ans=mid; l=mid+1; }else r=mid-1; } return ans; } long M = (long)1e9+7; InputStream is; PrintWriter pw; String INPUT = ""; void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); pw = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); pw.flush(); if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms"); } public static void main(String[] args) throws Exception { new Main().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char) skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o)); } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
c622cac5070952efd082624311f68af4
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class CreativeSnap { static Long[] dp; static int INF = (int) 1e9 + 7; public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(), k = s.nextInt(), A = s.nextInt(), B = s.nextInt(); dp = new Long[k]; for(int i = 0; i < k; i++) { dp[i] = s.nextLong(); } Arrays.sort(dp); System.out.println(dnc(1, 1 << n, A, B)); } private static long dnc(int lo, int hi, int A, int B) { if(lo > hi) { return 0; } int ceil = first(lo); int floor = last(hi); if(lo == hi) { return floor < ceil ? A : (long)(hi-lo+1)*(floor-ceil+1)*B; } if(floor < ceil) { return A; } long total = (long)(floor - ceil + 1)*(hi-lo+1)*B; int mid = (lo + hi)>>>1; long divided = dnc(lo, mid,A, B); divided += dnc(mid+1, hi, A, B); return Math.min(total, divided); } private static int first(int index) { int lo = 0, hi = dp.length; while(lo < hi) { int mid = (lo + hi) >>> 1; if(dp[mid] < index) { lo = mid+1; } else { hi = mid; } } return lo; } private static int last(int index) { int lo = -1, hi = dp.length-1; while( lo < hi) { int mid = (lo + hi + 1) >>> 1; if(dp[mid] > index) { hi = mid-1; } else { lo = mid; } } return lo; } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
b0c49e2aacb49df870091072c8bb8534
train_001.jsonl
1549208100
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $$$2$$$, divide the base into $$$2$$$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $$$A$$$ amount of power, otherwise it takes his $$$B \cdot n_a \cdot l$$$ amount of power, where $$$n_a$$$ is the number of avengers and $$$l$$$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
256 megabytes
// package CF1111; import java.io.*; import java.util.*; public class CF1111C { static FastReader s; static PrintWriter out; static String INPUT = "3 2 5 1\n" + "8 7\n"; //02357 public static void main(String[] args) { long time = System.currentTimeMillis(); boolean oj = System.getProperty("ONLINE_JUDGE") != null; out = new PrintWriter(System.out); s = new FastReader(oj); int n = s.nextInt(); int k = s.nextInt(); long a = s.nextLong(); long b = s.nextLong(); long[] arr = s.nextLongArray(k); arrays.sort(arr); // int[] arr2 = {0,2,3,5,5,7}; // out.println(Arrays.binarySearch(arr2,1)); // out.println(Arrays.binarySearch(arr2,6)); out.println(func(a, b, 1, (long)(1 << (long)n), arr)); if (!oj) { System.out.println(Arrays.deepToString(new Object[]{System.currentTimeMillis() - time + " ms"})); } out.flush(); } private static long func(long a, long b, long start, long end, long[] arr) { if (start == end) { if (Arrays.binarySearch(arr, end) >= 0) { long pos1 = (long)BS.binarySearchFirstOccurence(arr, end); long pos2 = (long)BS.binarySearchLastOccurence(arr, end); return b * (pos2 - pos1 + 1L); } else { return a; } } long pos = Arrays.binarySearch(arr, start); long pos2 = Arrays.binarySearch(arr, end); boolean bool1 = false; boolean bool2 = false; if (pos < 0) { pos = (-1L) * (pos + 1L); bool1 = true; } if (pos2 < 0) { pos2 = (-1L) * (pos2 + 1L); bool2 = true; } if(!bool2) { pos2 = (long)BS.binarySearchLastOccurence(arr, end); } if(!bool1) { pos = (long)BS.binarySearchFirstOccurence(arr, start); } if (pos2 == pos && bool1 && bool2) { return a; } long a1 = func(a, b, start, (start + end) / 2, arr); long a2 = func(a, b, ((start + end) / 2) + 1, end, arr); long min1; if(!bool1 && !bool2) { min1 = (end - start + 1L) * b * (pos2 - pos + 1L); } else { if(bool2) { min1 = (end - start + 1L) * b * (pos2 - pos); } else { min1 = (end - start + 1L) * b * (pos2 - pos + 1L); } } return Math.min(min1, a1 + a2); } private static class Maths { static ArrayList<Long> printDivisors(long n) { // Note that this loop runs till square root ArrayList<Long> list = new ArrayList<>(); for (long i = 1; i <= Math.sqrt(n); i++) { if (n % i == 0) { if (n / i == i) { list.add(i); } else { list.add(i); list.add(n / i); } } } return list; } // GCD - Using Euclid theorem. private static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } // Extended euclidean algorithm // Used to solve equations of the form ax + by = gcd(a,b) // return array [d, a, b] such that d = gcd(p, q), ap + bq = d static long[] extendedEuclidean(long p, long q) { if (q == 0) return new long[]{p, 1, 0}; long[] vals = extendedEuclidean(q, p % q); long d = vals[0]; long a = vals[2]; long b = vals[1] - (p / q) * vals[2]; return new long[]{d, a, b}; } // X ^ y mod p static long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if ((y & 1) == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } // Returns modulo inverse of a // with respect to m using extended // Euclid Algorithm. Refer below post for details: // https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/ static long inv(long a, long m) { long m0 = m, t, q; long x0 = 0, x1 = 1; if (m == 1) return 0; // Apply extended Euclid Algorithm while (a > 1) { q = a / m; t = m; m = a % m; a = t; t = x0; x0 = x1 - q * x0; x1 = t; } // Make x1 positive if (x1 < 0) x1 += m0; return x1; } // k is size of num[] and rem[]. // Returns the smallest number // x such that: // x % num[0] = rem[0], // x % num[1] = rem[1], // .................. // x % num[k-2] = rem[k-1] // Assumption: Numbers in num[] are pairwise // coprime (gcd for every pair is 1) static long findMinX(long num[], long rem[], long k) { int prod = 1; for (int i = 0; i < k; i++) prod *= num[i]; int result = 0; for (int i = 0; i < k; i++) { long pp = prod / num[i]; result += rem[i] * inv(pp, num[i]) * pp; } return result % prod; } } private static class BS { // Binary search private static int binarySearch(int[] arr, int ele) { int low = 0; int high = arr.length - 1; while (low <= high) { int mid = (low + high) / 2; if (arr[mid] == ele) { return mid; } else if (ele < arr[mid]) { high = mid - 1; } else { low = mid + 1; } } return -1; } // First occurence using binary search private static int binarySearchFirstOccurence(long[] arr, long ele) { int low = 0; int high = arr.length - 1; int ans = -1; while (low <= high) { int mid = (low + high) / 2; if (arr[mid] == ele) { ans = mid; high = mid - 1; } else if (ele < arr[mid]) { high = mid - 1; } else { low = mid + 1; } } return ans; } // Last occurenece using binary search private static int binarySearchLastOccurence(long[] arr, long ele) { int low = 0; int high = arr.length - 1; int ans = -1; while (low <= high) { int mid = (low + high) / 2; if (arr[mid] == ele) { ans = mid; low = mid + 1; } else if (ele < arr[mid]) { high = mid - 1; } else { low = mid + 1; } } return ans; } } private static class arrays { // Merge sort static void merge(long arr[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; long L[] = new long[n1]; long R[] = new long[n2]; for (int i = 0; i < n1; ++i) L[i] = arr[l + i]; for (int j = 0; j < n2; ++j) R[j] = arr[m + 1 + j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } static void sort(long arr[], int l, int r) { if (l < r) { int m = (l + r) / 2; sort(arr, l, m); sort(arr, m + 1, r); merge(arr, l, m, r); } } static void sort(long[] arr) { sort(arr, 0, arr.length - 1); } } private static class UnionFindDisjointSet { int[] parent; int[] size; int n; int size1; public UnionFindDisjointSet(int n) { this.n = n; this.parent = new int[n]; this.size = new int[n]; for (int i = 0; i < n; i++) { parent[i] = i; } for (int i = 0; i < n; i++) { size[i] = 1; } this.size1 = n; } private int numDisjointSets() { System.out.println(size1); return size1; } private boolean find(int a, int b) { int rootA = root(a); int rootB = root(b); if (rootA == rootB) { return true; } return false; } private int root(int b) { while (parent[b] != b) { parent[b] = parent[parent[b]]; b = parent[b]; } return b; } private void union(int a, int b) { int rootA = root(a); int rootB = root(b); if (rootA == rootB) { return; } if (size[rootA] < size[rootB]) { parent[rootA] = parent[rootB]; size[rootB] += size[rootA]; } else { parent[rootB] = parent[rootA]; size[rootA] += size[rootB]; } size1--; System.out.println(Arrays.toString(parent)); } } private static class SegTree { int[] st; int[] arr; public SegTree(int[] arr) { this.arr = arr; int size = (int) Math.ceil(Math.log(arr.length) / Math.log(2)); st = new int[(int) ((2 * Math.pow(2, size)) - 1)]; buildSegmentTree(1, 0, arr.length - 1); } //**********JUST CALL THE CONSTRUCTOR, THIS FUNCTION WILL BE CALLED AUTOMATICALLY****** private void buildSegmentTree(int index, int L, int R) { if (L == R) { st[index] = arr[L]; return; } buildSegmentTree(index * 2, L, (L + R) / 2); buildSegmentTree(index * 2 + 1, (L + R) / 2 + 1, R); // Replace this line if you want to change the function of the Segment tree. st[index] = Math.min(st[index * 2], st[index * 2 + 1]); } //***********We have to use this function ************** private int Query(int queL, int queR) { return Query1(1, 0, arr.length - 1, queL, queR); } //This is a helper function. //************* DO NOT USE THIS **************** private int Query1(int index, int segL, int segR, int queL, int queR) { if (queL > segR || queR < segL) { return -1; } if (queL <= segL && queR >= segR) { return st[index]; } int ans1 = Query1(index * 2, segL, (segL + segR) / 2, queL, queR); int ans2 = Query1(index * 2 + 1, (segL + segR) / 2 + 1, segR, queL, queR); if (ans1 == -1) { return ans2; } if (ans2 == -1) { return ans1; } // Segment tree implemented for range minimum query. Change the below line to change the function. return Math.min(ans1, ans2); } private void update(int idx, int val) { update1(1, 0, arr.length - 1, idx, val); } private void update1(int node, int queL, int queR, int idx, int val) { // idx - index to be updated in the array // node - index to be updated in the seg tree if (queL == queR) { // Leaf node arr[idx] += val; st[node] += val; } else { int mid = (queL + queR) / 2; if (queL <= idx && idx <= mid) { // If idx is in the left child, recurse on the left child update1(2 * node, queL, mid, idx, val); } else { // if idx is in the right child, recurse on the right child update1(2 * node + 1, mid + 1, queR, idx, val); } // Internal node will have the min of both of its children st[node] = Math.min(st[2 * node], st[2 * node + 1]); } } } private static class FastReader { InputStream is; public FastReader(boolean onlineJudge) { is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes()); } byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } double nextDouble() { return Double.parseDouble(next()); } char nextChar() { return (char) skip(); } String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } String nextLine() { int b = skip(); StringBuilder sb = new StringBuilder(); while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } char[] next(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } char[][] nextMatrix(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = next(m); return map; } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int[][] next2DInt(int n, int m) { int[][] arr = new int[n][]; for (int i = 0; i < n; i++) { arr[i] = nextIntArray(m); } return arr; } long[][] next2DLong(int n, int m) { long[][] arr = new long[n][]; for (int i = 0; i < n; i++) { arr[i] = nextLongArray(m); } return arr; } int[] shuffle(int[] arr) { Random r = new Random(); for (int i = 1, j; i < arr.length; i++) { j = r.nextInt(i); arr[i] = arr[i] ^ arr[j]; arr[j] = arr[i] ^ arr[j]; arr[i] = arr[i] ^ arr[j]; } return arr; } int[] uniq(int[] arr) { Arrays.sort(arr); int[] rv = new int[arr.length]; int pos = 0; rv[pos++] = arr[0]; for (int i = 1; i < arr.length; i++) { if (arr[i] != arr[i - 1]) { rv[pos++] = arr[i]; } } return Arrays.copyOf(rv, pos); } } }
Java
["2 2 1 2\n1 3", "3 2 1 2\n1 7"]
1 second
["6", "8"]
NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1$$$ and $$$2-2$$$.For base $$$1-1$$$, he can burn it with power $$$2 \cdot 1 \cdot 1 = 2$$$. For $$$2-2$$$, he can destroy it with power $$$1$$$, as there are no avengers. So, the total power for destroying $$$1-2$$$ is $$$2 + 1 = 3$$$, which is less than $$$4$$$. Similarly, he needs $$$3$$$ power to destroy $$$3-4$$$. The total minimum power needed is $$$6$$$.
Java 8
standard input
[ "binary search", "divide and conquer", "brute force", "math" ]
4695aa2b3590a0734ef2c6c580e471a9
The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line contains $$$k$$$ integers $$$a_{1}, a_{2}, a_{3}, \ldots, a_{k}$$$ ($$$1 \leq a_{i} \leq 2^n$$$), where $$$a_{i}$$$ represents the position of avenger in the base.
1,700
Output one integer — the minimum power needed to destroy the avengers base.
standard output
PASSED
ff51466dc428973be4d3349687dfdc8b
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.math.BigInteger; import java.util.Scanner; public class Forca390B { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } for (int i = 0; i < n; i++) { b[i] = in.nextInt(); } BigInteger happiness = new BigInteger("0"); for (int i = 0; i < n; i++) { if(2*a[i] < b[i] || b[i] == 1){ happiness = happiness.add(new BigInteger("-1")); } else { long x = b[i] / 2; long y = x + b[i]%2; happiness = happiness.add(BigInteger.valueOf(x).multiply(BigInteger.valueOf(y))); } } System.out.println(happiness); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
56f8e5b590688ab33265fcd2746951de
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; int[] v = new int[n]; for(int i=0; i<n; i++) a[i] = sc.nextInt()*2; for(int i=0; i<n; i++) v[i] = sc.nextInt(); long ans = 0, x, y; // System.out.println(Arrays.toString(a)); for(int i=0; i<n; i++){ if(a[i] >= v[i]){ if(v[i] == 1){ ans--; x = 0; y = 0; }else if(v[i]%2 == 0){ x = v[i]/2; y = v[i]/2; // System.out.println(x + " " + y + " " + v[i] + " " + i); }else{ x = v[i]/2; y = v[i]-x; } ans += x*y; // System.out.println(x + " " + y + ": " + ans); }else{ ans--; } } System.out.println(ans); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
27a7ffed840cf971c1a7a3aa5e960538
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner s = new Scanner(System.in); int size = s.nextInt(); int[] a = new int[size]; long count = 0; for(int i = 0 ; i < size; i++ ) { a[i] = s.nextInt(); } for(int i = 0 ; i < size ; i++) { int b = s.nextInt(); if(b > a[i]*2 || b < 2) { count--; } else { count += (long)Math.pow(b,2)/4; } } System.out.println(count); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
04a804de318827dad26823ce56b49d13
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner in=new Scanner(System.in); int n=in.nextInt(); long count=0; int A[]=new int[n]; int B[]=new int[n]; for(int i=0;i<n;i++){ A[i]=in.nextInt(); } for(int i=0;i<n;i++){ B[i]=in.nextInt(); } for(int i=0;i<n;i++){ // System.out.print(A[i]+"+"+((B[i]-B[i]/2))+" "); // System.out.print(A[i]+"+"+((B[i]-B[i]/2))+" "); if(B[i]>=2 && (B[i]-B[i]/2)<=A[i]){ count+=(long)B[i]/2*(B[i]-B[i]/2); }else{ count--; } } System.out.println(count); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
f084a5bf2220e22c7afd9204879810ab
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); long result = 0; int[] a = new int[n]; for(int i = 0; i < n; i++) { a[i] = scanner.nextInt(); } long[] b = new long[n]; for(int i = 0; i < n; i++) { b[i] = scanner.nextInt(); if(b[i] < 2) { result--; } else if(b[i] % 2 == 0) { if(b[i]/2 <= a[i]) { result += (b[i]/2)*(b[i]/2); } else { result--; } } else { if(Math.max(((b[i]-1)/2), ((b[i]+1)/2)) <= a[i]) { result += ((b[i]-1)/2)*((b[i]+1)/2); } else { result--; } } } System.out.println(result); } } //25000000000000000
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
98775061d0a83f4ec536381516e03e8a
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintWriter; import java.util.StringTokenizer; public class B390{ static final boolean FILE_IO = false; static final String output_file = "output.txt"; static final String input_file = "input.txt"; public static void main(String[] args){ InputReader in = new InputReader(); PrintWriter out; if(FILE_IO){ try{ out = new PrintWriter(output_file); } catch(FileNotFoundException e){ throw new RuntimeException(e); } } else { out = new PrintWriter(System.out); } final long start = System.currentTimeMillis(); new Task1().solve(in, out); final long duration = System.currentTimeMillis()-start; out.close(); } static class Task1{ public void solve(InputReader in, PrintWriter out){ int n=in.nextInt(); int[] a=new int[n]; int[] b=new int[n]; for(int i=0; i<n; i++) a[i]=in.nextInt(); long joy=0; for(int i=0; i<n; i++){ b[i]=in.nextInt(); if(b[i]>2*(a[i])){ joy -= 1; continue; } long first = b[i]/2; long second = b[i]-b[i]/2; if(first==0 || second==0){ joy -= 1; } else{ joy += first*second; } //out.println(joy); } out.println(joy); } } static class InputReader{ private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(){ if(FILE_IO){ try{ reader = new BufferedReader(new FileReader(input_file)); } catch(FileNotFoundException e){ throw new RuntimeException(e); } } else { 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 (int)Integer.parseInt(next()); } public long nextLong(){ return (long)Long.parseLong(next()); } public double nextDouble(){ return (double)Double.parseDouble(next()); } public String nextLine(){ String s = null; try{ s = reader.readLine(); } catch(Exception e){ throw new RuntimeException(e); } return s; } } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
57eafa3a7a28a800ed3d6c175432f348
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
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.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); 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 = new int[n]; int[] B = new int[n]; for (int i = 0; i < n; ++i) A[i] = in.nextInt(); for (int i = 0; i < n; ++i) B[i] = in.nextInt(); long ans = 0; for (int i = 0; i < n; ++i) { if (2 * A[i] < B[i] || B[i] == 1) { ans--; } else { ans += (long) (B[i] / 2) * (B[i] - B[i] / 2); } } out.println(ans); } } static class InputReader { 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 UnknownError(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new UnknownError(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { return Integer.parseInt(next()); } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
4945beda78df5e1081e78f633a0a8cb0
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.util.*; public class B { public static void main(String[] args) { Scanner qwe = new Scanner(System.in); int n = qwe.nextInt(); long[] a= new long[n]; for (int i = 0; i < a.length; i++) { a[i] = qwe.nextLong(); } long[] b = new long[n]; long ans = 0; for (int i = 0; i < b.length; i++) { b[i] = qwe.nextLong(); if(2*a[i] >= b[i]){ if(b[i] % 2 == 1){ long temp = b[i]/2; if(temp == 0){ ans--; } else ans += temp*(b[i]-temp); } else{ ans += b[i]*b[i]/4; } } else ans--; } System.out.println(ans); qwe.close(); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
6cc6c4d364d1d558080b1bb331e93708
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; import java.util.InputMismatchException; import java.util.NoSuchElementException; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Árysson Cavalcanti */ 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out) { int n=in.readInt(); int[] a= IOUtils.readIntArray(in, n), b=IOUtils.readIntArray(in, n); long ret=0; for (int i=0; i<n; i++) { int x= MiscUtils.min(b[i]/2, a[i]), y=MiscUtils.min(b[i]-x, a[i]); if (x+y==b[i] && 1L*x*y>0) ret+=1L*x*y; else ret--; } out.printLine(ret); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public 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); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public void close() { writer.close(); } public void printLine(long i) { writer.println(i); } } class IOUtils { public static int[] readIntArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = in.readInt(); return array; } } class MiscUtils { public static<T extends Comparable<T>> T min(T first, T second) { if (first.compareTo(second) <= 0) return first; return second; } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
9acef720521dfc4f89fea0d46a86c8c0
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); long arr[] = new long [n]; long arr1[] = new long [n]; for (int i=0; i<n;i++){ arr[i] = scanner.nextLong(); } for (int i=0; i<n;i++){ arr1[i] = scanner.nextLong(); } long sum=0; for (int i=0;i<n;i++){ if(arr[i]*2<arr1[i]){ sum--; } if(arr[i]*2==arr1[i]){ sum+=arr[i]*arr[i]; } if(arr[i]*2>arr1[i]){ if(arr1[i]%2==0){ sum+=(arr1[i]*arr1[i])/4; }else if(arr1[i]==1){ //System.out.println("aaa"); sum--; }else { long a = arr1[i]/2; sum+=(a*(a+1)); } } } System.out.println(sum); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
6e6b1300bcda874f23e982d80acbc9b0
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.io.*; import java.util.*; public class b { public static void main(String[] args) throws IOException { input.init(System.in); PrintWriter out = new PrintWriter(System.out); int n = input.nextInt(); int[] as = new int[n], bs = new int[n]; for(int i = 0; i<n; i++) as[i] = input.nextInt(); for(int i = 0; i<n; i++) bs[i] = input.nextInt(); long res = 0; for(int i = 0; i<n; i++) { if(as[i] + as[i] < bs[i] || bs[i] == 1) res--; else { int a = bs[i]/2, b = bs[i] - a; if(b > as[i]) { b = as[i]; a = bs[i] - as[i]; } res += (long)a*b; } } out.println(res); out.close(); } public static class input { static BufferedReader reader; static StringTokenizer tokenizer; static void init(InputStream input) { reader = new BufferedReader(new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } static String next() throws IOException { while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine()); return tokenizer.nextToken(); } 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
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
8bc7ba937b3c7319571232c2694acfe7
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.util.*; public class CF229{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Long[] a=new Long[n]; Long[] b=new Long[n]; for(int i=0;i<n;i++){ a[i]=sc.nextLong(); } for(int i=0;i<n;i++){ b[i]=sc.nextLong(); } long total=0; for(int i=0;i<n;i++){ if(b[i]>1 && b[i]<=2*a[i]){total+=(b[i]/2)*(b[i]-(b[i]/2));} else{--total;} } System.out.println(total); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
c7a4eb0f0801b654bc40aac4c3ee587c
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int n,i; long sum=0,c=0; n=sc.nextInt(); long a[]=new long[n]; long b[]=new long[n]; for(i=0;i<n;i++) { a[i]=sc.nextLong(); } for(i=0;i<n;i++) { b[i]=sc.nextLong(); } sum=0; for(i=0;i<n;i++) { if(a[i]*2<b[i]) { sum=sum-1; continue; } else if(a[i]*2==b[i]) { sum=sum+(a[i]*a[i]); } else if(a[i]*2>b[i]) { if(b[i]%2==0) { c=b[i]/2; sum=sum+(c*c); } else if(b[i]==1) { sum=sum-1; } else { c=b[i]/2; sum=sum+(c*(c+1)); } } } System.out.println(sum); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
fde2895eec3ec1f33c51c1d9e596ffbb
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.util.*; import java.io.*; public class B { public static void main(String[] args) throws IOException { in.init(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); long ans = 0; long[] a = new long[n]; long[] b = new long[n]; for(int i = 0; i < n; i ++) a[i] = in.nextInt(); for(int i = 0; i < n; i ++) b[i] = in.nextInt(); for(int i = 0; i < n; i ++) { if(b[i]==1) ans--; else if(b[i]/2 + b[i]%2 <= a[i]) ans+=(b[i]/2)*((b[i]/2) + (b[i]%2)); else ans--; } out.println(ans); out.close(); } public static class in { static BufferedReader reader; static StringTokenizer tokenizer; static void init(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = new StringTokenizer(""); } static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } 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
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
94194d5d22982083a3196dda8914d649
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.io.*; import java.util.*; public class Template implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException { try { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } catch (Exception e) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } } String readString() throws IOException { while (!tok.hasMoreTokens()) { try { tok = new StringTokenizer(in.readLine(), " :"); } catch (Exception e) { return null; } } return tok.nextToken(); } int readInt() throws IOException { return Integer.parseInt(readString()); } int[] readIntArray(int size) throws IOException { int[] res = new int[size]; for (int i = 0; i < size; i++) { res[i] = readInt(); } return res; } long readLong() throws IOException { return Long.parseLong(readString()); } double readDouble() throws IOException { return Double.parseDouble(readString()); } <T> List<T>[] createGraphList(int size) { List<T>[] list = new List[size]; for (int i = 0; i < size; i++) { list[i] = new ArrayList<>(); } return list; } public static void main(String[] args) { new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start(); } long timeBegin, timeEnd; void time() { timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } long memoryTotal, memoryFree; void memory() { memoryFree = Runtime.getRuntime().freeMemory(); System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB"); } public void run() { try { timeBegin = System.currentTimeMillis(); memoryTotal = Runtime.getRuntime().freeMemory(); init(); solve(); out.close(); if (System.getProperty("ONLINE_JUDGE") == null) { time(); memory(); } } catch (Exception e) { e.printStackTrace(); System.exit(-1); } } void solve() throws IOException { int n = readInt(); int[] a = readIntArray(n); int[] b = readIntArray(n); long answer = 0; for (int i = 0; i < n; i++) { if (b[i] <= 1) { answer--; continue; } long half = b[i] / 2; long other = b[i] - half; if (Math.max(half, other) > a[i]) { answer--; continue; } answer += half * other; } out.println(answer); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
a3996a78a957849fc4c8cbd603d7e4a5
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.io.Reader; import java.util.InputMismatchException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; /** * Built using CHelper plug-in * Actual solution is at the top * @author Niyaz Nigmatullin */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); FastPrinter out = new FastPrinter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, FastScanner in, FastPrinter out) { int n = in.nextInt(); int[] a = in.readIntArray(n); long ans = 0; for (int i = 0; i < n; i++) { int x = in.nextInt(); if (x > 2 * a[i] || x == 1) { --ans; } else { ans += (long) (x / 2) * ((x + 1) / 2); } } out.println(ans); } } class FastScanner extends BufferedReader { public FastScanner(InputStream is) { super(new InputStreamReader(is)); } public int read() { try { int ret = super.read(); // if (isEOF && ret < 0) { // throw new InputMismatchException(); // } // isEOF = ret == -1; return ret; } catch (IOException e) { throw new InputMismatchException(); } } static boolean isWhiteSpace(int c) { return c >= 0 && c <= 32; } public int nextInt() { int c = read(); while (isWhiteSpace(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int ret = 0; while (c >= 0 && !isWhiteSpace(c)) { if (c < '0' || c > '9') { throw new NumberFormatException("digit expected " + (char) c + " found"); } ret = ret * 10 + c - '0'; c = read(); } return ret * sgn; } public String readLine() { try { return super.readLine(); } catch (IOException e) { return null; } } public int[] readIntArray(int n) { int[] ret = new int[n]; for (int i = 0; i < n; i++) { ret[i] = nextInt(); } return ret; } } class FastPrinter extends PrintWriter { public FastPrinter(OutputStream out) { super(out); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
dcfae21c410ef9fe84e55accff15afbe
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.math.BigInteger; import java.util.Scanner; public class B390 { public static void main(String[] args) { BigInteger happiness = BigInteger.valueOf(0); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < 2; i++) { for (int j = 0; j < n; j++) { if (i == 0) { a[j] = sc.nextInt(); } else { b[j] = sc.nextInt(); } } } BigInteger x; BigInteger y; for (int i = 0; i < n; i++) { if (b[i] == 1) { happiness = happiness.subtract(BigInteger.valueOf(1)); } if (a[i] * 2 < b[i]) { happiness = happiness.subtract(BigInteger.valueOf(1)); } else { if (b[i] % 2 == 0) { x = BigInteger.valueOf(b[i] / 2); happiness = happiness.add(x.multiply(x)); } else { x = BigInteger.valueOf((b[i] - 1) / 2); y = BigInteger.valueOf((b[i] + 1) / 2); happiness = happiness.add(x.multiply(y)); } } } System.out.println(happiness); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
b542945b4e89bd56814bc38bda257fdc
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
//package codeforces; import java.util.Scanner; public class Music { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int n = in.nextInt(); long A[] = new long[n]; long B[] = new long[n]; long joy = 0; for (int i=0;i < n;i++) A[i] = in.nextLong(); for (int i=0;i < n;i++) B[i] = in.nextLong(); for (int i=0;i < n;i++){ if (2*A[i] < B[i]) joy--; else{ if (B[i] == 1) joy--; else if (B[i] == 2) joy++; else{ if (B[i] % 2 == 0) joy += (B[i]/2)*(B[i]/2); else joy += ((B[i]+1)/2)*((B[i]-1)/2); } } } System.out.println(joy); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
49fc0500580158ca4e6508c3fb1d7fcb
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; 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; FastScanner in = new FastScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); BInnaDimaAndSong solver = new BInnaDimaAndSong(); solver.solve(1, in, out); out.close(); } static class BInnaDimaAndSong { public void solve(int testNumber, FastScanner in, PrintWriter out) { int n = in.nextInt(); long a[] = new long[n]; long b[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = in.nextLong(); } long joy = 0; for (int i = 0; i < n; i++) { b[i] = in.nextLong(); if (b[i] != 1 && (b[i] / 2 + b[i] % 2) <= a[i]) { if (b[i] % 2 == 0) { joy += (b[i] / 2 * b[i] / 2); } else { joy += ((b[i] / 2) * ((b[i] / 2) + 1)); } } else { joy--; } //out.println("joy "+joy+" "+a[i]+" "+b[i]); } out.println(joy); } } static class FastScanner { private final InputStream stream; private final byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastScanner(InputStream stream) { this.stream = stream; } 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++]; } boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } 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(); } } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
3341b5e7cc4e834ad1ab57d6e13da9a7
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.SortedSet; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; /** * # * * @author pttrung */ public class B_Round_229_Div2 { public static long MOD = 1000000007; public static void main(String[] args) throws FileNotFoundException { // PrintWriter out = new PrintWriter(new FileOutputStream(new File( // "output.txt"))); PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(); int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } long result = 0; for(int i = 0; i < n; i++){ int v = in.nextInt(); if(2*a[i] >= v && v > 1){ long x = v/2; long y = v - x; result += x*y; }else{ result--; } } out.println(result); out.close(); } public static int[] KMP(String val) { int i = 0; int j = -1; int[] result = new int[val.length() + 1]; result[0] = -1; while (i < val.length()) { while (j >= 0 && val.charAt(j) != val.charAt(i)) { j = result[j]; } j++; i++; result[i] = j; } return result; } public static boolean nextPer(int[] data) { int i = data.length - 1; while (i > 0 && data[i] < data[i - 1]) { i--; } if (i == 0) { return false; } int j = data.length - 1; while (data[j] < data[i - 1]) { j--; } int temp = data[i - 1]; data[i - 1] = data[j]; data[j] = temp; Arrays.sort(data, i, data.length); return true; } public static int digit(long n) { int result = 0; while (n > 0) { n /= 10; result++; } return result; } public static double dist(long a, long b, long x, long y) { double val = (b - a) * (b - a) + (x - y) * (x - y); val = Math.sqrt(val); double other = x * x + a * a; other = Math.sqrt(other); return val + other; } public static class Point implements Comparable<Point> { int x, y; public Point(int start, int end) { this.x = start; this.y = end; } @Override public int hashCode() { int hash = 5; hash = 47 * hash + this.x; hash = 47 * hash + this.y; return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Point other = (Point) obj; if (this.x != other.x) { return false; } if (this.y != other.y) { return false; } return true; } @Override public int compareTo(Point o) { return x - o.x; } } public static class FT { long[] data; FT(int n) { data = new long[n]; } public void update(int index, long value) { while (index < data.length) { data[index] += value; index += (index & (-index)); } } public long get(int index) { long result = 0; while (index > 0) { result += data[index]; index -= (index & (-index)); } return result; } } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } public static long pow(long a, long b) { if (b == 0) { return 1; } if (b == 1) { return a; } long val = pow(a, b / 2); if (b % 2 == 0) { return val * val % MOD; } else { return val * (val * a % MOD) % MOD; } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() throws FileNotFoundException { // System.setOut(new PrintStream(new // BufferedOutputStream(System.out), true)); br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new InputStreamReader(new // FileInputStream(new File("input.txt")))); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { st = null; try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(); } } public boolean endLine() { try { String next = br.readLine(); while (next != null && next.trim().isEmpty()) { next = br.readLine(); } if (next == null) { return true; } st = new StringTokenizer(next); return st.hasMoreTokens(); } catch (Exception e) { throw new RuntimeException(); } } } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
96e50cd82724b7f76d65f215d8f6b57a
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author prakharjain */ 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); BInnaDimaAndSong solver = new BInnaDimaAndSong(); solver.solve(1, in, out); out.close(); } static class BInnaDimaAndSong { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(); int[] a = in.nextIntArray(n); int[] b = in.nextIntArray(n); long ans = 0; for (int i = 0; i < n; i++) { if (2 * a[i] < b[i] || b[i] == 1) { ans--; } else { if (b[i] % 2 == 0) { ans += ((long) b[i] / 2) * (b[i] / 2); } else { ans += ((long) b[i] / 2) * (b[i] / 2 + 1); } } } out.println(ans); } } 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(long i) { writer.println(i); } } 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 static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } 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 boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; ++i) array[i] = nextInt(); return array; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
711ae9e9babd86f6f7264002e7bf5d67
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
//package round229; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class B { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(); int[] a = na(n); int[] b = na(n); long ret = 0; for(int i = 0;i < n;i++){ if(2*a[i] < b[i] || b[i] == 1){ ret--; }else if(b[i] % 2 == 0){ ret += (long)(b[i]/2)*(b[i]/2); }else{ ret += (long)(b[i]/2)*(b[i]/2+1); } } out.println(ret); } void run() throws Exception { is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new B().run(); } private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
291cad6a72c05b69cafe6274fb8ff45e
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Morgrey */ 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.readInt(); int[] a = IOUtils.readIntArray(in, n); int[] b = IOUtils.readIntArray(in, n); long ans = 0; for (int i = 0; i < n; i++) { if (b[i] == 1) ans--; else if (a[i] * 2 >= b[i]) { a[i] = Math.min(a[i] * 2, b[i]); if (a[i] % 2 == 0) ans += ((a[i] / 2L) * (a[i] / 2L)); else ans += (a[i] / 2L) * ((a[i] / 2L) + 1); } else ans--; } out.printLine(ans); } } 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 printLine(long i) { writer.println(i); } } static class IOUtils { public static int[] readIntArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = in.readInt(); return array; } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public 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
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
419983d1c47f3b5fe0f811fb40e769ed
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.io.*; import java.util.*; public class B { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); Scanner s = new Scanner(System.in); int n = Integer.parseInt(f.readLine()); long[] a = new long[n], b = new long[n]; String[] split = f.readLine().split("\\s+"); for(int i = 0; i < n; i++) a[i] = Integer.parseInt(split[i]); split = f.readLine().split("\\s+"); for(int i = 0; i < n; i++) b[i] = Integer.parseInt(split[i]); long joy = 0; for(int i = 0; i < n; i++) { if(a[i]*2 < b[i]) { joy--; continue; } long add1 = b[i]/2, add2 = ((b[i]+1)/2); if(add1 < 1 || add2 < 1 || add1 > a[i] || add2 > a[i] || add1+add2 != b[i]) joy--; else joy += (b[i]/2) * ((b[i]+1)/2); } // System.out.println(); // System.out.println(bruteForce(a, b, n)); System.out.println(joy); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
cf39ef75f357a56aaba2f4f71ef699cd
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
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 hbayramov */ 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); Task solver = new Task(); solver.solve(1, in, out); out.close(); } static class Task { public void solve(int testNumber, Scanner in, PrintWriter out) { int n = in.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for (int i = 0; i < n; ++i) a[i] = in.nextInt(); for (int i = 0; i < n; ++i) b[i] = in.nextInt(); long sj = 0; for (int i = 0; i < n; ++i) { if (a[i] + a[i] < b[i] || b[i] == 1) --sj; else { int c = b[i] / 2; int d = b[i] - c; if (c > a[i]) { d = a[i]; c = b[i] - a[i]; } sj += (long) c * d; } } out.println(sj); } } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
4e23fb0d322046c1bcfeda908d483424
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.util.*; public class GFG { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long a[]=new long[n]; long b[]=new long[n]; int i; for(i=0;i<n;i++){ a[i]=sc.nextLong(); } for(i=0;i<n;i++){ b[i]=sc.nextLong(); } long sum=0; for(i=0;i<n;i++){ if(a[i]*2<b[i]) { sum-=1; continue; } else if((long)(a[i]*2)==b[i]){ if(a[i]==1){ sum+=1; } else{ sum+=(long)(a[i]*a[i]); } } else{ if(b[i]==1){ sum-=1; continue; } else if(b[i]%2==0){ long num=(long)(b[i]/2); sum+=(long)(num*num); } else{ long num=(long)(b[i]/2); sum+=(long)(num*(num+1)); } } //System.out.println(sum); } System.out.println(sum<0?"-1":sum); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
99cfe0df85648c2bd8eb7bd1591e30cf
train_001.jsonl
1392132600
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sn = new Scanner(System.in); int n = sn.nextInt(); long[] note_max = new long[n]; long[] note_target = new long[n]; for (int i = 0; i < n; ++i) note_max[i] = sn.nextLong(); long joy = 0; for (int i = 0; i < n; ++i) { note_target[i] = sn.nextLong(); if (note_target[i] != 1 && note_max[i] * 2 >= note_target[i]) joy += Math.floor((float)note_target[i] / 2) * Math.ceil((float)note_target[i] / 2); else --joy; } System.out.print(joy); sn.close(); } }
Java
["3\n1 1 2\n2 2 3", "1\n2\n5"]
1 second
["4", "-1"]
NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.
Java 8
standard input
[ "implementation" ]
986a7d97e62856d5301d5a70ea01466a
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).
null
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
standard output
PASSED
2787b243c0b5938e395e8bf0b4ba85a0
train_001.jsonl
1415205000
In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maximum difference of charisma of two children in the group (in particular, if the group consists of one child, its sociability equals a zero). The teacher wants to divide the children into some number of groups in such way that the total sociability of the groups is maximum. Help him find this value.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } static class TaskD { int n; int[] charisma; boolean[] bad; long[][] dp; long rec(int pos, int connected) { if (pos == n) return 0; long res = dp[connected][pos]; if (res != -1) return res; res = rec(pos + 1, 0); if (pos >= 1 && (bad[pos] == false || connected == 0)) { res = Math.max(res, rec(pos + 1, 1) + Math.abs(charisma[pos] - charisma[pos - 1])); } return dp[connected][pos] = res; } public void solve(int testNumber, InputReader in, PrintWriter out) { this.n = in.nextInt(); charisma = new int[n]; for (int i = 0; i < n; i++) { charisma[i] = in.nextInt(); } dp = new long[2][n]; for (long[] dp1 : dp) { Arrays.fill(dp1, -1); } bad = new boolean[n]; for (int i = 2; i < n; i++) { if (Math.signum(charisma[i] - charisma[i - 1]) != Math.signum(charisma[i - 1] - charisma[i - 2])) { bad[i] = true; } } for (int i = n - 1; i >= 0; i--) rec(i, 0); long ans = rec(0, 0); out.println(ans); } } 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\n1 2 3 1 2", "3\n3 3 3"]
2 seconds
["3", "0"]
NoteIn the first test sample one of the possible variants of an division is following: the first three children form a group with sociability 2, and the two remaining children form a group with sociability 1.In the second test sample any division leads to the same result, the sociability will be equal to 0 in each group.
Java 11
standard input
[ "dp", "greedy", "data structures" ]
406fadc8750f8ef32551916d474ae143
The first line contains integer n — the number of children in the line (1 ≤ n ≤ 106). The second line contains n integers ai — the charisma of the i-th child ( - 109 ≤ ai ≤ 109).
2,400
Print the maximum possible total sociability of all groups.
standard output
PASSED
ea8405edb6f2b0820e067330927df904
train_001.jsonl
1416238500
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.Let's assume that if the traveler covers distance rj in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.The traveler's path must end in the farthest rest point.
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.List; import java.util.StringTokenizer; public class Main { public static void main(String args[]) { InputStream inputStream = System.in; OutputStream outputStream = System.out; SolverE.InputReader in = new SolverE.InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); SolverE solver = new SolverE(); int testCount = 1; for (int i = 1; i <= testCount; i++) { solver.solve(in, out); } out.close(); } } class SolverE { int par[]; boolean dp(double k, int n, double frust[][], int b[]) { double dp[] = new double[n+1]; int tpar[] = new int[n+1]; for (int i=1; i<=n; i++) { dp[i] = -1e31; for (int j=0; j<i; j++) { double x = dp[j] + b[i] * k - frust[j][i]; dp[i] = Math.max(dp[i], x); if (dp[i] == x) { tpar[i] = j; } } } //System.out.println(k + " : " + Arrays.toString(dp)); if (dp[n] > 0) { par = tpar; //System.out.println("selected : " + k + ", parent = " + Arrays.toString(par)); } return dp[n] > 0; } public void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); int l = in.nextInt(); int x[] = new int[n+1]; int b[] = new int[n+1]; for (int i=1; i<=n; i++) { x[i] = in.nextInt(); b[i] = in.nextInt(); } double frust[][] = new double[n+1][n+1]; for (int i=0; i<=n; i++) { for (int j=i+1; j<=n; j++) { frust[i][j] = frust(x, i, j, l); } } int times = 100; double lo = 0; double hi = 1e15; for (int i=0; i<times; i++) { double mid = (lo + hi) / 2; if (dp(mid, n, frust, b)) { hi = mid; } else { lo = mid; } } //dp(0.13267268241473806, n, frust, b); //System.out.println(Arrays.toString(par)); List<Integer> sol = new ArrayList<>(); int pr = n; while (pr != 0) { sol.add(pr); pr = par[pr]; } for (int i=sol.size()-1; i>=0; i--) { out.print(sol.get(i) + " "); } out.println(); } private double frust(final int[] x, final int i, final int j, final int l) { int d = x[j] - x[i]; return Math.sqrt(Math.abs(l - d)); } static class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); } 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 9\n10 10\n20 10\n30 1\n31 5\n40 10"]
1 second
["1 2 4 5"]
NoteIn the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as .
Java 7
standard input
[ "dp", "binary search" ]
9ea7a7b892fefaaf8197cf48e92eb9f1
The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path. Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 ≤ xi, bi ≤ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
2,300
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
standard output
PASSED
c07e67d7a1987ea9c8d5a6d1fc6c08a8
train_001.jsonl
1416238500
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.Let's assume that if the traveler covers distance rj in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.The traveler's path must end in the farthest rest point.
256 megabytes
import java.util.*; public class e { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(), l = input.nextInt(); int[] xs = new int[n], bs = new int[n]; last = new int[n]; for(int i = 0; i<n; i++) { xs[i] = input.nextInt(); bs[i] = input.nextInt(); } double lo = 0, hi = 1e9; while(hi - lo > 1e-9) { double mid = (lo+hi)/2; if(possible(mid, xs, bs, l)) lo = mid; else hi = mid; } //System.out.println(lo); ArrayList<Integer> res = new ArrayList<Integer>(); int at = n-1; while(at != -1) { res.add(at+1); at = last[at]; } for(int i = res.size() -1; i>=0; i--) System.out.print(res.get(i)+" "); } static int[] last; static boolean possible(double ratio, int[] xs, int[] bs, int l) { int n = xs.length; double[] max = new double[n]; Arrays.fill(max, -1e18); for(int i = 0; i<n; i++) { double cur = i == 0 ? 0 : max[i-1]; int curx = i == 0 ? 0 : xs[i-1]; for(int j = i; j<n; j++) { double next = cur + bs[j] - ratio * Math.sqrt(Math.abs(l - (xs[j] - curx))); if(next > max[j]) { max[j] = next; last[j] = i-1; } } } //System.out.println(max[n-1]); return max[n-1] >= 0; } }
Java
["5 9\n10 10\n20 10\n30 1\n31 5\n40 10"]
1 second
["1 2 4 5"]
NoteIn the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as .
Java 7
standard input
[ "dp", "binary search" ]
9ea7a7b892fefaaf8197cf48e92eb9f1
The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path. Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 ≤ xi, bi ≤ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
2,300
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
standard output
PASSED
20ad63b3949969fddc966834f901cec2
train_001.jsonl
1416238500
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.Let's assume that if the traveler covers distance rj in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.The traveler's path must end in the farthest rest point.
256 megabytes
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) { Cf489E tmp=new Cf489E(); tmp.solve(); } } class Cf489E { static final int N=1005; static final double inf=1000000009; double x[]=new double[N]; double b[]=new double[N]; double f[]=new double[N]; int path[]=new int[N]; int n; double L; boolean cheak(double y) { Arrays.fill(f, 0); for(int i=1;i<=n;i++) { f[i]=inf; for(int j=0;j<i;j++) { double tmp=f[j]+Math.sqrt(Math.abs(x[i]-x[j]-L))-y*b[i]; if(tmp<f[i]) { f[i]=tmp; path[i]=j; } } } return f[n]<0; } void get_path(int u) { if(u==0) return; get_path(path[u]); System.out.print(u+" "); } void solve() { Scanner in=new Scanner(System.in); Arrays.fill(path,0); n=in.nextInt(); L=in.nextDouble(); x[0]=0; b[0]=0; for(int i=1;i<=n;i++) { x[i]=in.nextDouble(); b[i]=in.nextDouble(); } double l=0,r=inf/10; for(int i=0;i<100;i++) { double m=(l+r)/2; if(cheak(m)) { r=m; }else { l=m; } } get_path(n); System.out.println(); } }
Java
["5 9\n10 10\n20 10\n30 1\n31 5\n40 10"]
1 second
["1 2 4 5"]
NoteIn the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as .
Java 7
standard input
[ "dp", "binary search" ]
9ea7a7b892fefaaf8197cf48e92eb9f1
The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path. Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 ≤ xi, bi ≤ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
2,300
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
standard output
PASSED
56ce3b5f5129f70aa1178b80ef8204ba
train_001.jsonl
1416238500
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.Let's assume that if the traveler covers distance rj in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.The traveler's path must end in the farthest rest point.
256 megabytes
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) { Cf489E tmp=new Cf489E(); tmp.solve(); } } class Cf489E { static final int N=1005; static final double inf=1000000009; double x[]=new double[N]; double b[]=new double[N]; double f[]=new double[N]; int path[]=new int[N]; int n; double L; boolean cheak(double y) { Arrays.fill(f, 0); for(int i=1;i<=n;i++) { f[i]=inf; for(int j=0;j<i;j++) { double tmp=f[j]+Math.sqrt(Math.abs(x[i]-x[j]-L))-y*b[i]; if(tmp<f[i]) { f[i]=tmp; path[i]=j; } } } return f[n]<0; } void get_path(int u) { if(u==0) return; get_path(path[u]); System.out.print(u+" "); } void solve() { Scanner in=new Scanner(System.in); Arrays.fill(path,0); n=in.nextInt(); L=in.nextDouble(); x[0]=0; b[0]=0; for(int i=1;i<=n;i++) { x[i]=in.nextDouble(); b[i]=in.nextDouble(); } double l=0,r=inf/10; for(int i=0;i<50;i++) { double m=(l+r)/2; if(cheak(m)) { r=m; }else { l=m; } } get_path(n); System.out.println(); } }
Java
["5 9\n10 10\n20 10\n30 1\n31 5\n40 10"]
1 second
["1 2 4 5"]
NoteIn the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as .
Java 7
standard input
[ "dp", "binary search" ]
9ea7a7b892fefaaf8197cf48e92eb9f1
The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path. Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 ≤ xi, bi ≤ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
2,300
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
standard output
PASSED
463c138cb9b46336cc3cea1a8bf5edce
train_001.jsonl
1416238500
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.Let's assume that if the traveler covers distance rj in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.The traveler's path must end in the farthest rest point.
256 megabytes
import java.util.ArrayList; import java.io.InputStream; import java.io.InputStreamReader; import java.util.List; import java.io.BufferedReader; import java.math.BigInteger; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Collections; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author To Huu Quan */ 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); TaskE solver = new TaskE(); solver.solve(1, in, out); out.close(); } } class TaskE { final double INF = 1E18; final double EPS = 1E-9; int n, l; int[] x, b; public void solve(int testNumber, InputReader in, PrintWriter out) { n = in.nextInt(); l = in.nextInt(); x = new int[n + 1]; b = new int[n + 1]; for (int i = 1; i <= n; ++i) { x[i] = in.nextInt(); b[i] = in.nextInt(); } double low = 0, high = INF; List<Integer> res = null; while (high - low > EPS) { double mid = (low + high) / 2; List<Integer> trace = check(mid); if (trace == null) { low = mid; } else { high = mid; res = trace; } } if (res != null) { for (int u : res) out.print(u + " "); } else { throw new RuntimeException(); } } private List<Integer> check(double ans) { double[] dp = new double[n + 1]; int[] trace = new int[n + 1]; for (int i = 1; i <= n; ++i) { dp[i] = INF; for (int j = 0; j < i; ++j) if (dp[i] > dp[j] + cal(x[i] - x[j]) - ans * b[i]) { dp[i] = dp[j] + cal(x[i] - x[j]) - ans * b[i]; trace[i] = j; } } if (dp[n] > 0) return null; List<Integer> res = new ArrayList<Integer>(); for (int u = n; u != 0; u = trace[u]) res.add(u); Collections.reverse(res); return res; } private double cal(int r) { return Math.sqrt(Math.abs(r - l)); } } 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 9\n10 10\n20 10\n30 1\n31 5\n40 10"]
1 second
["1 2 4 5"]
NoteIn the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as .
Java 7
standard input
[ "dp", "binary search" ]
9ea7a7b892fefaaf8197cf48e92eb9f1
The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path. Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 ≤ xi, bi ≤ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
2,300
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
standard output
PASSED
c0c611e8e4ab3342b31ef855500a3016
train_001.jsonl
1416238500
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.Let's assume that if the traveler covers distance rj in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.The traveler's path must end in the farthest rest point.
256 megabytes
//package round277h; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class E { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), L = ni(); int[][] rest = new int[n][]; for(int i = 0;i < n;i++){ rest[i] = new int[]{ni(), ni()}; } double low = 0, high = 2000000; for(int rep = 0;rep < 70;rep++){ double h = (low + high) / 2; if(ok(h, rest, L)){ high = h; }else{ low = h; } } int[] rroute = route(high, rest, L); for(int i = rroute.length-1;i >= 0;i--){ out.print(rroute[i] + " "); } out.println(); } boolean ok(double h, int[][] rest, int L) { int n = rest.length; double[] dp = new double[n+1]; for(int i = 1;i <= n;i++){ double min = Double.POSITIVE_INFINITY; for(int j = 0;j < i;j++){ double r = rest[i-1][0] - (j == 0 ? 0 : rest[j-1][0]); min = Math.min(min, Math.sqrt(Math.abs(r-L)) + dp[j] - h * rest[i-1][1]); } dp[i] = min; } return dp[n] < 0; } int[] route(double h, int[][] rest, int L) { int n = rest.length; int[] prev = new int[n+1]; Arrays.fill(prev, -1); double[] dp = new double[n+1]; for(int i = 1;i <= n;i++){ double min = Double.POSITIVE_INFINITY; int arg = -1; for(int j = 0;j < i;j++){ double r = rest[i-1][0] - (j == 0 ? 0 : rest[j-1][0]); double v = Math.sqrt(Math.abs(r-L)) + dp[j] - h * rest[i-1][1]; if(v < min){ min = v; arg = j; } } dp[i] = min; prev[i] = arg; } int[] route = new int[n+1]; int p = 0; for(int u = n;u != 0;u = prev[u]){ route[p++] = u; } return Arrays.copyOf(route, p); } void run() throws Exception { is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new E().run(); } private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); } }
Java
["5 9\n10 10\n20 10\n30 1\n31 5\n40 10"]
1 second
["1 2 4 5"]
NoteIn the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as .
Java 7
standard input
[ "dp", "binary search" ]
9ea7a7b892fefaaf8197cf48e92eb9f1
The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path. Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 ≤ xi, bi ≤ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
2,300
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
standard output
PASSED
ad87425addcf5da2f45568573bd03bee
train_001.jsonl
1416238500
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.Let's assume that if the traveler covers distance rj in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.The traveler's path must end in the farthest rest point.
256 megabytes
import java.io.*; import java.util.*; public class hiking { private static Reader in; private static PrintWriter out; public static double[][] dist; public static void main(String[] args) throws IOException { in = new Reader(); out = new PrintWriter(System.out, true); N = in.nextInt(); L = in.nextInt(); x = new int[N+1]; b = new int[N+1]; dist = new double[N+1][N+1]; x[0] = 0; for (int i = 1; i <= N; i++) { x[i] = in.nextInt(); b[i] = in.nextInt(); } for (int i = 0; i <= N; i++) for (int j = i+1; j <= N; j++) dist[i][j] = Math.sqrt(Math.abs(x[j]-x[i]-L)); double lo = 0, hi = 1e12; for (int i = 0; i < 100; i++) { double mid = (lo + hi) / 2.; if (can(mid)) hi = mid; else lo = mid; } int[] prev = new int[N+1]; prev[0] = -1; double[] dp = new double[N+1]; for (int i = 1; i <= N; i++) { dp[i] = dist[0][i] - lo * b[i]; for (int j = i-1; j >= 0; j--) { if(dist[j][i] - lo * b[i] + dp[j] < dp[i]) { dp[i] = dist[j][i] - lo * b[i] + dp[j]; prev[i] = j; } } } ArrayList<Integer> path = new ArrayList<Integer>(); int cur = N; while (cur != 0) { path.add(cur); cur = prev[cur]; } out.print(path.get(path.size()-1)); for (int i = path.size()-2; i >= 0; i--) out.print(" "+path.get(i)); out.println(); out.close(); System.exit(0); } public static int N, L; public static int[] x, b; private static boolean can(double ratio) { double[] dp = new double[N+1]; for (int i = 1; i <= N; i++) { dp[i] = dist[0][i] - ratio * b[i]; for (int j = i-1; j >= 0; j--) { dp[i] = Math.min(dp[i], dist[j][i] - ratio * b[i] + dp[j]); } } return dp[N] < 0; } 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[1024]; int cnt = 0; byte c = read(); while (c <= ' ') c = read(); do { buf[cnt++] = c; } while ((c = read()) != '\n'); return new String(buf, 0, cnt); } public String next() throws IOException { byte[] buf = new byte[1024]; int cnt = 0; byte c = read(); while (c <= ' ') c = read(); do { buf[cnt++] = c; } while ((c = read()) > ' '); 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(); } } }
Java
["5 9\n10 10\n20 10\n30 1\n31 5\n40 10"]
1 second
["1 2 4 5"]
NoteIn the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as .
Java 7
standard input
[ "dp", "binary search" ]
9ea7a7b892fefaaf8197cf48e92eb9f1
The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path. Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 ≤ xi, bi ≤ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
2,300
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
standard output
PASSED
cc40b1bc7b348fac77ca8701e4a09c53
train_001.jsonl
1416238500
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.Let's assume that if the traveler covers distance rj in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.The traveler's path must end in the farthest rest point.
256 megabytes
import java.util.List; import java.util.Scanner; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Anudeep Nekkanti */ 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); TaskE solver = new TaskE(); solver.solve(1, in, out); out.close(); } } class TaskE { private static final double EPS = 1e-7; public void solve(int testNumber, Scanner in, PrintWriter out) { int n, l; n = in.nextInt(); l = in.nextInt(); int[] x = new int[n + 1]; int[] b = new int[n + 1]; x[0] = b[0] = 0; for (int i = 0; i < n; i++) { x[i + 1] = in.nextInt(); b[i + 1] = in.nextInt(); } double lo = 0, hi = 1000 * 1000 * 1000; double best[] = new double[n + 1]; while (lo < (hi - EPS)) { double mid = (lo + hi) * 0.5; best[0] = 0; for (int i = 1; i <= n; i++) { best[i] = 1000 * 1000 * 1000; for (int j = 0; j < i; j++) { double cur = best[j] + Math.sqrt(Math.abs((x[i] - x[j]) - l)); if (cur < best[i]) best[i] = cur; } best[i] -= mid * b[i]; } if (best[n] > 0) { lo = mid; } else { hi = mid; } } best[0] = 0; int[] prev = new int[n + 1]; prev[0] = -1; for (int i = 1; i <= n; i++) { best[i] = 1000 * 1000 * 1000; for (int j = 0; j < i; j++) { double cur = best[j] + Math.sqrt(Math.abs((x[i] - x[j]) - l)); if (cur < best[i]) { prev[i] = j; best[i] = cur; } } best[i] -= lo * b[i]; } List<Integer> li; li = new ArrayList<>(); while (n != 0) { li.add(n); n = prev[n]; } Collections.reverse(li); for (Integer aLi : li) { out.printf("%d ", aLi); } out.println(); } }
Java
["5 9\n10 10\n20 10\n30 1\n31 5\n40 10"]
1 second
["1 2 4 5"]
NoteIn the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as .
Java 7
standard input
[ "dp", "binary search" ]
9ea7a7b892fefaaf8197cf48e92eb9f1
The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path. Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 ≤ xi, bi ≤ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
2,300
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
standard output
PASSED
31bab8e414d6e29f94ac64d9573b9a5c
train_001.jsonl
1416238500
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.Let's assume that if the traveler covers distance rj in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.The traveler's path must end in the farthest rest point.
256 megabytes
import java.io.IOException; import java.util.Arrays; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author George Marcus */ 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); TaskE solver = new TaskE(); solver.solve(1, in, out); out.close(); } } class TaskE { double[] dp; int[] prev; int[] x; int[] b; int len; int N; public void solve(int testNumber, InputReader in, PrintWriter out) { N = in.nextInt(); len = in.nextInt(); // N = 1000; x = new int[N + 1]; b = new int[N + 1]; for (int i = 1; i <= N; i++) { x[i] = in.nextInt(); b[i] = in.nextInt(); // x[i] = i * 1000; // b[i] = 1000000 - x[i]; } dp = new double[N + 1]; prev = new int[N + 1]; double st = 0.0; double dr = 1e7; double m; for (int it = 0; it < 50; it++) { m = (st + dr) / 2; go(m); if (dp[N] > 0.0) { st = m; } else { dr = m; } } m = (st + dr) / 2; go(m); // System.out.println(m); int i = N; int[] path = new int[N + 1]; int p = 0; while (i != -1) { path[p++] = i; i = prev[i]; } for (int j = p - 2; j >= 0; j--) { if (j < p - 2) { out.print(" "); } out.print(path[j]); } out.println(); } private void go(double m) { Arrays.fill(dp, 1e100); dp[0] = 0; prev[0] = -1; for (int i = 0; i <= N; i++) { int d = 0; for (int j = i + 1; j <= N; j++) { d += x[j] - x[j - 1]; double crt = Math.sqrt(Math.abs(d - len)) - m * b[j]; if (dp[i] + crt < dp[j]) { dp[j] = dp[i] + crt; prev[j] = i; } } } } } class InputReader { 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 nextInt() { return Integer.parseInt(nextString()); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } }
Java
["5 9\n10 10\n20 10\n30 1\n31 5\n40 10"]
1 second
["1 2 4 5"]
NoteIn the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as .
Java 7
standard input
[ "dp", "binary search" ]
9ea7a7b892fefaaf8197cf48e92eb9f1
The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path. Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 ≤ xi, bi ≤ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
2,300
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
standard output