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
9d87003c1ecf7920e91f1883560422b6
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.util.Scanner; public class A1277 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); int t=input.nextInt(); int[] result=new int[t]; for(int j=0;j<t;j++) { int n=input.nextInt(),count=0; long l=(long) Math.floor(Math.log10(n))+1,x=((long)(Math.pow(10, l))-1)/9,y=x; count+=9*(int)(Math.floor(Math.log10(n))); while(y<=n) { count++; y+=x; } result[j]=count; } for(int x:result) System.out.println(x); } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
5c280a60944961d43f303cf25ff4ce0a
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Reader in = new Reader(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); out: while (t-- > 0) { String n = in.next(); int ans = (n.length()-1)*9; int f = Character.getNumericValue(n.charAt(0)); int prev = f; for (int i = 1; i < n.length(); i++) { int d = Character.getNumericValue(n.charAt(i)); if (d < prev) { out.println(ans + f - 1); continue out; } if (d > prev) { out.println(ans + f); continue out; } prev = d; } out.println(ans + f); } out.close(); } private static class Reader { private StringTokenizer tk; private BufferedReader in; Reader () { in = new BufferedReader(new InputStreamReader(System.in)); } int nextInt() { return Integer.parseInt(next()); } String next() { if (tk == null || !tk.hasMoreElements()) { try { tk = new StringTokenizer(in.readLine()); } catch (IOException ignored) { } } return tk.nextToken(); } } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
5e1397f7b0075282a0204a4cf06edd9a
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Reader in = new Reader(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); while (t-- > 0) { String n = in.next(); int f = n.charAt(0); int len = n.length(); int ans = (len-1)*9 + f - '0'; for (int i = 1; i < len; i++) { if (n.charAt(i) < f) { ans--; break; } if (n.charAt(i) > f) { break; } } out.println(ans); } out.close(); } private static class Reader { private StringTokenizer tk; private BufferedReader in; Reader () { in = new BufferedReader(new InputStreamReader(System.in)); } int nextInt() { return Integer.parseInt(next()); } String next() { if (tk == null || !tk.hasMoreElements()) { try { tk = new StringTokenizer(in.readLine()); } catch (IOException ignored) { } } return tk.nextToken(); } } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
951abe1b6b56669912f2733c441dcdba
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Reader in = new Reader(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); out: while (t-- > 0) { String n = in.next(); int f = n.charAt(0) - '0'; int ans = (n.length()-1)*9 + f; for (int i = 1; i < n.length(); i++) { int d = n.charAt(i) - '0'; if (d < f) { out.println(ans - 1); continue out; } if (d > f) { out.println(ans); continue out; } } out.println(ans); } out.close(); } private static class Reader { private StringTokenizer tk; private BufferedReader in; Reader () { in = new BufferedReader(new InputStreamReader(System.in)); } int nextInt() { return Integer.parseInt(next()); } String next() { if (tk == null || !tk.hasMoreElements()) { try { tk = new StringTokenizer(in.readLine()); } catch (IOException ignored) { } } return tk.nextToken(); } } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
06c775a5f9217bceacdcf1920656604f
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Reader in = new Reader(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); while (t-- > 0) { String n = in.next(); int f = n.charAt(0); int ans = (n.length()-1)*9 + f - '0'; boolean flag = false; for (int i = 1; i < n.length(); i++) { if (n.charAt(i) < f) { flag = true; break; } if (n.charAt(i) > f) { break ; } } if (flag) ans--; out.println(ans); } out.close(); } private static class Reader { private StringTokenizer tk; private BufferedReader in; Reader () { in = new BufferedReader(new InputStreamReader(System.in)); } int nextInt() { return Integer.parseInt(next()); } String next() { if (tk == null || !tk.hasMoreElements()) { try { tk = new StringTokenizer(in.readLine()); } catch (IOException ignored) { } } return tk.nextToken(); } } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
ae2c42ecf9f04af72a8c02ce60fbb4e2
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.util.*; public class polycarp { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { long n=sc.nextLong(); long b = 0;long ans = 0; for (long len = 1; len <= 9; len++) { b = b * 10 + 1; for (long m = 1; m <= 9; m++) if (b * m <= n) ans++; } System.out.println(ans); } } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
5a189998432971d91e27820a7aba63d7
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.util.*; import java.lang.*; import java.math.*; import java.text.*; import java.io.*; public class Solution { static PrintWriter out = new PrintWriter(System.out); static void flush() { out.flush(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try{ st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } static int fact(int n) { if(n == 1) return 1; return n * fact(n-1); } public int[] readIntArray(int n) { int[] arr = new int[n]; for(int i=0; i<n; ++i) arr[i]=nextInt(); return arr; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int solve(int n) { int count =0; if(n/10 == 0) { return n%10; } else if(n/100 == 0) { return 9 + n/11; } else { String str = Integer.toString(n); count = 9*(str.length()-1); String str1 = ""; for(int i=0;i<str.length();i++) { str1 += "1"; } int d = 2; StringBuilder sb = new StringBuilder(); sb.append(1); int p = 0; while(true) { if(str1.length() <= 9) { p = Integer.parseInt(str1); } else { break; } if(n/p != 0) { StringBuilder sb1 = new StringBuilder(); sb1.append(d); count++; str1 = str1.replaceAll(sb.toString(), sb1.toString()); d++; sb = new StringBuilder(); sb.append(sb1.toString()); } else { break; } } } return count; } public static void main(String args[]) throws Exception { FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-- > 0 ) { int n = sc.nextInt(); out.println(solve(n)); flush(); } long end = System.currentTimeMillis(); NumberFormat formatter = new DecimalFormat("#0.00000"); //System.out.print("Execution time is " + formatter.format((end - start) / 1000d) + " seconds"); } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
cf61e4ea18a972d5ebb8afca1009bb5b
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = s.nextInt(); } for (int i = 0; i < n; i++) { System.out.println(numBeauty(a[i])); } } public static int numBeauty(int n) { if (n < 10) return n; String a = Integer.toString(n); // 454654 int x = a.length()-1; int b = great(a); return x*9 + b; } public static int great(String a) { int fir = Character.getNumericValue(a.charAt(0)); int sec = Character.getNumericValue(a.charAt(1)); if (sec > fir) return fir; if (fir == sec) { boolean more = true; int cur = 0; for (int i = 2; i < a.length(); i++) { cur = Character.getNumericValue(a.charAt(i)); if (cur > sec) { break; } if (cur < sec) { more = false; break; } } if (more) { return fir; } else { return fir-1; } } return fir-1; } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
429c4a368ae90a3deea230d4c9e6feaa
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.io.*; import java.util.*; public class vk18 { public static void main(String[]st) throws Exception { Scanner scan=new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s; int q=Integer.parseInt(br.readLine()); while(q!=0) { int i; String na=br.readLine(); String sb=""; //char c[]=new char[na.length()]; for(i=0;i<na.length();i++) sb+="1"; //String sb=c.toString(); int ans=(na.length()-1)*9; int p1=Integer.parseInt(na); int p2=Integer.parseInt(sb); int div=(int)(p1/p2); ans+=div; System.out.println(ans); q--; } } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
b8c3adddb1200a5c16256b90bfab4191
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
// Java program For handling Input/Output import java.io.*; import java.util.*; import java.math.*; //import java.awt.*; public class Main { Scanner sc; Map<Integer, List<Integer>> graph = new HashMap<>(); //actual logic void solve(){ int t = ni(); while(t-- > 0) { int n = ni(); String div = ""; for(int i = 0;i < (n+"").length();i++) div += "1"; System.out.println(9 * ((n+"").length()-1) + n/Integer.parseInt(div)); } } //constructor Main(){ try{ sc = new Scanner(System.in); }catch(Exception e){ System.out.println(e); } } //main metohd public static void main(String[] args) { new Main().solve(); } //Utility methods void graphInput(int n) { for(int i = 0;i < n;i++) { int a = ni(); int b = ni(); if(!graph.containsKey(a)) { List<Integer> l = new ArrayList<>(); l.add(b); graph.put(a, l); } else graph.get(a).add(b); } System.out.println(graph); } void bfs(int nodes) { Queue<Integer> q = new LinkedList<>(); int visited[] = new int[nodes+1]; q.add(1); while(!q.isEmpty()) { System.out.print(q.peek() + " "); visited[q.peek()] = 1; if(graph.get(q.peek()) != null) { for(int i: graph.get(q.peek())) { if(visited[i] != 1) q.add(i); } } q.poll(); } } //input an integer from scanner int ni() { int a = sc.nextInt(); return a; } //input a long from scanner long nl() { return sc.nextLong(); } //input a float from scanner float nf(){ float a = sc.nextFloat(); return a; } //input a double from scanner double nd(){ double a = sc.nextDouble(); return a; } //input a sentence from scanner String ns(){ return sc.nextLine(); } //converts a string to stringtokenizer StringTokenizer nst(String s){ return new StringTokenizer(s); } //input an intger array void ia(int a[]){ for(int i = 0;i < a.length;i++) a[i] = sc.nextInt(); } // void la(long a[]){ for(int i = 0;i < a.length;i++) a[i] = sc.nextLong(); } //input a float array void fa(float a[]){ for(int i = 0;i < a.length;i++) a[i] = sc.nextFloat(); } //input a double array void da(double a[]){ for(int i = 0;i < a.length;i++) a[i] = sc.nextDouble(); } //input a string array either with all empty input or from scanner void sa(String a[], boolean empty){ if(empty) { for(int i = 0;i < a.length;i++) { a[i] = ""; } } else { for(int i = 0;i < a.length;i++) { a[i] = ns(); } } } //input two dimensional integer array void ida(int a[][], int n, int m) { for(int i = 0;i < n;i++) { for(int j = 0;j < m;j++) { a[i][j] = ni(); } } } //input two dimentional long array void lda(long a[][], int n, int m) { for(int i = 0;i < n;i++) { for(int j = 0;j < m;j++) { a[i][j] = nl(); } } } //input two dimensional double array void dda(double a[][], int n, int m) { for(int i = 0;i < n;i++) { for(int j = 0;j < m;j++) { a[i][j] = nd(); } } } //convert string to integer int stoi(String s){ return Integer.parseInt(s); } //convert string to double double stod(String s){ return Double.parseDouble(s); } //find minimum in a long array long lmin(long a[]) { long min = Long.MAX_VALUE; for(int i = 0;i < a.length;i++) { if(min > a[i]) min = a[i]; } return min; } //find minimum in a integer array int imin(int a[]) { int min = Integer.MAX_VALUE; for(int i = 0;i < a.length;i++) { if(min > a[i]) min = a[i]; } return min; } //find maximum in a long array long lmax(long a[]) { long max = Long.MIN_VALUE; for(int i = 0;i < a.length;i++) { if(max < a[i]) max = a[i]; } return max; } //find maximum in an integer array int imax(int a[]) { int max = Integer.MIN_VALUE; for(int i = 0;i < a.length;i++) { if(max < a[i]) max = a[i]; } return max; } //check whether an element is present in an integer array by binary search boolean ibs(int a[], int toFind) { Arrays.sort(a); int min = 0; int max = a.length-1; boolean found = false; while(min <= max && !found) { int mid = min + (max-min)/2; if(a[mid] == toFind) { found = true; } else if(toFind > a[mid]) { min = mid+1; } else { max = mid-1; } } return found; } //check whether an element is present in a long array boolean lbs(long a[], long toFind) { Arrays.sort(a); int min = 0; int max = a.length-1; boolean found = false; while(min <= max && !found) { int mid = min + (max-min)/2; if(a[mid] == toFind) { found = true; } else if(toFind > a[mid]) { min = mid+1; } else { max = mid-1; } } return found; } int stb(String s) { int sum = 0; int k = 0; for(int i = s.length()-1;i >= 0;i--) { sum += stoi(s.charAt(i)+"") * Math.pow(2, k++); } return sum; } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
17cc9711c7c9678c0d97ed69550b31a0
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Random; import java.util.StringTokenizer; public class nA { boolean isGood(int x) { int z = x % 10; x /= 10; while (x > 0) { if (x % 10 != z) { return false; } x /= 10; } return true; } public void run() throws NumberFormatException, IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(System.out); final int t = nextInt(); for (int i = 0; i < t; i++) { String s = br.readLine(); final int n = Integer.parseInt(s); long k = 0; int nn = n; while (nn > 0) { nn /= 10; k++; } long sum = (k - 1) * 9; int x = Integer.parseInt(s.substring(0, 1)); sum += x - 1; char[] ch = s.toCharArray(); boolean flag = true; int q = x; for (int j = 0; j < k - 1; j++) { q = 10 * q + x; } if (q <= n) { sum++; } pw.println(sum); } pw.close(); } StringTokenizer st; BufferedReader br; PrintWriter pw; public static void main(String[] args) throws IOException { new nA().run(); } public String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } public int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(nextToken()); } public long nextLong() throws NumberFormatException, IOException { return Long.parseLong(nextToken()); } public double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(nextToken()); } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
0860c93966a70077da9526e89bb881fe
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.io.*; import java.util.*; public class test { public static void main(String args[]) { Scanner sc =new Scanner(System.in); int test=sc.nextInt(); for(int j=0;j<test;j++) { int c=sc.nextInt(); int o=c; int re; int b=Integer.toString(o).length(); if(b==1) { re=c; } else{ re=(b-1)*9; int ne=0; for(int i=1;i<=b;i++) { ne=ne*10+1; } int l=1,k=ne; while(k<=c) { re++; l++; k=ne*l; } } System.out.println(re); } } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
346022a911a76646f18cac20e79fbc36
train_003.jsonl
1576321500
Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.
256 megabytes
import java.util.*; public class CodeForces1277A{ public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int[] a = new int[n]; for(int i = 0;i<n;i++){ a[i] = input.nextInt(); } int[] arr = new int[n]; for(int i = 0;i<n;i++){ arr[i] = isBool(a[i]); } for(int i = 0;i<arr.length;i++){ System.out.println(arr[i]); } } public static int isBool(int a){ int n = 10; int count = 0; int ans = 0; if(a < 10){ return a; } else{ while(a / n >= 1){ count++; n*=10; } String s = "10"; for(int i = 1;i<count;i++){ s+="0"; } String l = ""; if(a-Integer.parseInt(s) != 0){ int m = s.length() - 1; for(int i = 0;i<m;i++){ l+="1"; } for(int i = Integer.parseInt(s) + Integer.parseInt(l);i<=a;i+=Integer.parseInt(s) + Integer.parseInt(l)){ ans++; } } return count * 9 + ans; } } }
Java
["6\n18\n1\n9\n100500\n33\n1000000000"]
1 second
["10\n1\n9\n45\n12\n81"]
NoteIn the first test case of the example beautiful years are $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$7$$$, $$$8$$$, $$$9$$$ and $$$11$$$.
Java 8
standard input
[ "implementation" ]
99a5b21a5984d5248e82f843f82e9420
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) β€” how many years Polycarp has turned.
1,000
Print $$$t$$$ integers β€” the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.
standard output
PASSED
da9b5b35bd75fbf7a89dcdcfd2dff1b6
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
public class Main { public static void main(String[] args) { java.util.Scanner sc = new java.util.Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int prevX = sc.nextInt(); int prevY = sc.nextInt(); double distance = 0; for (int i = 1; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); distance += Math.sqrt(Math.pow(x-prevX, 2) + Math.pow(y-prevY, 2)); prevX = x; prevY = y; } System.out.println(distance/50*k); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
d5d4e0a9c7fe427687de3dc61bc77685
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.text.DecimalFormat; import java.io.IOException; import java.io.InputStreamReader; import java.text.NumberFormat; import java.util.StringTokenizer; import java.io.BufferedReader; 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); AWastedTime solver = new AWastedTime(); solver.solve(1, in, out); out.close(); } static class AWastedTime { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int k = in.nextInt(); Pair[] a = new Pair[n]; for (int i = 0; i < n; i++) { a[i] = new Pair(in.nextInt(), in.nextInt()); } double ans = 0; for (int i = 0; i < n - 1; i++) { long dx = a[i].u - a[i + 1].u; long dy = a[i].v - a[i + 1].v; double d = Math.sqrt(dx * dx + dy * dy); ans += d; } ans *= k; ans /= 50.0; DecimalFormat df = new DecimalFormat("#0.000000000"); out.println(df.format(ans)); } public class Pair implements Comparable<Pair> { final long u; final long v; public Pair(long u, long v) { this.u = u; this.v = v; } public int hashCode() { int hu = (int) (u ^ (u >>> 32)); int hv = (int) (v ^ (v >>> 32)); return 31 * hu + hv; } public boolean equals(Object o) { Pair other = (Pair) o; return u == other.u && v == other.v; } public int compareTo(Pair other) { return Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v); } public String toString() { return "[u=" + u + ", v=" + v + "]"; } } } 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
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
4b28322009a806c19f5af5500ffad9e6
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Input cin = new Input(inputStream); Output cout = new Output(outputStream); StringBuilder sb = new StringBuilder(); long n = cin.nextLong(), k = cin.nextLong(), x1 = cin.nextLong(), y1 = cin.nextLong(), x2, y2; double d = 0, w; for (int i = 1; i < n; i++) { x2 = cin.nextLong(); y2 = cin.nextLong(); d += Math.sqrt(Math.pow(x2-x1, 2) + Math.pow(y2-y1, 2)); x1 = x2; y1 = y2; } w = round((d/50) * k, 6); sb.append(w); cout.println(sb.toString().trim()); cout.close(); } public static double round(double valueToRound, int numberOfDecimalPlaces) { double multipicationFactor = Math.pow(10, numberOfDecimalPlaces); double interestedInZeroDPs = valueToRound * multipicationFactor; return Math.round(interestedInZeroDPs) / multipicationFactor; } static class Output { private final PrintWriter writer; Output(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public Output(Writer writer) { this.writer = new PrintWriter(writer); } void close() { writer.close(); } void println(Object i) { writer.println(i); } void print(Object i) { writer.print(i); } } static class Input { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private Input.SpaceCharFilter filter; Input(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++]; } String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } int nextInt() { return Integer.parseInt(this.next()); } long nextLong() { return Long.parseLong(this.next()); } boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } String next() { return nextString(); } public interface SpaceCharFilter { boolean isSpaceChar(int ch); } } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
a1b068bcdf72d254de5e625e4ad3babb
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.text.DecimalFormat; import java.util.Scanner; public class CF127AWastedTime { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int k = s.nextInt(); int[][] dat = new int[n][2]; for (int i = 0; i < n; i++) { dat[i][0] = s.nextInt(); dat[i][1] = s.nextInt(); } double res = 0.0; for (int i =1; i < dat.length; i++) { int xi = Math.abs(dat[i][0])+Math.abs(dat[i-1][0]); if(((dat[i][0])>0&&(dat[i-1][0])>0)||(dat[i][0])<0&&(dat[i-1][0])<0) { xi = Math.abs(dat[i][0])-Math.abs(dat[i-1][0]); } int yi =Math.abs(dat[i][1])+Math.abs(dat[i-1][1]); if(((dat[i][1])>0&&(dat[i-1][1])>0)||((dat[i][1])<0&&(dat[i-1][1])<0)) { yi = Math.abs(dat[i][1])-Math.abs(dat[i-1][1]); } res+= Math.sqrt(Math.pow(xi,2)+Math.pow(yi,2)); } res=res/50; DecimalFormat df2 = new DecimalFormat("#.#########"); System.out.println(df2.format(res*k).replace(',', '.')); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
04bc695a84680f0a81c2701baed436e7
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ // package waste_time; import java.util.Scanner; /** * * @author Ahmed_Martin */ public class Waste_time { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner f=new Scanner(System.in); int n=f.nextInt(); int k=f.nextInt(); int x=f.nextInt(); int y=f.nextInt(); double sum=0; for(int i=0;i<n-1;i++){ int x1=f.nextInt(); int y1=f.nextInt(); sum+=Math.sqrt((Math.pow(x-x1,2))+(Math.pow(y-y1,2))); x=x1; y=y1; } System.out.printf("%.9f",(sum/50)*k); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
7cf18df232571e50f7178f4acca53c21
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; import java.lang.Math; import java.util.LinkedList; import java.util.Queue; public class knk { public static void main(String[] args) { Scanner in = new Scanner(System.in) ; double d =0 ; int n = in.nextInt() ; int k = in.nextInt() ; double x1 = in.nextDouble() ; double y1 = in.nextDouble() ; for(int i = 1 ; i< n ;i++ ) { double x2 = in.nextDouble() ; double y2 = in.nextDouble() ; d += Math.sqrt(Math.pow(( x2-x1),2) + Math.pow(( y2-y1),2)) ; x1 = x2 ; y1 = y2 ; } double ans = (k * d) / 50.0 ; System.out.printf("%.9f",ans) ; } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
ee58016d205e275d1c647266aa16aea5
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; public class Solution{ public static void main(String args[]) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int k = input.nextInt(); float distance = 0; int xo = input.nextInt(), yo = input.nextInt(); for(int i=1; i<n; i++) { int xn = input.nextInt(); int yn = input.nextInt(); distance += (float) Math.sqrt( (xn-xo)*(xn-xo) + (yn-yo)*(yn-yo) ); xo = xn; yo = yn; } input.close(); System.out.println((distance*k)/50); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
d6a564c07290736458c9a64f1ec837fd
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
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 */ 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 N = in.nextInt(); int K = in.nextInt(); int previousX = in.nextInt(); int previousY = in.nextInt(); double time = 0; for (int i = 0; i < N - 1; i++) { int currentX = in.nextInt(); int currentY = in.nextInt(); double distance = getDistance(previousX, previousY, currentX, currentY); time += distance / 50; previousX = currentX; previousY = currentY; } out.print((K * time)); } private double getDistance(int previousX, int previousY, int currentX, int currentY) { return Math.sqrt(Math.pow(currentX - previousX, 2) + Math.pow(currentY - previousY, 2)); } } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
9af760f73b67f39a24ad0344682c7fb6
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
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 */ 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 N = in.nextInt(); int K = in.nextInt(); int previousX = in.nextInt(); int previousY = in.nextInt(); double time = 0; for (int i = 0; i < N - 1; i++) { int currentX = in.nextInt(); int currentY = in.nextInt(); double distance = Math.sqrt(Math.pow(currentX - previousX, 2) + Math.pow(currentY - previousY, 2)); time += distance / 50; previousX = currentX; previousY = currentY; } out.print(String.format("%.9f", (K * time))); } } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
b158c43dd03cd6ff6fbf76739ae8a84e
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import static java.lang.Integer.parseInt; public class Main { private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); private static StringBuilder out = new StringBuilder(); private static StringTokenizer ReadNextLine() throws IOException { return new StringTokenizer(in.readLine()); } static class Point { private int x; private int y; Point() { this(0,0); } Point(Point Other) { this(Other.x, Other.y); } Point(int x, int y) { setX(x); setY(y); } double Dist(Point Other) { return Math.hypot(x - Other.x, y - Other.y); } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } } public static void main(String[] args) throws IOException { StringTokenizer LineReader; LineReader = ReadNextLine(); int n = parseInt(LineReader.nextToken()); int k = parseInt(LineReader.nextToken()); Point[] A = new Point[n]; double Ans = 0.0; for(int i = 0; i < n; i++) { LineReader = ReadNextLine(); A[i] = new Point(parseInt(LineReader.nextToken()), parseInt(LineReader.nextToken())); if(i > 0) { Ans += A[i].Dist(A[i - 1]) / 50.0; } } Ans *= k; System.out.println(Ans); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
265bc5f469eafd435fcc27767114aac2
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class Main { private static double dist(int x1, int y1, int x2, int y2) { return Math.sqrt(Math.pow(x1-x2,2) + Math.pow(y1-y2,2)); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); double total = 0; int x1 = sc.nextInt(); int y1 = sc.nextInt(); for (int i = 1; i < n; i++) { int x2 = sc.nextInt(); int y2 = sc.nextInt(); total += dist(x1,y1,x2,y2); x1 = x2; y1 = y2; } System.out.println(total*k/50); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
4e2d5e1da9d55ec31e60e9ee6eaf43a7
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; /** * * @author lenovo 110 */ public class wasted_time { public static double distance(int x1, int y1, int x2, int y2) { return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } public static void main(String[] args) { Scanner in = new Scanner(System.in); int points = in.nextInt(); int papaers = in.nextInt(); int x1 = in.nextInt(); int y1 = in.nextInt(); double totalDistance = 0; for (int i = 1; i < points; i++) { int x2 = in.nextInt(); int y2 = in.nextInt(); totalDistance += distance(x1, y1, x2, y2); x1 = x2; y1 = y2; } double time = totalDistance / 50; System.out.println(time * papaers); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
8aeb20469b399ceb0863749c4997cac7
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; import java.io.*; public class prb{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); double[][] q = new double[n][2]; for(int i=0; i<n; i++){ q[i][0] = in.nextInt(); q[i][1] = in.nextInt(); } double dist = 0; for(int i=0; i<n-1; i++){ dist += Math.sqrt(Math.pow(q[i][0] - q[i+1][0],2) + Math.pow(q[i][1] - q[i+1][1], 2)); } dist *= k; dist/=50.0; System.out.printf("%.10f\n", dist); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
a49faf99034a35b8802609367c8db8e6
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class A127 { public static BufferedReader read = null; public static PrintWriter out = null; public static StringTokenizer token = null; public static void solve() { int n = nint(); int k = nint(); double[][] a = new double[n][2]; for(int i=0; i<n; i++) { a[i][0] = nint(); a[i][1] = nint(); } double td = 0; for(int i = 1; i<n; i++) { td+= Math.sqrt(Math.pow(a[i][0]-a[i-1][0], 2) + Math.pow(a[i][1]-a[i-1][1], 2)); } td/=50.00; td*=k; out.printf("%.14f", td); } public static void main(String[] args) { read = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.flush(); out.close(); } // i/o functions public static String next() // returns the next string { while(token == null || !token.hasMoreTokens()) { try { token = new StringTokenizer(read.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return token.nextToken(); } public static int nint() { return Integer.parseInt(next()); } public static long nlong() { return Long.parseLong(next()); } public static double ndouble() { return Double.parseDouble(next()); } public static int[] narr(int n) { int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = nint(); return a; } public static long[] nal(int n) { long[] a = new long[n]; for(int i=0; i<n; i++) a[i] = nlong(); return a; } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
ec8162d8cff77a56aace7289897a06c9
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class CF127_D2_A { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int k = scanner.nextInt(); Pair[] pairs = new Pair[n]; for (int i = 0; i < n; i++) { int x = scanner.nextInt(); int y = scanner.nextInt(); pairs[i] = new Pair(x, y); } double distance = 0d; for (int i = 0; i < n - 1; i++) { distance += calculateDistance(pairs[i], pairs[i + 1]); } // System.out.println(distance); distance /= 50; distance *= k; System.out.println(String.format("%.09f", distance)); } private static double calculateDistance(Pair p1, Pair p2) { return Math.sqrt(Math.pow(p1.x - p2.x,2) + Math.pow(p1.y - p2.y,2) ); } static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
5f08ebaa8c5c487f9ece5a4ad52e81b2
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; public class CFA81{ public static void main(String args[]){ Scanner ob=new Scanner(System.in); // System.out.println("KSJ"); int n=ob.nextInt(); int k=ob.nextInt(); int x[]=new int[n]; int y[]=new int[n]; for(int i=0;i<n;i++){ x[i]=ob.nextInt(); y[i]=ob.nextInt(); } double sum=0.0; for(int i=0;i<n-1;i++){ sum+=Math.sqrt((x[i]-x[i+1])*(x[i]-x[i+1])+(y[i]-y[i+1])*(y[i]-y[i+1])); } //System.out.println(sum); System.out.printf("%.9f",(sum/50)*k); System.out.println(); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
1d83d4c6ea0a770e609f4b2d3bea168f
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class WastedTime { public static void main(String[] args) { Scanner input = new Scanner (System.in); int n = input.nextInt(); int k = input.nextInt(); int [] x = new int [n]; int [] y = new int [n]; double sum = 0.0; x[0] = input.nextInt(); y[0] = input.nextInt(); for (int i = 1 ; i < n ; i++) { x[i] = input.nextInt(); y[i] = input.nextInt(); int xdif = (x[i] - x[i-1]) * (x[i] - x[i-1]); int ydif = (y[i] - y[i-1]) * (y[i] - y[i-1]); double d = Math.sqrt(xdif + ydif); sum += d; } System.out.println(sum * k / 50.0); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
4d6f79a672c35749780add13ba416eab
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class test { public static Double dista(int x1,int y1,int x2,int y2) { return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1-y2, 2)); } public static void main(String [] args) { Scanner sc = new Scanner(); int n = sc.nextInt(); int k = sc.nextInt(); int xS [] = new int[n]; int yS [] = new int[n]; for(int i=0;i<n;i++) { xS[i] = sc.nextInt(); yS[i] = sc.nextInt(); } double sum = 0; for(int i=0;i+1<n;i++) { sum += dista(xS[i], yS[i], xS[i+1], yS[i+1]); } sum = sum * k; sum = sum/50f; System.out.printf("%.9f",sum); } static class Scanner{ BufferedReader br; StringTokenizer st; public Scanner() { 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
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
107b01b963d23539b8fd324e43cafffa
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class ATimeSpend { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt(); double ans = 0; for(int i=0; i<n-1; i++) { int x = sc.nextInt(); int y = sc.nextInt(); int t = x - a; int s = y -b; int ts = t*t + s*s; //System.out.println(t +" "+ s + " "+ts); ans = ans + Math.sqrt(ts); a = x; b =y; } System.out.println(String.format("%.9f" ,(ans * k)/50)); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
56a03d2ea1a7b3a83e4bff896ac7050d
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.util.*; public class Main { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n=ni(); int k=ni(); double dis=0.0; int x1=ni(),y1=ni(),x2=ni(),y2=ni(); dis+=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); x1=x2; y1=y2; for(int i=2;i<n;i++){ x2=ni(); y2=ni(); dis+=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); x1=x2; y1=y2; } out.println((dis/50.0)*k); } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.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 void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
39eb18570c4b68b0396cf92e02eefecd
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.util.*; public class Main{ InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n=ni(); int k=ni(); double dis=0.0; int x1=ni(),y1=ni(),x2=ni(),y2=ni(); dis+=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); x1=x2; y1=y2; for(int i=2;i<n;i++){ x2=ni(); y2=ni(); dis+=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); x1=x2; y1=y2; } out.println((dis/50.0)*k); } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.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 void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
d4697e87376b71deef520bcbfa34ebf9
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.awt.*; import java.util.Scanner; public class Wasted_Time { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt() -1; int k = sc.nextInt(); Point p1 = new Point(sc.nextInt(),sc.nextInt()); //Point p = new Point(); double total = 0; while(n-- >0) { Point tmp = new Point(sc.nextInt(),sc.nextInt()) ; total += tmp.distance(p1); // System.out.println(total); p1.x = tmp.x; p1.y = tmp.y; } System.out.println((total/50.0) * k ); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
b5b6dad31a521726a31d568e7ddf9c49
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; import java.io.*; public class a{ public static void main(String[]args)throws Exception{ // File f=new File("/home/ujjwal/Desktop/hi.txt"); Scanner sc=new Scanner(System.in);//wuffuw double n=sc.nextDouble(),k=sc.nextDouble(),x[]=new double[(int)n],y[]=new double[(int)n]; for(int i=0;i<n;i++){ x[i]=sc.nextDouble(); y[i]=sc.nextDouble(); } double diffx=0,diffy=0,le=0,tle=0,time=0; for(int i=0;i<n-1;i++){ diffx=x[i]-x[i+1]; diffy=y[i]-y[i+1]; le=Math.sqrt((diffx*diffx)+(diffy*diffy)); tle=tle+le; } time=(tle*k)/(50.0); System.out.println(time); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
557052e6b5aca1d469c3d740db42b120
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; import java.io.*; public class a{ public static void main(String[]args)throws Exception{ // File f=new File("/home/ujjwal/Desktop/hi.txt"); Scanner sc=new Scanner(System.in);//wuffuw double n=sc.nextDouble(),k=sc.nextDouble(),x[]=new double[(int)n],y[]=new double[(int)n]; for(int i=0;i<n;i++){ x[i]=sc.nextDouble(); y[i]=sc.nextDouble(); } double diffx=0,diffy=0,le=0,tle=0,time=0; for(int i=0;i<n-1;i++){ diffx=Math.abs(x[i]-x[i+1]); diffy=Math.abs(y[i]-y[i+1]); le=Math.sqrt((diffx*diffx)+(diffy*diffy)); tle=tle+le; } time=(tle*k)/(50.0); System.out.println(time); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
f74e784849fb1c2c038afff60a3f4fc0
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class WastedTime { public static void main (String ... args){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int k = scanner.nextInt(); Point[] points = new Point[n]; while (n-- > 0){ points[n] = new Point(scanner.nextInt(), scanner.nextInt()); } double distance = 0; for (int i=0; i< points.length - 1; i++){ distance += getDistance(points[i], points[i+1]); } double total = distance/50 * k; System.out.println(total); } private static double getDistance (Point p1, Point p2){ return Math.sqrt((Math.pow(p1.i- p2.i, 2) + Math.pow(p1.j - p2.j, 2))); } static class Point { int i,j; public Point(int i, int j) { this.i = i; this.j = j; } } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
1ef53b8146fb7a10b163f8351e785e46
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
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(); int k = scanner.nextInt(); double l = 0; int mas[][] = new int[n][2]; for(int i = 0; i < n; i++){ mas[i][0] = scanner.nextInt(); mas[i][1] = scanner.nextInt(); } for(int i = 0; i < (n-1); i++){ l += Math.sqrt((mas[i+1][0] - mas[i][0])*(mas[i+1][0] - mas[i][0]) + (mas[i+1][1] - mas[i][1])*(mas[i+1][1] - mas[i][1])); } System.out.print(l / 50 * k); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
6dbef935a0af8fc4a5e6da0543765886
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
/* package whatever; // 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 Main { public static void main (String[] args) throws java.lang.Exception { Scanner in=new Scanner(System.in); int n=in.nextInt(); double ans=0; int k=in.nextInt(); int xprev=in.nextInt(); int yprev=in.nextInt(); for(int i=1;i<n;i++) { int x=in.nextInt(); int y=in.nextInt(); double p=x-xprev; double q=y-yprev; ans=ans+Math.sqrt(p*p+q*q); xprev=x; yprev=y; } ans=ans*(double)k/50.0; System.out.println(ans); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
9a4fbfb2887003016225c6f3fcb705fb
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Main { static final double INF = 1e9; static final double EPS = 1e-9; // we will use constant Math.PI in Java double DEG_to_RAD(double d) { return d * Math.PI / 180.0; } double RAD_to_DEG(double r) { return r * 180.0 / Math.PI; } //struct point_i { int x, y; }; // basic raw form, minimalist mode static class point implements Comparable<point>{ double x, y; // only used if more precision is needed point() { x = y = 0.0; } // default constructor point(double _x, double _y) { x = _x; y = _y; } // user-defined // use EPS (1e-9) when testing equality of two floating points public int compareTo(point other) { // override less than operator if (Math.abs(x - other.x) > EPS) // useful for sorting return (int)Math.ceil(x - other.x); // first: by x-coordinate else if (Math.abs(y - other.y) > EPS) return (int)Math.ceil(y - other.y); // second: by y-coordinate else return 0; } }; // they are equal static double dist(point p1, point p2) { // Euclidean distance // Math.hypot(dx, dy) returns sqrt(dx * dx + dy * dy) return Math.hypot(p1.x - p2.x, p1.y - p2.y); } // return double // rotate p by theta degrees CCW w.r.t origin (0, 0) point rotate(point p, double theta) { double rad = DEG_to_RAD(theta); // multiply theta with PI / 180.0 return new point(p.x * Math.cos(rad) - p.y * Math.sin(rad), p.x * Math.sin(rad) + p.y * Math.cos(rad)); } class line { double a, b, c; }; // a way to represent a line // the answer is stored in the third parameter void pointsToLine(point p1, point p2, line l) { if (Math.abs(p1.x - p2.x) < EPS) { // vertical line is fine l.a = 1.0; l.b = 0.0; l.c = -p1.x; } else { l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x); l.b = 1.0; // IMPORTANT: we fix the value of b to 1.0 l.c = -(double)(l.a * p1.x) - p1.y; } } // not needed since we will use the more robust form: ax + by + c = 0 (see above) class line2 { double m, c; }; // another way to represent a line int pointsToLine2(point p1, point p2, line2 l) { if (Math.abs(p1.x - p2.x) < EPS) { // special case: vertical line l.m = INF; // l contains m = INF and c = x_value l.c = p1.x; // to denote vertical line x = x_value return 0; // we need this return variable to differentiate result } else { l.m = (double)(p1.y - p2.y) / (p1.x - p2.x); l.c = p1.y - l.m * p1.x; return 1; // l contains m and c of the line equation y = mx + c } } boolean areParallel(line l1, line l2) { // check coefficients a & b return (Math.abs(l1.a-l2.a) < EPS) && (Math.abs(l1.b-l2.b) < EPS); } boolean areSame(line l1, line l2) { // also check coefficient c return areParallel(l1 ,l2) && (Math.abs(l1.c - l2.c) < EPS); } // returns true (+ intersection point) if two lines are intersect boolean areIntersect(line l1, line l2, point p) { if (areParallel(l1, l2)) return false; // no intersection // solve system of 2 linear algebraic equations with 2 unknowns p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b); // special case: test for vertical line to avoid division by zero if (Math.abs(l1.b) > EPS) p.y = -(l1.a * p.x + l1.c); else p.y = -(l2.a * p.x + l2.c); return true; } class vec { double x, y; // name: `vec' is different from Java Vector vec(double _x, double _y) { x = _x; y = _y; } }; vec toVec(point a, point b) { // convert 2 points to vector return new vec(b.x - a.x, b.y - a.y); } vec scale(vec v, double s) { // nonnegative s = [<1 .. 1 .. >1] return new vec(v.x * s, v.y * s); } // shorter.same.longer point translate(point p, vec v) { // translate p according to v return new point(p.x + v.x , p.y + v.y); } // convert point and gradient/slope to line void pointSlopeToLine(point p, double m, line l) { l.a = -m; // always -m l.b = 1; // always 1 l.c = -((l.a * p.x) + (l.b * p.y)); } // compute this void closestPoint(line l, point p, point ans) { line perpendicular = new line(); // perpendicular to l and pass through p if (Math.abs(l.b) < EPS) { // special case 1: vertical line ans.x = -(l.c); ans.y = p.y; return; } if (Math.abs(l.a) < EPS) { // special case 2: horizontal line ans.x = p.x; ans.y = -(l.c); return; } pointSlopeToLine(p, 1 / l.a, perpendicular); // normal line // intersect line l with this perpendicular line // the intersection point is the closest point areIntersect(l, perpendicular, ans); } // returns the reflection of point on a line void reflectionPoint(line l, point p, point ans) { point b = new point(); closestPoint(l, p, b); // similar to distToLine vec v = toVec(p, b); // create a vector ans = translate(translate(p, v), v); } // translate p twice double dot(vec a, vec b) { return (a.x * b.x + a.y * b.y); } double norm_sq(vec v) { return v.x * v.x + v.y * v.y; } // returns the distance from p to the line defined by // two points a and b (a and b must be different) // the closest point is stored in the 4th parameter double distToLine(point p, point a, point b, point c) { // formula: c = a + u * ab vec ap = toVec(a, p), ab = toVec(a, b); double u = dot(ap, ab) / norm_sq(ab); c = translate(a, scale(ab, u)); // translate a to c return dist(p, c); } // Euclidean distance between p and c // returns the distance from p to the line segment ab defined by // two points a and b (still OK if a == b) // the closest point is stored in the 4th parameter double distToLineSegment(point p, point a, point b, point c) { vec ap = toVec(a, p), ab = toVec(a, b); double u = dot(ap, ab) / norm_sq(ab); if (u < 0.0) { c = new point(a.x, a.y); // closer to a return dist(p, a); } // Euclidean distance between p and a if (u > 1.0) { c = new point(b.x, b.y); // closer to b return dist(p, b); } // Euclidean distance between p and b return distToLine(p, a, b, c); } // run distToLine as above double angle(point a, point o, point b) { // returns angle aob in rad vec oa = toVec(o, a), ob = toVec(o, b); return Math.acos(dot(oa, ob) / Math.sqrt(norm_sq(oa) * norm_sq(ob))); } double cross(vec a, vec b) { return a.x * b.y - a.y * b.x; } //// another variant //int area2(point p, point q, point r) { // returns 'twice' the area of this triangle A-B-c // return p.x * q.y - p.y * q.x + // q.x * r.y - q.y * r.x + // r.x * p.y - r.y * p.x; //} // note: to accept collinear points, we have to change the `> 0' // returns true if point r is on the left side of line pq boolean ccw(point p, point q, point r) { return cross(toVec(p, q), toVec(p, r)) > 0; } // returns true if point r is on the same line as the line pq boolean collinear(point p, point q, point r) { return Math.abs(cross(toVec(p, q), toVec(p, r))) < EPS; } void run() { point P1 = new point(), P2 = new point(), P3 = new point(0, 1); // note that both P1 and P2 are (0.00, 0.00) System.out.println(P1.compareTo(P2) == 0); // true System.out.println(P1.compareTo(P3) == 0); // false point[] P = new point[6]; P[0] = new point(2, 2); P[1] = new point(4, 3); P[2] = new point(2, 4); P[3] = new point(6, 6); P[4] = new point(2, 6); P[5] = new point(6, 5); // sorting points demo Arrays.sort(P); for (int i = 0; i < P.length; i++) System.out.printf("(%.2f, %.2f)\n", P[i].x, P[i].y); // rearrange the points as shown in the diagram below P = new point[7]; P[0] = new point(2, 2); P[1] = new point(4, 3); P[2] = new point(2, 4); P[3] = new point(6, 6); P[4] = new point(2, 6); P[5] = new point(6, 5); P[6] = new point(8, 6); /* // the positions of these 7 points (0-based indexing) 6 P4 P3 P6 5 P5 4 P2 3 P1 2 P0 1 0 1 2 3 4 5 6 7 8 */ double d = dist(P[0], P[5]); System.out.printf("Euclidean distance between P[0] and P[5] = %.2f\n", d); // should be 5.000 // line equations line l1 = new line(), l2 = new line(), l3 = new line(), l4 = new line(); pointsToLine(P[0], P[1], l1); System.out.printf("%.2f * x + %.2f * y + %.2f = 0.00\n", l1.a, l1.b, l1.c); // should be -0.50 * x + 1.00 * y - 1.00 = 0.00 pointsToLine(P[0], P[2], l2); // a vertical line, not a problem in "ax + by + c = 0" representation System.out.printf("%.2f * x + %.2f * y + %.2f = 0.00\n", l2.a, l2.b, l2.c); // should be 1.00 * x + 0.00 * y - 2.00 = 0.00 // parallel, same, and line intersection tests pointsToLine(P[2], P[3], l3); System.out.printf("l1 & l2 are parallel? %b\n", areParallel(l1, l2)); // no System.out.printf("l1 & l3 are parallel? %b\n", areParallel(l1, l3)); // yes, l1 (P[0]-P[1]) and l3 (P[2]-P[3]) are parallel pointsToLine(P[2], P[4], l4); System.out.printf("l1 & l2 are the same? %b\n", areSame(l1, l2)); // no System.out.printf("l2 & l4 are the same? %b\n", areSame(l2, l4)); // yes, l2 (P[0]-P[2]) and l4 (P[2]-P[4]) are the same line (note, they are two different line segments, but same line) point p12 = new point(); boolean res = areIntersect(l1, l2, p12); // yes, l1 (P[0]-P[1]) and l2 (P[0]-P[2]) are intersect at (2.0, 2.0) System.out.printf("l1 & l2 are intersect? %b, at (%.2f, %.2f)\n", res, p12.x, p12.y); // other distances point ans = new point(); d = distToLine(P[0], P[2], P[3], ans); System.out.printf("Closest point from P[0] to line (P[2]-P[3]): (%.2f, %.2f), dist = %.2f\n", ans.x, ans.y, d); closestPoint(l3, P[0], ans); System.out.printf("Closest point from P[0] to line V2 (P[2]-P[3]): (%.2f, %.2f), dist = %.2f\n", ans.x, ans.y, dist(P[0], ans)); d = distToLineSegment(P[0], P[2], P[3], ans); System.out.printf("Closest point from P[0] to line SEGMENT (P[2]-P[3]): (%.2f, %.2f), dist = %.2f\n", ans.x, ans.y, d); // closer to A (or P[2]) = (2.00, 4.00) d = distToLineSegment(P[1], P[2], P[3], ans); System.out.printf("Closest point from P[1] to line SEGMENT (P[2]-P[3]): (%.2f, %.2f), dist = %.2f\n", ans.x, ans.y, d); // closer to midway between AB = (3.20, 4.60) d = distToLineSegment(P[6], P[2], P[3], ans); System.out.printf("Closest point from P[6] to line SEGMENT (P[2]-P[3]): (%.2f, %.2f), dist = %.2f\n", ans.x, ans.y, d); // closer to B (or P[3]) = (6.00, 6.00) reflectionPoint(l4, P[1], ans); System.out.printf("Reflection point from P[1] to line (P[2]-P[4]): (%.2f, %.2f)\n", ans.x, ans.y); // should be (0.00, 3.00) System.out.printf("Angle P[0]-P[4]-P[3] = %.2f\n", RAD_to_DEG(angle(P[0], P[4], P[3]))); // 90 degrees System.out.printf("Angle P[0]-P[2]-P[1] = %.2f\n", RAD_to_DEG(angle(P[0], P[2], P[1]))); // 63.43 degrees System.out.printf("Angle P[4]-P[3]-P[6] = %.2f\n", RAD_to_DEG(angle(P[4], P[3], P[6]))); // 180 degrees System.out.printf("P[0], P[2], P[3] form A left turn? %b\n", ccw(P[0], P[2], P[3])); // no System.out.printf("P[0], P[3], P[2] form A left turn? %b\n", ccw(P[0], P[3], P[2])); // yes System.out.printf("P[0], P[2], P[3] are collinear? %b\n", collinear(P[0], P[2], P[3])); // no System.out.printf("P[0], P[2], P[4] are collinear? %b\n", collinear(P[0], P[2], P[4])); // yes point p = new point(3, 7), q = new point(11, 13), r = new point(35, 30); // collinear if r(35, 31) System.out.printf("r is on the %s of line p-r\n", ccw(p, q, r) ? "left" : "right"); // right /* // the positions of these 6 points E<-- 4 3 B D<-- 2 A C 1 -4-3-2-1 0 1 2 3 4 5 6 -1 -2 F<-- -3 */ // translation point A = new point(2.0, 2.0); point B = new point(4.0, 3.0); vec v = toVec(A, B); // imagine there is an arrow from A to B (see the diagram above) point C = new point(3.0, 2.0); point D = translate(C, v); // D will be located in coordinate (3.0 + 2.0, 2.0 + 1.0) = (5.0, 3.0) System.out.printf("D = (%.2f, %.2f)\n", D.x, D.y); point E = translate(C, scale(v, 0.5)); // E will be located in coordinate (3.0 + 1/2 * 2.0, 2.0 + 1/2 * 1.0) = (4.0, 2.5) System.out.printf("E = (%.2f, %.2f)\n", E.x, E.y); // rotation System.out.printf("B = (%.2f, %.2f)\n", B.x, B.y); // B = (4.0, 3.0) point F = rotate(B, 90); // rotate B by 90 degrees COUNTER clockwise, F = (-3.0, 4.0) System.out.printf("F = (%.2f, %.2f)\n", F.x, F.y); point G = rotate(B, 180); // rotate B by 180 degrees COUNTER clockwise, G = (-4.0, -3.0) System.out.printf("G = (%.2f, %.2f)\n", G.x, G.y); } public static void main(String[] args) { Scanner reader = new Scanner(System.in); String input = reader.nextLine(); String[] nk = input.split(" "); String[] xy; int n = Integer.valueOf(nk[0]); int k = Integer.valueOf(nk[1]); int x, y; double distance = 0; point p = null; for(int i = 0; i< n; i++){ input = reader.nextLine(); xy = input.split(" "); x = Integer.valueOf(xy[0]); y = Integer.valueOf(xy[1]); if(i ==0){ p = new point(x,y); } else{ point p2 = p; p = new point(x,y); distance += dist(p2,p); } } distance = (distance/50) * k; System.out.println(distance); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
96032ad2ddff54679131502d2a790153
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; public class PA { public static void main(String[] args) { new PA().run(); } private void run() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] px = new int[n]; int[] py = new int[n]; for (int i = 0; i < n; i++) { px[i] = sc.nextInt(); py[i] = sc.nextInt(); } double d = 0; for (int i = 1; i < n; i++) { int dx = px[i] - px[i-1]; int dy = py[i] - py[i-1]; d += Math.sqrt(dx * dx + dy * dy); } double r = d * k / 50.0; System.out.println(String.format("%.9f", r)); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
ca06c957ee98e796a705b5891a37f78d
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.awt.Point; import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); double k = sc.nextDouble(); double[] points = new double[n*2]; points[0] = sc.nextDouble(); points[1] = sc.nextDouble(); double ans = 0; for(int i = 2;i<n*2;i+=2) { points[i] = sc.nextDouble(); points[i+1] = sc.nextDouble(); ans += Math.sqrt(Math.pow(points[i]-points[i-2], 2)+Math.pow(points[i+1]-points[i-1],2)); } ans = ans * (k/50); out.printf("%.9f\n", ans); out.close(); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 8
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
7688ddf3696eaba742e23f953e43ba3f
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.*; import java.util.*; public class WastedTime implements Runnable { void solve() throws IOException { int n = nextInt(); int k = nextInt(); double [][]c = new double[n][2]; for(int i=0;i<n;i++){ c[i][0] = nextDouble(); c[i][1] = nextDouble(); } double dist = 0.0; for(int i=1;i<n;i++){ dist += Math.sqrt((c[i][0]-c[i-1][0])*(c[i][0]-c[i-1][0]) + (c[i][1]-c[i-1][1])*(c[i][1]-c[i-1][1])); } double time = dist/50.0; double ret = time * k; writer.println(ret); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; public void run() { try { reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out); tokenizer = null; solve(); reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public static void main(String[] args) { new WastedTime().run(); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
7736bef7ac732944c30b4541ad3ee7b1
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.*; public class Pract1 { public static void main(String[] args) { try { InputStreamReader reader=new InputStreamReader(System.in); BufferedReader bufferdReader= new BufferedReader(reader); String str=bufferdReader.readLine(); //Char seperator=new String[] input=new String[2]; input=str.split(" "); double result=0; int n= Integer.parseInt(input[0]); int k= Integer.parseInt(input[1]); int[][] data1= new int[n][2]; for(int i=0;i<n;i++) { str=bufferdReader.readLine(); input=str.split(" "); data1[i][0]= Integer.parseInt(input[0]); data1[i][1]= Integer.parseInt(input[1]); } for(int i=0;i<n-1;i++) { result+=Math.sqrt(Math.pow((data1[i+1][0]-data1[i][0]),2)+Math.pow((data1[i+1][1]-data1[i][1]),2)); } Double finalresult=(result*k)/50; System.out.println(finalresult); } catch(IOException ex) { } } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
3cde6bc8837b8a7eba1c0fff8792526d
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; public class WastedTime { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int k = in.nextInt(); int speed = 50; double result = 0, x = in.nextDouble(), y = in.nextDouble(), x1, y1; for (int i = 1; i < n; i++) { x1 = in.nextDouble(); y1 = in.nextDouble(); result += Math.sqrt( Math.pow(x - x1, 2) + Math.pow(y - y1, 2) ); x = x1; y = y1; } result = result / speed; result *= k; out.println(String.format("%.9f", result)); out.close(); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
f5bfc4c390884902e81b324effb7f5fb
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { FastScanner in; PrintWriter out; public void run(Main oMain) { try { in = new FastScanner(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(oMain); out.close(); } catch (IOException e) { e.printStackTrace(); } } public void solve(Main oMain) throws IOException { int n = in.nextInt(); int k = in.nextInt(); double distance = 0.0; if (n < 2) { out.println("0.0"); return; } // add check for 0 distance. no moves int oldX = in.nextInt(); int oldY = in.nextInt(); int newX = 0; int newY = 0; for (int i=1; i<n; i++) { newX = in.nextInt(); newY = in.nextInt(); distance += distanceBetween(oldX, oldY, newX, newY); oldX = newX; oldY = newY; } double time = distance/50*k; /*BigDecimal bd = new BigDecimal(time); bd.setScale(6, RoundingMode.HALF_UP);*/ out.printf("%.6f", time); } private double distanceBetween(int x1, int y1, int x2, int y2) { return Math.sqrt((x2-x1)*(x2-x1)*1.0 + (y2-y1)*(y2-y1)); } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStreamReader in) { br = new BufferedReader(in); } String nextLine() { String str = null; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } public static void main(String[] arg) { Main oMain = new Main(); oMain.run(oMain); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
ed96bbdc7f7a329b8e898dfba367db3a
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; public class WastedTime { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); int n=input.nextInt(); int k=input.nextInt(); int []x=new int[n]; int []y=new int[n]; for(int i=0;i<n;i++){ x[i]=input.nextInt(); y[i]=input.nextInt(); } double d=0; for(int i=0;i<n-1;i++){ d+=Math.pow(Math.pow(x[i+1]-x[i],2)+Math.pow(y[i+1]-y[i],2),0.5); } double r=d*k; double t=r/50.0; System.out.printf("%2.9f",t); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
ae7f9b41ad0d60edc9b3b4890bea62d3
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; public class test { public static void main(String [] s){ Scanner in = new Scanner(System.in); int number,k; number = in.nextInt(); k = in.nextInt(); double [][]data = new double[number][2]; for(int q=0; q<number; q++) { data[q][0] = in.nextDouble(); data[q][1] = in.nextDouble(); } double result = 0,suma = 0; for(int i = 0; i<number-1 ;i++){ suma+=math(data[i+1][0],data[i][0],data[i+1][1],data[i][1]); } result = (suma*k)/50; System.out.println(result); } static double math(double x2,double x1 , double y2 , double y1){ return Math.sqrt(Math.pow((x2-x1),2)+Math.pow((y2-y1),2)); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
89c13aaecfa71321eb36875c2eb850dc
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class SpendingTime { public static void main(String[] args) { Scanner read = new Scanner(System.in); int n = read.nextInt(); int k = read.nextInt(); int []x = new int[n]; int []y = new int[n]; for (int i=0;i<n;i++){ x[i]=read.nextInt(); y[i]=read.nextInt(); } double len=0; for (int i=0;i<n-1;i++){ len+= Math.sqrt( (x[i]-x[i+1])*(x[i]-x[i+1]) + (y[i]-y[i+1])*(y[i]-y[i+1])); } System.out.println(k*len/50); //System.out.printf("%.32f",k*len/50); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
5efff4bf662dc362eec9594ea3c80019
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.StringTokenizer; /** * * @author zulkan */ public class signature { public static void main(String p[])throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st =new StringTokenizer(br.readLine()); int jmlInp=Integer.parseInt(st.nextToken()); double k=Float.parseFloat(st.nextToken()); Integer x1=0; Integer y1=0; double total=0.000000000; for(int a=0;a<jmlInp;a++){ st =new StringTokenizer(br.readLine()); int tempx=Integer.parseInt(st.nextToken()); int tempy=Integer.parseInt(st.nextToken()); if(a>0){ total+=Math.sqrt(((x1-tempx)*(x1-tempx))+((y1-tempy)*(y1-tempy))); } x1=tempx; y1=tempy; } //System.out.println(total); Double output=total/50.000000000*k; /* int jml=output.toString().indexOf(".")+1; System.out.println(jml); String o=""; for(int a=0;a<9+jml;a++){ if(a<output.toString().length()) o+=output.toString().substring(a,a+1); else o+="0"; } //System.out.println(o); * */ //BigDecimal v1 = new BigDecimal(output); //System.out.println(v1.divide(BigDecimal.valueOf(1),9,RoundingMode.HALF_DOWN)); DecimalFormat df=new DecimalFormat("#.######"); System.out.println(df.format(output)); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
3c269d8d19177261dfa79ec677386953
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.text.NumberFormat; import java.util.StringTokenizer; /** * * @author zulkan */ public class wastedTime { public static void main(String p[])throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st =new StringTokenizer(br.readLine()); int jmlInp=Integer.parseInt(st.nextToken()); double k=Float.parseFloat(st.nextToken()); Integer x1=0; Integer y1=0; double total=0.000000000; for(int a=0;a<jmlInp;a++){ st =new StringTokenizer(br.readLine()); int tempx=Integer.parseInt(st.nextToken()); int tempy=Integer.parseInt(st.nextToken()); if(a>0){ total+=Math.sqrt(((x1-tempx)*(x1-tempx))+((y1-tempy)*(y1-tempy))); } x1=tempx; y1=tempy; } //System.out.println(total); Double output=total/50.000000000*k; int jml=output.toString().indexOf(".")+1; //System.out.println(jml); String o=""; for(int a=0;a<9+jml;a++){ if(a<output.toString().length()) o+=output.toString().substring(a,a+1); else o+="0"; } //System.out.println(o); BigDecimal v1 = new BigDecimal(output); System.out.println(v1.divide(BigDecimal.valueOf(1),9,RoundingMode.HALF_DOWN)); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
ea971899159eaaaf5410974f9cd55847
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.text.DecimalFormat; import java.util.Scanner; public class A_Wasted_Time { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(), k=input.nextInt(); int[][] ai=new int[n][2]; int i; for(i=0;i<n;i++){ ai[i][0]=input.nextInt(); ai[i][1]=input.nextInt(); } double length=0;int x,y; for(i=0;i<n-1;i++){ x=ai[i][0]-ai[i+1][0]; y=ai[i][1]-ai[i+1][1]; length=length+java.lang.Math.sqrt(x*x+y*y); } double time=length*k/50; DecimalFormat df=new DecimalFormat("#.000000000"); System.out.println(df.format(time)); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
7ff1ffc54fa40fab8863bb336fbddc4f
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class WastedTime { private static Scanner in = new Scanner(System.in); public static void main(String[] args) { int n = in.nextInt(); int k = in.nextInt(); int [][] segments = new int [n][2]; for (int i = 0; i < segments.length; i++) { segments[i][0] = in.nextInt(); segments[i][1] = in.nextInt(); } double dPoints = 0.0; for (int i = 0; i < segments.length-1; i++) dPoints += Math.abs(distance(segments[i], segments[i+1])); double speed = 50; System.out.println(dPoints/speed*k); } public static double distance (int [] point1, int [] point2) { double dist = Math.pow(point2[0]-point1[0] ,2); dist += Math.pow(point2[1]-point1[1] ,2); dist = Math.pow(dist, 0.5); return dist; } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
04d216d1320746f642176dce2f3f85fa
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; public class WastedTime { public static void main(String[] args) throws Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int[] p=new int[n*2]; int i; for (i=0;i<p.length;i++) p[i]=sc.nextInt(); int x=p[0]; int y=p[1]; double dist; double signlen=0; for (i=2;(i+1)<p.length;i+=2) { dist=Math.sqrt(Math.pow((x-p[i]),2)+Math.pow((y-p[i+1]),2)); signlen+=dist; x=p[i]; y=p[i+1]; } double tot_sign=signlen*k; double wt=tot_sign/50; System.out.println(""+wt); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
0c83660b9f0f267381f0ee14284878ac
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import static java.lang.Math.sqrt; import java.util.Scanner; public class CodeForces127A { public static void main(final String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int x1 = sc.nextInt(); int y1 = sc.nextInt(); double sum = 0; for (int i = 1; i < n; i++) { int x2 = sc.nextInt(); int y2 = sc.nextInt(); sum += sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); x1 = x2; y1 = y2; } System.out.println(sum * k / 50); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
0794276b457267769bcfe2b2b8a493e1
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
/* ********QUESTION DESCRIPTION************* * @author (codeKNIGHT) */ import java.util.*; import java.math.*; import java.io.*; public class a93 { public static void main(String args[])throws IOException { Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); //FileReader f=new FileReader("C:\\users\\Lokesh\\Desktop\\input.txt"); //Scanner in=new Scanner(f); //int t=in.nextInt(); int i; String s; int n,k; double d=0; n=in.nextInt(); k=in.nextInt(); int x[]=new int[n]; int y[]=new int[n]; for(i=0;i<n;i++) { x[i]=in.nextInt(); y[i]=in.nextInt(); } for(i=0;i<n-1;i++) { d+=Math.sqrt(Math.pow((x[i]-x[i+1]),2)+Math.pow((y[i]-y[i+1]),2)); } out.println((d*k)/50); out.flush(); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
f0e03a234df09b80d16cf16327b51228
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author codeKNIGHT */ 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(); } } class TaskA { public void solve(int testNumber, Scanner in, PrintWriter out) { int n=in.nextInt() ; int k=in.nextInt() ; int i,x[]=new int[n],y[]=new int[n]; double d=0; for(i=0;i<n;i++) { x[i]=in.nextInt(); y[i]=in.nextInt() ; } for(i=0;i<n-1;i++) { d+=Math.sqrt(Math.pow((x[i]-x[i+1]),2)+Math.pow((y[i]-y[i+1]),2)); } out.println((d*k)/50); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
253b366bbb6762888cc75de3b49a486f
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class A_93 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt() ; int k = s.nextInt(); double ll = 0.0; int [] arrx = new int[n]; int [] arry = new int[n]; for(int i = 0 ; i < n ; i ++) { arrx[i] = s.nextInt() ; arry[i] = s.nextInt(); } for(int i = 0 ; i < arrx.length - 1 ; i++) { ll+= Math.sqrt(Math.pow(arrx[i+1] - arrx[i], 2) + Math.pow(arry[i+1] - arry[i], 2))/50; } System.out.printf("%.9f", ll*k); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
b05f149913040f437b9afe4528963421
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.*; import java.util.*; public class A { Scanner in; PrintWriter out; void run() throws Exception { in = new Scanner(System.in); out = new PrintWriter(new OutputStreamWriter(System.out)); solve(); out.flush(); } public static void main(String[] args) throws Exception { new A().run(); } void solve() throws Exception { int n = in.nextInt(); int k = in.nextInt(); Point prev = null; double dist = 0.0; while(n-->0) { int x = in.nextInt(); int y = in.nextInt(); Point p = new Point(x,y); if(prev==null) { prev = p; continue; } dist += p.distance(prev); prev = p; } double time = (dist*k)/50; out.println(time); } } class Point { int x; int y; public Point(int x2, int y2) { x=x2; y=y2; } public double distance(Point p) { int delx = p.x - x; int dely = p.y-y; double dist = delx*delx + dely*dely; return Math.sqrt(dist); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
e2a2c0450389472aac2575b099dd80da
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.File; import java.util.*; import java.io.PrintWriter; public class A { public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); double t = 0; int n = in.nextInt(); int k = in.nextInt(); int x1 = in.nextInt(); int y1 = in.nextInt(); for (int i =1;i<n;i++){ int x = in.nextInt(); int y = in.nextInt(); t += Math.sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1)); y1=y; x1=x; } System.out.printf("%f",t*k/50); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
d59e080f4badeda0c4bd70e67f9dcc0f
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; import java.util.StringTokenizer; public class Main { FastScanner in; PrintWriter out; Main () { in = new FastScanner(IO_Type.CONSOLE).getScanner(); out = new FastWriter(IO_Type.CONSOLE).getWriter(); //in = new FastScanner(IO_Type.TEST, "test.txt").getScanner(); //out = new FastWriter(IO_Type.TEST, "result.txt").getWriter(); //in = new FastScanner(IO_Type.FILE, "input.txt").getScanner(); //out = new FastWriter(IO_Type.TEST, "output.txt").getWriter(); } public static void main (String[]args) { Main task = new Main(); task.solve(); task.close(); } public void close () { in.close(); out.close(); } public void solve () { int n = in.nextInt(); int k = in.nextInt(); int[]x = new int[n]; int[]y = new int[n]; for (int i = 0; i < n; i++) { x[i] = in.nextInt(); y[i] = in.nextInt(); } double distance = 0; double time = 50; for (int i = 1; i < n; i++) { distance += (Math.sqrt(Math.pow(Math.abs(x[i] - x[i - 1]), 2) + Math.pow(Math.abs(y[i] - y[i - 1]), 2))) / 0.05; } out.println(distance * k / 1000); } } class Algebra { /**** * Number of co-prime numbers on [1, n]. * Number a is Co-prime if gcd (a, n) == 1 * O (sqrt(n)) ****/ public static int phi(int n) { int result = n; for (int i = 2; i*i <= n; ++i) { if (n % i == 0) { while (n % i == 0) { n /= i; } result -= result / i; } } if (n > 1) { result -= result / n; } return result; } /**** * Raise number a to power of n. * O (log n) ****/ public static int binpow (int a, int n) { int res = 1; while (n != 0) { if ((n & 1) == 1) res *= a; a *= a; n >>= 1; } return res; } /**** * Finding the greatest common divisor of two numbers. * O (log min(a, b)) ****/ public static int gcd (int a, int b) { return (b != 0) ? gcd (b, a % b) : a; } /**** * Finding the lowest common multiple of two numbers. * O (log min(a, b)) ****/ public static int lcm (int a, int b) { return a / gcd (a, b) * b; } /**** * Eratosthenes Sieve of numbers - [0..n]. True - simple, False - not simple. * O (n log log n) ****/ public static boolean[] sieveOfEratosthenes (int n) { boolean [] prime = new boolean[n + 1]; Arrays.fill(prime, true); prime[0] = prime[1] = false; for (int i=2; i<=n; ++i) { if (prime[i]) { if (i * 1L * i <= n) { for (int j=i*i; j<=n; j+=i) { prime[j] = false; } } } } return prime; } } class IO_Type { public static String CONSOLE = "console"; public static String FILE = "file"; public static String TEST = "test"; } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner getScanner() { return this; } FastScanner(String type) { if (type.equals("console")) { FastScanner(System.in); } } FastScanner(String type, String inFileName) { if (type.equals("file")) { File f = new File(inFileName); try { FastScanner(new FileInputStream(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } else if (type.equals("test")) { File f = new File(inFileName); try { FastScanner(new FileInputStream(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } } void FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { System.err.println(e); return ""; } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } BigInteger nextBigInt() { return new BigInteger(next()); } void close() { try { br.close(); } catch (IOException e) { } } } class FastWriter { PrintWriter pw; PrintWriter getWriter() { return pw; } FastWriter(String type) { FastWriter(type); } FastWriter (String type, String outFileName) { FastWriter(type, outFileName); } PrintWriter FastWriter(String type) { if (type.equals("console")) { pw = new PrintWriter(System.out); } return pw; } PrintWriter FastWriter(String type, String outFileName) { if (type.equals("console")) { pw = new PrintWriter(System.out); } else if (type.equals("test")) { try { pw = new PrintWriter(new File(outFileName)); } catch (FileNotFoundException e) { e.printStackTrace(); } } else if (type.equals("file")) { try { pw = new PrintWriter(new File(outFileName)); } catch (FileNotFoundException e) { e.printStackTrace(); } } return pw; } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
5381212e8687dc041ec23269e6a55d63
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int[] nk = t_int_a(br, 2); double dist = 0; int[] last_point = t_int_a(br, 2); for (int i = 0; i < nk[0] - 1; i++) { int[] point = t_int_a(br, 2); int x_diff = last_point[0] - point[0]; int y_diff = last_point[1] - point[1]; dist += Math.sqrt(x_diff * x_diff + y_diff * y_diff); last_point = point; } System.out.println(dist * nk[1] / 50.0); br.close(); } public static int t_int(BufferedReader br) throws Exception { return Integer.parseInt(br.readLine()); } public static StringTokenizer t_st(BufferedReader br) throws Exception { return new StringTokenizer(br.readLine()); } public static int[] t_int_a(BufferedReader br, int n) throws Exception { StringTokenizer st = t_st(br); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(st.nextToken()); } return a; } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
49a70442a5891d22b701f8632e4d185a
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class Solver { public static void main(String args[]) throws Exception { BufferedReader stream = new BufferedReader(new InputStreamReader(System.in)); // read data String[] input = stream.readLine().split(" "); int n = Integer.parseInt(input[0]); int k = Integer.parseInt(input[1]); double distance = 0; input = stream.readLine().split(" "); int x = Integer.parseInt(input[0]); int y = Integer.parseInt(input[1]); for (int i = 1; i < n; i++) { input = stream.readLine().split(" "); int a = Integer.parseInt(input[0]); int b = Integer.parseInt(input[1]); distance += Math.sqrt(Math.pow(x - a, 2) + Math.pow(y - b, 2)); x = a; y = b; } double result = k * distance / 50; System.out.println(result); // System.out.println( (double)Math.round(value * 1000000) / 1000000 ); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
8c5ea548fdb94516e41ecb4025df6910
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; public class Main { Scanner in; PrintWriter out; class Point { int x; int y; Point(int x, int y) { this.x = x; this.y = y; } } double distance(Point a, Point b) { return Math.sqrt(Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2)); } void solve() { int n = in.nextInt(); int k = in.nextInt(); Point a[] = new Point[n]; for (int i = 0; i < n; i++) { a[i] = new Point(in.nextInt(), in.nextInt()); } double len = 0; for (int i = 1; i < n; i++) { len += distance(a[i], a[i - 1]); } out.printf("%.8f",k * len / 50); } void run() { in = new Scanner(System.in); out = new PrintWriter(System.out); try { solve(); } finally { out.close(); } } public static void main(String[] args) { new Main().run(); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
99bfa418904472c3f8f276f1669ac15a
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.awt.Point; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n =in.nextInt(), k=in.nextInt(); Point a = new Point(in.nextInt(), in.nextInt()), b; double distance=0; for(int i=1; i<n; i++){ b = new Point(in.nextInt(), in.nextInt()); distance += a.distance(b); a=b; } double time = k*distance/50.0; System.out.println(String.format("%.9f", time)); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
91b4a2d05222add7f076029ec76c380c
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Main { static Scanner in; static PrintWriter out; public static void main(String[] args) { Main.run(); } public static void run() { //in = new Scanner(new File("input.txt")); //out = new PrintWriter(new File("output.txt")); in = new Scanner(System.in); out = new PrintWriter(System.out); double x = solve(); out.print(x); out.close(); } public static double solve() { double ans = 0.0; int n = in.nextInt(); int k = in.nextInt(); int x = in.nextInt(); int y = in.nextInt(); for (int i = 1;i<n;++i) { int px = x; int py = y; x = in.nextInt(); y = in.nextInt(); ans += Math.sqrt((x-px)*(x-px)+(y-py)*(y-py)); } ans = ans/50*k; return ans; } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
1ef02baa9362ee7e7e8cc130460a4274
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class CodeForces{ static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); //static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); static StringTokenizer token; public static void main(String args[])throws Exception{ token = new StringTokenizer(reader.readLine()); int n = Integer.parseInt(token.nextToken()); int k = Integer.parseInt(token.nextToken()); double out = 0; token = new StringTokenizer(reader.readLine()); int a = Integer.parseInt(token.nextToken()); int b = Integer.parseInt(token.nextToken()); int aa,bb; for(int i = 0; i < n - 1; i++){ token = new StringTokenizer(reader.readLine()); aa = Integer.parseInt(token.nextToken()); bb = Integer.parseInt(token.nextToken()); out += jarak(aa - a, bb - b); a = aa; b = bb; } out = out/50*k; System.out.printf("%1.9f\n", out); } static double jarak(int a, int b){ return Math.sqrt((a*a + b*b)); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
5b42cd0580732fca7744ef942a6fa085
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; public class A127 { public static void main(String[] args){ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int scale = scan.nextInt(); int[] x = new int[n]; int[] y = new int[n]; for(int i = 0; i < n; i++) { x[i] = scan.nextInt(); y[i] = scan.nextInt(); } double ret = 0; for(int i = 0; i < n-1; i++) { int j = i+1; j %= n; ret += Math.hypot(x[i]-x[j], y[i]-y[j]); } ret *= scale; ret /= 50; System.out.println(ret); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
979c7769a3cd9de00830b7a85e764160
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class A_DoubleCola { public static void main(String[] args) { A_DoubleCola problem = new A_DoubleCola(); problem.solve(); } private void solve() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int a1 = sc.nextInt(); int a2 = sc.nextInt(); double time = 0; for(int i = 1; i < n; i++){ int a3 = sc.nextInt(); int a4 = sc.nextInt(); time += Math.sqrt(Math.pow(a3 - a1, 2) + Math.pow(a4 - a2, 2)); a1 = a3; a2 = a4; } System.out.printf("%.9f", time*k/50); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
35a23e39ccb5588e46110f3d8360048c
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { // long start = System.currentTimeMillis(); // long end = System.currentTimeMillis(); // System.out.println(" Execution time was "+(end-start)+" ms."); Scanner kb = new Scanner(System.in); int n = kb.nextInt(); int k = kb.nextInt(); int x[] = new int[n]; int y[] = new int[n]; for(int i=0;i<n;i++){ x[i] = kb.nextInt(); y[i] = kb.nextInt(); } int px = x[0]; int py = y[0]; double time = 0; for(int i =1;i<n;i++){ time += (Math.sqrt(Math.pow((x[i]-px),2)+Math.pow((y[i]-py),2)))/(50.0); px = x[i]; py = y[i]; } System.out.println(time*(double)k); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
8ee61f1e987d4aa90e5ad9a719e5538c
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[]x = new int[n+1], y = new int[n+1]; for (int i = 1; i <= n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); } double ans = 0; for (int i = 2; i <= n; i++) { ans += Math.sqrt((x[i]-x[i-1])*(x[i]-x[i-1])+(y[i]-y[i-1])*(y[i]-y[i-1])); } ans *= k/50.0; System.out.println(ans); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
f61e7a13ca3257e0667c279a3cd13c1e
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class WastedTime { public static void main(String[] args) { Scanner br=new Scanner(System.in); int n=br.nextInt(),k=br.nextInt(); int x=br.nextInt(),y=br.nextInt(); double dist=0; for(int i=1;i<n;i++) { int a=br.nextInt(),b=br.nextInt(); dist+=Math.hypot(a-x,b-y); x=a; y=b; } dist/=50; dist*=k; System.out.println(dist); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
fd9d9bb9f1b8983e6b941586d15df655
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.Scanner; public class a127 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int []x = new int [n+1]; int []y = new int [n+1]; double s = 0; for (int i = 1; i <=n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); } for (int i = 1; i < n; i++) { s+=(double) Math.sqrt(((x[i]-x[i+1]))*(x[i]-x[i+1])+(y[i]-y[i+1])*(y[i]-y[i+1])); } s=k*s/50; System.out.printf("%.9f",s); /*Input 5 10 3 1 -5 6 -2 -1 3 2 10 0 Output 6.032163204 */ } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
cb7756ee8b6f09bd7d0b2ab8d0b8017a
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.io.BufferedInputStream; import java.util.*; import static java.lang.Math.*; public class C127A { public void solve() throws Exception { int n = nextInt(); int k = nextInt(); int[][] a = new int[n][2]; for (int i = 0; i < n; i++) { a[i][0] = nextInt(); a[i][1] = nextInt(); } double res = 0; for (int i = 0; i < a.length - 1; i++) { int x = a[i][0] - a[i + 1][0]; int y = a[i][1] - a[i + 1][1]; res += sqrt(x * x + y * y); } res *= k; res /= 50; println(res); } // ------------------------------------------------------ void debug(Object... os) { System.err.println(Arrays.deepToString(os)); } void print(Object... os) { if (os != null && os.length > 0) System.out.print(os[0].toString()); for (int i = 1; i < os.length; ++i) System.out.print(" " + os[i].toString()); } void println(Object... os) { print(os); System.out.println(); } BufferedInputStream bis = new BufferedInputStream(System.in); String nextWord() throws Exception { char c = (char) bis.read(); while (c <= ' ') c = (char) bis.read(); StringBuilder sb = new StringBuilder(); while (c > ' ') { sb.append(c); c = (char) bis.read(); } return new String(sb); } String nextLine() throws Exception { char c = (char) bis.read(); while (c <= ' ') c = (char) bis.read(); StringBuilder sb = new StringBuilder(); while (c != '\n' && c != '\r') { sb.append(c); c = (char) bis.read(); } return new String(sb); } int nextInt() throws Exception { return Integer.parseInt(nextWord()); } long nextLong() throws Exception { return Long.parseLong(nextWord()); } public static void main(String[] args) throws Exception { new C127A().solve(); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
ad345023dc72c1a95bf6b9b4a8f3ab7b
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static Scanner scan = new Scanner(System.in); public static boolean bg = true; public static void main(String[] args) throws Exception { int n1 = Integer.parseInt(scan.next()); int k1 = Integer.parseInt(scan.next()); double total = 0.0; int[] xl = new int[n1]; int[] yl = new int[n1]; for (int i = 0; i < n1; i++) { xl[i] = Integer.parseInt(scan.next()); yl[i] = Integer.parseInt(scan.next()); } for (int i=0;i<n1-1;i++){ total+=Math.sqrt((xl[i+1]-xl[i])*(xl[i+1]-xl[i])+(yl[i+1]-yl[i])*(yl[i+1]-yl[i] ) ); } System.out.println(total*k1/50.0); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
db3c5620e94f7ff1aad0ec5112ce7990
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; public class WastedTime { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); double n=input.nextDouble(); double k=input.nextDouble(); if(n>=2&&n<=100&&k>=1&&k<=1000){ double [][]a=new double [(int)n][2]; for(int i=0;i<a.length;i++){ for(int j=0;j<a[0].length;j++){ a[i][j]=input.nextDouble(); } } double s=0; for(int i=0;i<a.length-1;i++){ s+=Math.pow(Math.pow(a[i+1][0]-a[i][0], 2)+Math.pow(a[i+1][1]-a[i][1],2),0.5); } double r=s*k/50.0; System.out.printf("%2.9f",r); } } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
b7afd9d834cd35a5b4579ab0f4fb0d75
train_003.jsonl
1320858000
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant β€” 50 millimeters per second.Scrooge signed exactly k papers throughout his life and all those signatures look the same.Find the total time Scrooge wasted signing the papers.
256 megabytes
import java.util.*; public class WastedTime { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); int n=input.nextInt(); int k=input.nextInt(); int []x=new int[n]; int []y=new int[n]; for(int i=0;i<n;i++){ x[i]=input.nextInt(); y[i]=input.nextInt(); } double d=0; for(int i=0;i<n-1;i++){ d+=Math.pow(Math.pow(x[i+1]-x[i],2)+Math.pow(y[i+1]-y[i],2),0.5); } double r=d*k; double t=r/50.0; System.out.printf("%2.9f",t); } }
Java
["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0"]
2 seconds
["0.200000000", "6.032163204", "3.000000000"]
null
Java 6
standard input
[ "geometry" ]
db4a25159067abd9e3dd22bc4b773385
The first line contains two integers n and k (2 ≀ n ≀ 100, 1 ≀ k ≀ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai β€” integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
900
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
standard output
PASSED
fed7459c42d71abb664d3db86d2ae69b
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.io.*; import java.util.*; /** * Created by noureldin on 2/20/17. */ public class main { private static boolean isSorted(int [] A){ for (int i = 1;i < A.length;i++) if(A[i - 1] > A[i]) return false; return true; } private static boolean isSorted2(int [] A){ if (isSorted(A)) return true; int [] B = new int[A.length]; int j = A.length - 1; for (int i = 0;i < A.length;i++) B[j--] = A[i]; return isSorted(B); } public static void main(String[] args) throws Exception{ IO io = new IO(null,null); int n = io.getNextInt(); int [] A = new int[n]; for (int i = 0;i < n;i++) A[i] = io.getNextInt(); boolean same = true; for (int i = 1;i < n && same;i++) same = A[i] == A[0]; if (same || n == 2) io.println(-1); else { boolean done = false; int j = 0; for (int i = 0;i < n && !done;i++){ if(i == j) continue; if(A[i] != A[j]){ int x,y; x = A[i]; y = A[j]; A[i] = y; A[j] = x; if(!isSorted2(A)){ io.println((j + 1) + " " + (i + 1)); done = true; } x = A[i]; y = A[j]; A[i] = y; A[j] = x; } } j = 1; for (int i = 0;i < n && !done;i++){ if(i == j) continue; if(A[i] != A[j]){ int x,y; x = A[i]; y = A[j]; A[i] = y; A[j] = x; if(!isSorted2(A)){ io.println((j + 1) + " " + (i + 1)); done = true; } x = A[i]; y = A[j]; A[i] = y; A[j] = x; } } if(!done) io.println(-1); } io.close(); } } class item implements Comparable<item>{ int price,time; public item(int time,int price){ this.price = price; this.time = time; } @Override public int compareTo(item o){ return this.price - o.price; } } class IO{ private BufferedReader br; private StringTokenizer st; private PrintWriter writer; private String inputFile,outputFile; public String getNext() throws FileNotFoundException, IOException{ while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String getNextLine() throws FileNotFoundException, IOException{ return br.readLine(); } public int getNextInt() throws FileNotFoundException, IOException{ return Integer.parseInt(getNext()); } public long getNextLong() throws FileNotFoundException, IOException{ return Long.parseLong(getNext()); } public void print(double x,int num_digits) throws IOException{ writer.printf("%." + num_digits + "f" ,x); } public void println(double x,int num_digits) throws IOException{ writer.printf("%." + num_digits + "f\n" ,x); } public void print(Object o) throws IOException{ writer.print(o.toString()); } public void println(Object o) throws IOException{ writer.println(o.toString()); } public IO(String x,String y) throws FileNotFoundException, IOException{ inputFile = x; outputFile = y; if(x != null) br = new BufferedReader(new FileReader(inputFile)); else br = new BufferedReader(new InputStreamReader(System.in)); if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile))); else writer = new PrintWriter(new OutputStreamWriter(System.out)); } protected void close() throws IOException{ br.close(); writer.close(); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 8
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
545a3a2ab88df8dbe2b7c00390fecae8
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { static class Reader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,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 s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} public long l(){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 i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} public double d() throws IOException {return Double.parseDouble(s()) ;} public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = i();}return ret;} } /////////////////////////////////////////////////////////////////////////////////////////// // RRRRRRRRR AAA HHH HHH IIIIIIIIIIIII LLL // // RR RRR AAAAA HHH HHH IIIIIIIIIII LLL // // RR RRR AAAAAAA HHH HHH III LLL // // RR RRR AAA AAA HHHHHHHHHHH III LLL // // RRRRRR AAA AAA HHHHHHHHHHH III LLL // // RR RRR AAAAAAAAAAAAA HHH HHH III LLL // // RR RRR AAA AAA HHH HHH IIIIIIIIIII LLLLLLLLLLLL // // RR RRR AAA AAA HHH HHH IIIIIIIIIIIII LLLLLLLLLLLL // /////////////////////////////////////////////////////////////////////////////////////////// public static void main(String[] args)throws IOException { PrintWriter out= new PrintWriter(System.out); Reader sc=new Reader(); int n=sc.i(); int arr[]=sc.arr(n); if(n<=2) out.println("-1"); else { long time=System.currentTimeMillis(); while(System.currentTimeMillis()-time<=800) { int pos1=(int)(Math.random()*n); int pos2=(int)(Math.random()*n); if(pos1==pos2||arr[pos1]==arr[pos2])continue; int brr[]=Arrays.copyOf(arr,n); int temp=brr[pos1]; brr[pos1]=brr[pos2]; brr[pos2]=temp; int flag1=0; int flag2=0; for(int i=1;i<n;i++) { if(brr[i]<=brr[i-1]) flag1=1; if(brr[i]>brr[i-1]) flag2=1; } if(!(flag1==1&&flag2==1)) continue; flag1=0; flag2=0; for(int i=1;i<n;i++) { if(brr[i]>=brr[i-1]) flag1=1; if(brr[i]<brr[i-1]) flag2=1; } if(!(flag1==1&&flag2==1)) continue; System.out.println(pos1+1+" "+(pos2+1)); System.exit(0); } out.println("-1"); } out.flush(); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 8
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
79ca2c060231f35dbcd6b2c5a7f3a708
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int n = in.nextInt(); int[]a = new int[n]; int[]b = new int[n]; int[]c = new int[n]; for(int i =0;i<n;i++) { a[i] = in.nextInt(); b[i]=a[i]; c[i]= a[i]; } Arrays.sort(b); Arrays.sort(c); c = reverse(c); boolean check = false; for (int i =0;i<n-1;i++) { if (a[i]!=a[i+1]&&(a[i]!=b[i+1]||a[i+1]!=b[i])&&(a[i]!=c[i+1]||a[i+1]!=c[i])) { out.printLine((i+1)+" "+(i+2)); check=true; break; } } if (!check) out.printLine(-1); out.flush(); } static int[] reverse(int[]validData) { for(int i = 0; i < validData.length / 2; i++) { int temp = validData[i]; validData[i] = validData[validData.length - i - 1]; validData[validData.length - i - 1] = temp; } return validData; } } class pair implements Comparable { int key; int value; public pair(Object key, Object value) { this.key = (int)key; this.value=(int)value; } @Override public int compareTo(Object o) { pair temp =(pair)o; return key-temp.key; } } class Graph { int n; ArrayList<Integer>[] adjList; public Graph(int n) { this.n = n; adjList = new ArrayList[n]; for (int i = 0; i < n; i++) adjList[i] = new ArrayList<>(); } } class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream stream) { this.stream = stream; } 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; } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 8
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
8c8e1b0e2e4df41bb0bea406073b0140
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.util.Scanner; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author flk */ 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, Scanner in, PrintWriter out) { int n = in.nextInt(); in.nextLine(); int [] a = new int[n]; int [] distinct = new int[3]; int [] d_pos = new int[3]; int num_distinct = 0; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); if (num_distinct < 3) { boolean newNum = true; for (int j = 0; j <num_distinct; j++) { if (a[d_pos[j]] == a[i]) { newNum = false; break; } } if (newNum) { distinct[num_distinct] = a[i]; d_pos[num_distinct] = i; num_distinct++; } } } if (num_distinct == 1 || (num_distinct == 2 && n == 2)) { out.print("-1"); } else if (num_distinct == 2) { if (n == 3) { if (a[0] == a[2]) { out.print("-1"); } else { out.print((d_pos[0]+1) + " " + (d_pos[1]+1)); } } else { int [] l_pos = new int[3]; int [] g_pos = new int[3]; int [] e_pos = new int[3]; int num_0 = 0; int num_1 = 0; for (int i = 0; i < n; i++) { if (a[i] == distinct[0]) num_0++; else num_1++; } if (num_0 != 1 && num_1 != 1) { out.print((d_pos[0]+1) + " " + (d_pos[1]+1)); } else { if (num_0 == 1) { out.print((d_pos[0]+1) + " " + (n/2 == d_pos[0]+1 ? n/2 + 1 :n/2)); } else { out.print((d_pos[1]+1) + " " + (n/2 == d_pos[1]+1 ? n/2 + 1 :n/2)); } } } } else { if (distinct[0] < distinct[1] && distinct[1] < distinct[2]) { out.print((d_pos[2]+1) + " " + (d_pos[1]+1)); } else if (distinct[0] > distinct[1] && distinct[1] > distinct[2]) { out.print((d_pos[1]+1) + " " + (d_pos[0]+1)); } else { out.print((d_pos[2]+1) + " " + (d_pos[0]+1)); } } } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 8
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
e2dfbc82ad7c685e91a926ecc6f27c39
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author cf252b_unsAr */ import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStreamReader; import static java.lang.System.*; import java.math.BigInteger; import java.util.List; import java.util.ArrayList; import java.util.Scanner; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; import java.util.TreeSet; public class cf252b_unsAr { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static Scanner sc = new Scanner(System.in); public static String getString() { try { return br.readLine(); } catch (Exception e) { } return ""; } public static Integer getInt() { try { return Integer.parseInt(br.readLine()); } catch (Exception e) { } return 0; } public static Integer[] getIntArr() { try { StringTokenizer temp = new StringTokenizer(br.readLine()); int n = temp.countTokens(); Integer temp2[] = new Integer[n]; for (int i = 0; i < n; i++) { temp2[i] = Integer.parseInt(temp.nextToken()); } return temp2; } catch (Exception e) { } return null; } public static int getMax(Integer[] ar) { int t = ar[0]; for (int i = 0; i < ar.length; i++) { if (ar[i] > t) { t = ar[i]; } } return t; } public static void print(Object a) { out.println(a); } public static int nextInt() { return sc.nextInt(); } public static double nextDouble() { return sc.nextDouble(); } public static BigInteger getFact(long in) { BigInteger ot = new BigInteger("1"); for (Integer i = 1; i <= in; i++) { ot = ot.multiply(new BigInteger(i.toString())); } return ot; } public static String gbase(int a, int base) { StringBuilder out = new StringBuilder(); int temp = a; while (temp > 0) { //out = temp % base + out; out.insert(0, temp % base); temp /= base; } return out.toString(); } public static void main(String[] ar) { int n = getInt(); if (n < 3) { print(-1); return; } Integer[] input = getIntArr(); if (cek(input)) { for (int i = 0; i < n-1; i++) { if (input[i] - input[i+1] != 0) { //print(input[i] - input[j]); print((i + 1) + " " + (i + 2)); return; } } } else { for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (input[i] - input[j] !=0) { int temp = input[i]; input[i] = input[j]; input[j] = temp; if (cek(input)) { temp = input[i]; input[i] = input[j]; input[j] = temp; } else { //print(Arrays.asList(input)); print((i + 1) + " " + (j + 1)); return; } } } } } print(-1); } /* static boolean cek(Integer[] input) { TreeSet<Integer> asal = new TreeSet<Integer>(Arrays.asList(input)); boolean membesar = false; boolean mengecil = false; LinkedHashSet<Integer> temp = new LinkedHashSet<Integer>(Arrays.asList(input)); if(temp.toString().equals(asal.toString())){ membesar = true; } //print(temp); temp.clear(); for(int i=input.length-1;i>=0;i--){ // print(temp); temp.add(input[i]); } //print(temp); if(temp.toString().equals(asal.descendingSet().toString())){ mengecil = true; } return membesar || mengecil; } * */ static boolean cek(Integer[] input) { boolean membesar = true; boolean mengecil = true; int last = input[0]; for (int i = 1; i < input.length; i++) { if (last < input[i]) { mengecil = false; } if (last > input[i]) { membesar = false; } last = input[i]; } return membesar || mengecil; } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
d477ae04f37ee9aaea0c725990c6c60a
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class program { public static Scanner in = new Scanner(System.in); public static void main(String[] args) { int n = in.nextInt(); int[] mass = new int[n]; int[] sortedMassAsc = new int[n]; int[] sortedMassDesc = new int[n]; int[] tmpMass = new int[n]; int a; for (int i = 0; i < n; ++i) { a = in.nextInt(); mass[i] = sortedMassAsc[i] = a; } if (n < 3) { System.out.println("-1"); return; } if (n == 3 && mass[0] == mass[2]) { System.out.println("-1"); return; } int tmp = mass[0]; boolean areSame = true; for (int i = 1; i < n; ++i) { if (tmp != mass[i]) { areSame = false; break; } } if (areSame) { System.out.println("-1"); return; } Arrays.sort(sortedMassAsc); for (int i = 0; i < n; ++i) { sortedMassDesc[i] = sortedMassAsc[n - i - 1]; } for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (mass[i] == mass[j]) { continue; } tmp = mass[i]; mass[i] = mass[j]; mass[j] = tmp; if (!Arrays.equals(mass, sortedMassAsc) && !Arrays.equals(mass, sortedMassDesc)) { System.out.println((i + 1) + " " + (j + 1)); return; } else { tmp = mass[i]; mass[i] = mass[j]; mass[j] = tmp; } } } System.out.println("-1"); } public static int gcd(int a, int b) { while (b != 0) { int tmp = a % b; a = b; b = tmp; } return a; } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
4463947a9a64233c37faaac786d19d93
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
//package example; import java.io.*; import java.util.*; public class Example { BufferedReader in; PrintWriter out; StringTokenizer st; String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch (Exception e) { } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } public void run() throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.flush(); out.close(); in.close(); } public void solve() throws Exception { int n = nextInt(); int[] a = new int[n]; int[] x = {-1, -1, -1}; int[] ind = {0, 0, 0}; for (int i = 0; i < n; i++) { a[i] = nextInt(); if (i == 0) { x[0] = a[i]; ind[0] = i + 1; } else { if (ind[1] == 0) { if (a[i] != x[0]) { x[1] = a[i]; ind[1] = i + 1; } else { ind[0] = i + 1; } } else if (ind[2] == 0) { if (a[i] != x[1]) { x[2] = a[i]; ind[2] = i + 1; } } } } String ans = "-1"; if (ind[2] != 0) { if (ind[0] > 1) { ans = ind[0] + " " + ind[1]; } else if (ind[2] < n) { ans = ind[1] + " " + ind[2]; } else if (n > 3) { ans = ind[0] + " " + ind[1]; } else if (n == 3 && x[0] != x[2]) { if ((x[0] > x[1] && x[1] > x[2]) || (x[0] < x[1] && x[1] < x[2])) { ans = ind[0] + " " + ind[1]; } else { ans = ind[0] + " " + ind[2]; } } } else if (ind[1] != 0) { if (ind[0] > 1 || ind[1] < n) { ans = ind[0] + " " + ind[1]; } } out.println(ans); } public static void main(String[] args) throws Exception { new Example().run(); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
12d109a07c9a9d10da98bf46747d90e5
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
//package example; import java.io.*; import java.util.*; public class Example { BufferedReader in; PrintWriter out; StringTokenizer st; String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch (Exception e) { } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } public void run() throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.flush(); out.close(); in.close(); } public void solve() throws Exception { int n = nextInt(); int[] a = new int[n]; int[] x = {-1, -1, -1}; int[] ind = {0, 0, 0}; for (int i = 0; i < n; i++) { a[i] = nextInt(); if (i == 0) { x[0] = a[i]; ind[0] = i + 1; } else { if (ind[1] == 0) { if (a[i] != x[0]) { x[1] = a[i]; ind[1] = i + 1; } else { ind[0] = i + 1; } } else if (ind[2] == 0) { if (a[i] != x[1]) { x[2] = a[i]; ind[2] = i + 1; } } } } String ans = "-1"; if (ind[2] != 0) { if (ind[0] > 1) { ans = ind[0] + " " + ind[1]; } else if (ind[2] < n) { ans = ind[1] + " " + ind[2]; } else if (n > 3) { ans = ind[0] + " " + ind[1]; } else if (n == 3 && x[0] != x[2]) { if ((x[0] > x[1] && x[1] > x[2]) || (x[0] < x[1] && x[1] < x[2])) { ans = ind[0] + " " + ind[1]; } else { ans = ind[0] + " " + ind[2]; } } } else if (ind[1] != 0) { if (ind[0] > 1 || ind[1] < n) { ans = ind[0] + " " + ind[1]; } } out.println(ans); } public static void main(String[] args) throws Exception { new Example().run(); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
1b59091a86a9f44aba6bc4d527a0eee5
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.util.*; public class cf252b { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] v = new int[n]; for(int i=0; i<n; i++) v[i] = in.nextInt(); int a = 0; int b = a; while(b < n-1 && v[a] == v[b]) b++; int c = b; while(c < n && (v[a]==v[c] || v[b]==v[c])) c++; if(c == n) c=a+1; if(c == b) c++; if(c == n) c--; if(ok(v,a,b)) { System.out.println((a+1) + " " + (b+1)); return; } if(ok(v,b,c)) { System.out.println((b+1) + " " + (c+1)); return; } if(ok(v,a,c)) { System.out.println((a+1) + " " + (c+1)); return; } System.out.println(-1); } static boolean ok(int[] v, int a, int b) { if(v[a] == v[b]) return false; int tmp = v[a]; v[a] = v[b]; v[b] = tmp; boolean ret = isSorted(v); tmp = v[a]; v[a] = v[b]; v[b] = tmp; return !ret; } static boolean isSorted(int[] v) { return isInc(v) || isDec(v); } static boolean isInc(int[] v) { for(int i=1; i<v.length; i++) if(v[i] < v[i-1]) return false; return true; } static boolean isDec(int[] v) { for(int i=1; i<v.length; i++) if(v[i] > v[i-1]) return false; return true; } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
e538b1b210fb1a45f7d38c74220a4e30
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; import java.util.StringTokenizer; public class Solver { StringTokenizer st; BufferedReader in; PrintWriter out; public static void main(String[] args) throws NumberFormatException, IOException { Solver solver = new Solver(); solver.open(); long time = System.currentTimeMillis(); solver.solve(); if (!"true".equals(System.getProperty("ONLINE_JUDGE"))) { System.out.println("Spent time: " + (System.currentTimeMillis() - time)); System.out.println("Memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); } solver.close(); } public void open() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } public String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { String line = in.readLine(); if (line == null) return null; st = new StringTokenizer(line); } return st.nextToken(); } public int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(nextToken()); } public long nextLong() throws NumberFormatException, IOException { return Long.parseLong(nextToken()); } public double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(nextToken()); } final int OFFSET = 150; boolean isSame(int[] a, int[] b) { if (a.length != b.length) return false; int n = a.length; for (int i = 0; i < n; i++) if (a[i] != b[i]) return false; return true; } Map<Integer, Integer> getDiff(int[] a, int without1, int without2) { HashMap<Integer, Integer> result = new HashMap<Integer, Integer>(); int n = a.length; for (int i = 0; i < n; i++) { if (i != without1 && i != without2) { result.put(a[i], i); } } return result; } public void solve() throws NumberFormatException, IOException { int n = nextInt(); if (n == 1 || n == 2) { out.println(-1); return; } boolean same = true; int[] a = new int[n], inc = new int[n], dec = new int[n]; for (int i = 0; i < n; i++) { a[i] = inc[i] = nextInt(); same &= a[i] == a[0]; } if (same) { out.println(-1); return; } Random rnd = new Random(System.currentTimeMillis()); for (int i = 0; i < n; i++) { int index = rnd.nextInt(n); int tmp = inc[index]; inc[index] = inc[i]; inc[i] = tmp; } Arrays.sort(inc); for (int i = 0; i < n; i++) { dec[i] = inc[n - 1 - i]; } List<Integer> list1 = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { if (a[i] != inc[i]) list1.add(i); } List<Integer> list2 = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { if (a[i] != dec[i]) list2.add(i); } if (list1.size() != 2 && list2.size() != 2) { int j = 0; while (a[j] == a[0]) j++; out.println("1 " + (j + 1)); } else { list1.add(-1); list1.add(-1); list2.add(-1); list2.add(-1); Map<Integer, Integer> diff = getDiff(a, list1.get(0), list2.get(0)); if (diff.size() >= 2) { Iterator<Integer> it = diff.values().iterator(); out.println((it.next() + 1) + " " + (it.next() + 1)); return; } diff = getDiff(a, list1.get(0), list2.get(1)); if (diff.size() >= 2) { Iterator<Integer> it = diff.values().iterator(); out.println((it.next() + 1) + " " + (it.next() + 1)); return; } diff = getDiff(a, list1.get(1), list2.get(0)); if (diff.size() >= 2) { Iterator<Integer> it = diff.values().iterator(); out.println((it.next() + 1) + " " + (it.next() + 1)); return; } diff = getDiff(a, list1.get(1), list2.get(1)); if (diff.size() >= 2) { Iterator<Integer> it = diff.values().iterator(); out.println((it.next() + 1) + " " + (it.next() + 1)); return; } out.println(-1); } } public void close() { out.flush(); out.close(); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
2e404f56cc000dc10adf752d671bbdbe
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.io.*; import java.util.*; public class nB { class Scanner { InputStream in; byte buffer[] = new byte[65536]; int pos = 0; int len = 0; Scanner(InputStream in) { this.in = in; } int nextChar() { try { if (pos == len) { len = in.read(buffer); if (len == -1) { len = 0; } pos = 0; } if (pos == len) { return -1; } int ans = buffer[pos] & 0xFF; pos++; return ans; } catch (IOException e) { throw new Error(e); } } int nextInt() { int ch = nextChar(); while (ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t') { ch = nextChar(); } int sign = 1; if (ch == '-') { ch = nextChar(); sign = -1; } int value = ch - '0'; ch = nextChar(); while ('0' <= ch && ch <= '9') { int d = ch - '0'; ch = nextChar(); value = value * 10 + d; } return value * sign; } } Scanner in; PrintWriter out; void solve() { int n = in.nextInt(); int a[] = new int[n]; int max = Integer.MIN_VALUE; int maxPos = -1; int another = Integer.MAX_VALUE; int anotherPos = -1; TreeSet<Integer> set = new TreeSet<Integer>(); for (int i = 0; i < n; i++) { a[i] = in.nextInt(); set.add(a[i]); if (a[i] > max || ((a[i] == max) && i > 0 && i < n - 1)) { max = a[i]; maxPos = i; } } for (int i = 1; i < n - 1; i++) { if (a[i] != max) { another = a[i]; anotherPos = i; } } if (n == 1 || n == 2) { out.println("-1"); return; } if (set.size() == 1) { out.println("-1"); return; } if (n == 3) { if (maxPos == 1) { if (a[0] == a[2]) { out.println("-1"); return; } if (a[0] < a[2]) { out.println(1 + " " + 2); return; } if (a[0] > a[2]) { out.println(2 + " " + 3); return; } } else if (maxPos == 0) { if(a[0] == a[2]){ out.println("-1"); return; } } } if (anotherPos == -1) { if (a[0] != max) { out.println(1 + " " + (maxPos + 1)); return; } else if (a[n - 1] != max) { out.println(n + " " + 2); return; } else { out.println("-1"); return; } } out.println((maxPos + 1) + " " + (anotherPos + 1)); } void run() { in = new Scanner(System.in); out = new PrintWriter(System.out); try { solve(); } finally { out.close(); } } public static void main(String[] args) { new nB().run(); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
15095091306a6db2af9adc23642b3498
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; public class B { /** * @param args * @throws IOException * @throws NumberFormatException */ public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int n=Integer.parseInt(in.readLine()); if(n<3){ out.println(-1); } else{ String[] inp=in.readLine().split(" "); int prev=-1,cur=Integer.parseInt(inp[0]),next=Integer.parseInt(inp[1]); int a1=-1; int a2=-1; for(int i=2; i<n; i++){ prev=cur; cur=next; next=Integer.parseInt(inp[i]); if(prev<cur && cur<=next || prev>cur && cur>=next ){ a1=i-2; a2=i-1; break; } else if(prev<=cur && cur<next || prev>=cur && cur>next){ a1=i-1; a2=i; break; } else if(next!=prev && (prev>cur && next>cur || prev<cur && next<cur)){ a1=i-2; a2=i; break; } else if(n>3 && i+1<n && (prev>cur && next>cur || prev<cur && next<cur)){ int nnext=Integer.parseInt(inp[i+1]); if(nnext==cur){ a1=i; a2=i+1; break; } } } if(a1==-1 || a2==-1){ out.println(-1); } else{ out.println((a1+1)+" "+(a2+1)); } } out.close(); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
b6fcb81d74db01ec6502c57abbc36652
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.awt.Point; import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class Start { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException { if (ONLINE_JUDGE) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } } String readString() throws IOException { while (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } int readInt() throws IOException { return Integer.parseInt(readString()); } long readLong() throws IOException { return Long.parseLong(readString()); } double readDouble() throws IOException { return Double.parseDouble(readString()); } public static void main(String[] args) { new Start().run(); } public static void mergeSort(int[] a) { mergeSort(a, 0, a.length - 1); } private static void mergeSort(int[] a, int levtIndex, int rightIndex) { final int MAGIC_VALUE = 50; if (levtIndex < rightIndex) { if (rightIndex - levtIndex <= MAGIC_VALUE) { insertionSort(a, levtIndex, rightIndex); } else { int middleIndex = (levtIndex + rightIndex) / 2; mergeSort(a, levtIndex, middleIndex); mergeSort(a, middleIndex + 1, rightIndex); merge(a, levtIndex, middleIndex, rightIndex); } } } private static void merge(int[] a, int levtIndex, int middleIndex, int rightIndex) { int length1 = middleIndex - levtIndex + 1; int length2 = rightIndex - middleIndex; int[] levtArray = new int[length1]; int[] rightArray = new int[length2]; System.arraycopy(a, levtIndex, levtArray, 0, length1); System.arraycopy(a, middleIndex + 1, rightArray, 0, length2); for (int k = levtIndex, i = 0, j = 0; k <= rightIndex; k++) { if (i == length1) { a[k] = rightArray[j++]; } else if (j == length2) { a[k] = levtArray[i++]; } else { a[k] = levtArray[i] <= rightArray[j] ? levtArray[i++] : rightArray[j++]; } } } private static void insertionSort(int[] a, int levtIndex, int rightIndex) { for (int i = levtIndex + 1; i <= rightIndex; i++) { int current = a[i]; int j = i - 1; while (j >= levtIndex && a[j] > current) { a[j + 1] = a[j]; j--; } a[j + 1] = current; } } public void run() { try { long t1 = System.currentTimeMillis(); init(); solve(); out.close(); long t2 = System.currentTimeMillis(); System.err.println("Time = " + (t2 - t1)); } catch (Exception e) { e.printStackTrace(System.err); System.exit(-1); } } class LOL implements Comparable<LOL> { int x; int y; public LOL(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(LOL o) { return x - o.x; // ----> // return o.x - x; // <---- // return o.y-y; } } public void solve() throws IOException { int n = readInt(); int [] a = new int [n]; TreeSet<Integer> set = new TreeSet<Integer>(); for (int i = 0; i < n; i++){ int k = readInt(); a[i] = k; set.add(k); } if (n==1 || n==2 || set.size()==1){ out.print(-1); return; } //mergeSort(b); if (n==3 && set.size()==2){ if (a[0]==a[2]){ out.print(-1); } else { if (a[0]==a[1]){ out.print(2 + " " + 3); } else { out.print(1 + " " + 2); } } return; } int t = 2; for (int i = 2 ; i < n; i++){ if (a[i] != a[0] && a[i]!=a[1]){ t = i; break; } } LOL [] b = new LOL[3];//{a[0],a[1],a[t]}; b[0] = new LOL(a[0],0); b[1] = new LOL(a[1],1); b[2] = new LOL(a[t],t); Arrays.sort(b); //if (b[0] == a[0]) if (set.size()==2){ if (a[t]==a[1]){ out.print(2 + " " + (1)); } else { out.print(2 + " " + (1+t)); } } else { if (b[0].x!=a[1]){ out.print(2+ " " + (1+b[0].y)); return; } if (b[2].x!=a[1]){ out.print(2+ " " + (1+b[2].y)); return; } if (b[1].x!=a[1]){ out.print(2+ " " + (1+b[1].y)); return; } } } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
2bfc888ae2d490c43421d36c9d9aa525
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.awt.*; import java.awt.geom.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; /* br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); */ public class Main { private static BufferedReader br; private static StringTokenizer st; private static PrintWriter pw; static int[] dx = new int[]{-1,0,1,0}; static int[] dy = new int[]{0,1,0,-1}; static Set<Integer>[] edges; static int k; static boolean[] seen; static boolean[] used; public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); //int qq = 1; int qq = Integer.MAX_VALUE; //int qq = readInt(); for(int casenum = 1; casenum <= qq; casenum++) { int n = readInt(); if(n <= 2) { while(n-->0)readInt(); pw.println(-1); } else { int[] list = new int[n]; for (int i = 0; i < list.length; i++) { list[i] = readInt(); } long t = System.currentTimeMillis(); while(System.currentTimeMillis() - t <= 100) { int a = (int)(Math.random()*n); int b = (int)(Math.random()*n); if(list[a] == list[b]) continue; int c = list[a]; list[a] = list[b]; list[b] = c; boolean le = true; boolean ge = true; for(int i = 1; i < n; i++) { if(list[i] > list[i-1]) { ge = false; } if(list[i] < list[i-1]) { le = false; } } if(!le && !ge) { pw.printf("%d %d\n", ++a, ++b); exitImmediately(); } c = list[a]; list[a] = list[b]; list[b] = c; } pw.println(-1); } } pw.close(); } public static long modpow(long b, long e, long m) { long r = 1; while(e > 0) { if(e%2==1) { r *= b; r %= m; } b *= b; b %= m; e /= 2; } return r; } private static void exitImmediately() { pw.close(); System.exit(0); } private static long readLong() throws IOException { return Long.parseLong(nextToken()); } private static double readDouble() throws IOException { return Double.parseDouble(nextToken()); } private static int readInt() throws IOException { return Integer.parseInt(nextToken()); } private static String nextToken() throws IOException { while(st == null || !st.hasMoreTokens()) { if(!br.ready()) { exitImmediately(); } st = new StringTokenizer(br.readLine().trim()); } return st.nextToken(); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
e211e70682c1858f7d4271e2fce4dcf5
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; public class B { public static class Solver { public static void Solve() { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int a[] = new int[n]; for(int i=0; i<n; i++) a[i] = in.nextInt(); int i1 = 0, i2 = 0; if (n == 1 || n == 2) out.printf("-1"); else { boolean inc=false, dec=false; boolean not = false; for (int i=0; i<n-1; i++) { if (a[i]<a[i+1] && !dec && !not && !inc) { inc = true; i1 = i; i2 = i+1; } else if (inc && a[i]>a[i+1]) { not = true; i1 = i; i2 = i+1; } else if (!dec && !inc && !not && a[i]>a[i+1]) { dec = true; i1 = i; i2 = i+1; } else if (!inc && dec && a[i]<a[i+1]) { not = true; i1 = i; i2 = i+1; } } if (!inc && !dec && !not) { out.printf("-1"); } else if ((inc || dec) && !not){ out.printf("%d %d", i1+1, i2+1); } else { inc = false; dec = false; not = false; int t = a[i1]; a[i1] = a[i2]; a[i2] = t; for (int i=0; i<n-1; i++) { if (a[i]<a[i+1] && !dec) inc = true; else if (a[i]<a[i+1] && dec) not = true; else if (a[i]>a[i+1] && !inc) dec = true; else if (a[i]>a[i+1] && inc) not = true; } if (not) out.printf("%d %d", i1+1, i2+1); else { inc = false; dec = false; not = false; t = a[i1]; a[i1] = a[i2]; a[i2] = t; t = a[i1-1]; a[i1-1] = a[i1]; a[i1] = t; for (int i=0; i<n-1; i++) { if (a[i]<a[i+1] && !dec) inc = true; else if (a[i]<a[i+1] && dec) not = true; else if (a[i]>a[i+1] && !inc) dec = true; else if (a[i]>a[i+1] && inc) not = true; } if (not) out.printf("%d %d", i1, i1+1); else out.printf("-1"); } } } in.close(); out.close(); } } public static void main(String[] args) { // TODO Auto-generated method stub Solver.Solve(); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
cbd8c3844af0ae8d279d04f86d9ca5f2
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] list = new int[n]; StringTokenizer token = new StringTokenizer(br.readLine()); for(int i = 0; i < n; i++) { list[i] = Integer.parseInt(token.nextToken()); } System.out.println(solve(list)); } public static String solve(int[] list) { if( list.length <= 2 || monochromatic(list)) { return "-1"; } if( list.length == 3 && list[0] == list[2]){ return "-1"; } Random r = new Random(); while(true) { int i = r.nextInt(list.length); int j = r.nextInt(list.length); if( list[i] == list[j] ) continue; swap( list, i, j ); if( !sorted(list) ) { return (i+1)+" " + (j+1); } swap( list, i, j ); } } public static void swap(int[] list, int i, int j) { int tmp = list[i]; list[i] = list[j]; list[j] = tmp; } public static boolean sorted(int[] list) { int m = list[0]; int M = list[0]; boolean b1,b2; b1 = b2 = true; for(int i = 1; i < list.length && (b1||b2); i++ ) { if( m > list[i] ) b1 = false; else m = list[i]; if( M < list[i] ) b2 = false; else M = list[i]; } return b1 || b2; } public static boolean monochromatic(int[] list) { int x = list[0]; for(int i = 1; i < list.length; i++ ) { if( list[i] != x ) return false; } return true; } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
21e60e6072ed1e6215605cadb7eded9a
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.util.Scanner; public class b { public static void main(String args[]) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int max = -1,min = Integer.MAX_VALUE; int imax = -1,imin = -1; boolean inc = true, dec = true, equal = true; int[] f = new int[n+1]; f[0] = in.nextInt(); for (int i=1;i<n;i++) { f[i] = in.nextInt(); if (max<=f[i]) { imax = i; max = f[i]; } if (min>f[i]) { imin = i; min = f[i]; } if (f[i-1]!=f[i]) { equal = false; } if (f[i-1]>f[i]) { inc = false; } if (f[i-1]<f[i]) { dec = false; } } if (equal || n==1 || n==2) { System.out.println(-1); return; } if (dec || inc) { for (int i=0;i+1<n;i++) { if (f[i]!=f[i+1]) { System.out.println((i+1)+" "+(i+2)); return; } } } boolean b1,b2; int x; if (!dec && !inc) { for (int i=0;i+1<n;i++) { if (f[i]!=f[i+1]) { x = f[i]; f[i] = f[i+1]; f[i+1] = x; b1 = true; b2 = true; for (int j=0;j<n-1;j++) { if (f[j]>f[j+1]) { b1 = false; break; } } for (int j=0;j<n-1;j++) { if (f[j]<f[j+1]) { b2 = false; break; } } if (b1 || b2) { x = f[i]; f[i] = f[i+1]; f[i+1] = x; } else { System.out.println((i+1)+" "+(i+2)); return; } } } } System.out.println(-1); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
ef69ef1e3c7c85ba4da38c5aed517352
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.io.FileInputStream; import java.io.IOException; import java.math.*; import java.util.*; public class Main2 { private static Scanner in; public static void main(String[] args) throws IOException { // helpers for input/output boolean LOCAL_TEST = false; // LOCAL_TEST = true;// comment it before submitting in = new Scanner(System.in); if (LOCAL_TEST) { in = new Scanner(new FileInputStream("E:\\zin2.txt")); } int N = in.nextInt(); int[] nums = new int[N]; int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for (int i = 0; i < N; i++) { nums[i] = in.nextInt(); if (nums[i] < min) { min = nums[i]; } if (nums[i] > max) { max = nums[i]; } if (!map.containsKey(nums[i])) map.put(nums[i], 1); else map.put(nums[i], map.get(nums[i]) + 1); } if (N <= 2) { System.out.println(-1); return; } if (map.size() == 1) { System.out.println(-1); return; } // for boolean isSortedAsc = isAscending(nums); boolean isSortedDesc = isDescending(nums); if (isSortedAsc || isSortedDesc) { for (int i = 0; i < N - 1; i++) { if (nums[i] != nums[i + 1]) { System.out.println((i + 1) + " " + (i + 2)); return; } } } else { for (int i = 1; i < N - 1; i++) { int x = nums[i]; if (x != min && x != max && x != nums[0]) { System.out.println((i + 1) + " " + 1); return; } if (x != min && x != max && x != nums[N - 1]) { System.out.println((i + 1) + " " + (N)); return; } } // if (N == 3) { // System.out.println(-1); // return; // } for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { if (nums[i] != nums[j]) { int tmp = nums[i]; nums[i] = nums[j]; nums[j] = tmp; if (!isSorted(nums)) { System.out.println((i + 1) + " " + (j + 1)); return; } else { tmp = nums[i]; nums[i] = nums[j]; nums[j] = tmp; } } } } } System.out.println(-1); } static boolean isSorted(int[] n) { return (isAscending(n) || isDescending(n)); } static boolean isAscending(int[] n) { boolean isSortedAscending = true; for (int i = 1; i < n.length; i++) { if (n[i] < n[i - 1]) isSortedAscending = false; } return isSortedAscending; } static boolean isDescending(int[] n) { boolean isSortedDescending = true; for (int i = 1; i < n.length; i++) { if (n[i] > n[i - 1]) isSortedDescending = false; } return isSortedDescending; } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
f440c5aca5d6e25f51d3b13719bb1b3b
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.util.Scanner; public class Round_153_CF_B { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] array = new int[n]; for (int i = 0; i < array.length; i++) { array[i] = scan.nextInt(); } boolean same = true; for (int i = 0; i < array.length - 1; i++) { if (array[i] != array[i + 1]) same = false; } if (array.length <= 2 || same) { System.out.println(-1); } else { int first = -1, second = -1; for (int i = 0; i < array.length - 1; i++) { if (array[i] == array[i + 1]) continue; swap(array, i, i + 1); boolean var = check(array, i); if (var) { first = i; second = i + 1; break; } swap(array, i, i + 1); } if (first == -1) { System.out.println(-1); } else System.out.println((first + 1) + " " + (second + 1)); } } public static boolean check(int[] array, int i) { for (int j = i + 1; j < array.length && j <= 3; j++) { if (array[j] == array[i]) return true; } if (i == 0) { if (array[i] > array[i + 1] && array[i + 1] < array[i + 2]) return true; if (array[i] < array[i + 1] && array[i + 1] > array[i + 2]) return true; } else if (i == array.length - 2) { if (array[i - 1] > array[i] && array[i] < array[i + 1]) return true; if (array[i - 1] < array[i] && array[i] > array[i + 1]) return true; } else { if (array[i] > array[i + 1] && array[i + 1] < array[i + 2]) return true; if (array[i] < array[i + 1] && array[i + 1] > array[i + 2]) return true; if (array[i - 1] > array[i] && array[i] < array[i + 1]) return true; if (array[i - 1] < array[i] && array[i] > array[i + 1]) return true; } return false; } public static void swap(int[] array, int i, int j) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
a250c6cf07e093f962f70991f4bb7561
train_003.jsonl
1354807800
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a1 ≀ a2 ≀ ... ≀ an; a1 β‰₯ a2 β‰₯ ... β‰₯ an. Help Petya find the two required positions to swap or else say that they do not exist.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class UnsortingArray { public void solve() throws IOException { Scanner sc = new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int i = 0, j = 0, k = 0; long ans = 0, sum = 0, count = 0; int n = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for (i = 0; i < n; ++i) { k = sc.nextInt(); a[i] = k; b[i] = k; } //System.out.println(Arrays.toString(a)); boolean eql = true; for (i = 1; i < n; ++i) { if (a[i] != a[i - 1]) { eql = false; } } if (eql) { System.out.println("-1"); System.exit(0); } else { for (i = 0; i < n; ++i) { for (j = i + 1; j < n; ++j) { if (a[i] != a[j]) { k = a[i]; a[i] = a[j]; a[j] = k; if (!isDec(a, n) && !isAec(a, n)) { System.out.println((i + 1) + " " + (j + 1)); System.exit(0); } k = a[i]; a[i] = a[j]; a[j] = k; } } } } System.out.println("-1"); } public static boolean isDec(int a[], int n) { int i = 0; boolean df = true; for (i = 1; i < n; ++i) { if (a[i] > a[i - 1]) { df = false; break; } } // System.out.println("dfD = "+df); // System.out.println(Arrays.toString(a)); return df; } public static boolean isAec(int a[], int n) { int i = 0; boolean df = true; for (i = 1; i < n; ++i) { if (a[i] < a[i - 1]) { df = false; break; } } // System.out.println("df = "+df); // System.out.println(Arrays.toString(a)); return df; } public static void main(String[] args) throws IOException { new UnsortingArray().solve(); } }
Java
["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1"]
2 seconds
["-1", "-1", "1 2", "-1"]
NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
Java 6
standard input
[ "sortings", "brute force" ]
2ae4d2ca09f28d10fa2c71eb2abdaa1c
The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an β€” the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
1,800
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
standard output
PASSED
59e470ca4c90f27fbabb8aa226f2e857
train_003.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.util.Arrays; import java.util.StringTokenizer; import java.io.*; public class Main { public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } } public static void main(String[] args) { FastReader s = new FastReader(); Main obj = new Main(); String str=s.next(); int l=str.length(); int k=s.nextInt(); int len=l/k; for(int i=0;i<l;i++){ if((l % k!=0) || str.charAt(i) != str.charAt((i/len)*len + len - 1 - (i % len))){ System.out.println("NO"); return; } } System.out.println("YES"); } public static boolean palindrome(String str) { int flag=0; for(int i=0;i<str.length()/2;i++) { if(str.charAt(i)==str.charAt(str.length()-i-1)) continue; else { flag=1; break; } } if(flag==0) return true; else return false; } } /* co coo coolest contest cool*/
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 11
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output
PASSED
ae9b11c7ab1af2d2c7f7adab44e1770a
train_003.jsonl
1432658100
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
256 megabytes
import java.util.Scanner; public class concenated_palindrome { public static void main(String args[]) { Scanner s = new Scanner(System.in); String str = s.next(); int k = s.nextInt(); System.out.println(solve(str,k)); } private static String solve(String str,int k) { if(str.length()%k!=0) return ("NO"); int count = 0; int step = str.length()/k; for(int i=0;i<str.length();i+=step) { if(is_a_palindrome(str.substring(i,i+step))) { count++; } } return (count==k)? "YES":"NO"; } private static boolean is_a_palindrome(String str) { int x = 0; int y = str.length()-1; while(x<y) { if(str.charAt(x)!=str.charAt(y)) return false; x++; y--; } return true; } }
Java
["saba\n2", "saddastavvat\n2"]
1 second
["NO", "YES"]
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
Java 11
standard input
[ "implementation", "brute force", "strings" ]
43bb8fec6b0636d88ce30f23b61be39f
The first line of input contains string s containing lowercase English letters (1 ≀ |s| ≀ 1000). The second line contains integer k (1 ≀ k ≀ 1000).
1,100
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
standard output