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 | 9e4687835edb88a45c8603a8582fcd32 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | /**
* A_Linear_Keyboard
*/
import java.util.*;
public class A_Linear_Keyboard {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] s = sc.nextLine().split(" ");
int n = Integer.parseInt(s[0]);
while(n-- > 0){
String str = sc.nextLine();
String t = sc.nextLine();
int res = 0;
for(int i = 1 ; i < t.length(); i++){
char c = t.charAt(i);
int preidx = str.indexOf(t.charAt(i-1));
int curidx = str.indexOf(t.charAt(i));
res += Math.abs(preidx - curidx);
}
System.out.println(res);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 25b77e3c8433385b1d37d35169329e9e | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String[] s = sc.nextLine().split(" ");
int n = Integer.parseInt(s[0]);
while(n-- > 0){
String str = sc.nextLine();
String t = sc.nextLine();
int res = 0;
for(int i = 1 ; i < t.length(); i++){
char c = t.charAt(i);
int preidx = str.indexOf(t.charAt(i-1));
int curidx = str.indexOf(t.charAt(i));
res += Math.abs(preidx - curidx);
}
System.out.println(res);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 0e0309a672c51b1795d4d5a14087a92d | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t--!=0){
String s = sc.next();
String word = sc.next();
HashMap<Character, Integer> map = new HashMap<>();
int k=0;
for(int i=1;i<=26;i++){
map.put(s.charAt(k),i);
k++;
}
int count=0;
for(int i=0;i<word.length()-1;i++){
int num1,num2;
num1 = map.get(word.charAt(i));
num2 = map.get(word.charAt(i+1));
count = count + Math.abs(num2-num1);
}
System.out.println(count);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 2a584b5f67cdd80a84fddde228c01e33 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.lang.*;
import java.util.*;
public class AB
{
public static void main(String args[]) throws Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0)
{
String a=sc.next();
String b=sc.next();
char s1[]=b.toCharArray();
int k,m,o,i,sum=0;
for(i=0,k=i+1;i<s1.length && k<s1.length;i++,k++)
{
o=a.indexOf(s1[i]);
m=a.indexOf(s1[k]);
sum=sum+Math.abs((o+1)-(m+1));
}
System.out.println(sum);
t--;
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | e7cb7c65e5fa522f9962671dbea894ca | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Codeforces {
public static void print(int[] arr) {
//for debugging only
for (int x : arr)
System.out.print(x + " ");
System.out.println();
}
public static boolean isPrime(long n) {
if (n < 2) return false;
if (n == 2 || n == 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
long sqrtN = (long) Math.sqrt(n) + 1;
for (long i = 6L; i <= sqrtN; i += 6) {
if (n % (i - 1) == 0 || n % (i + 1) == 0) return false;
}
return true;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public static ArrayList<Integer> findDiv(int N) {
//gens all divisors of N
ArrayList<Integer> ls1 = new ArrayList<Integer>();
ArrayList<Integer> ls2 = new ArrayList<Integer>();
for (int i = 1; i <= (int) (Math.sqrt(N) + 0.00000001); i++)
if (N % i == 0) {
ls1.add(i);
ls2.add(N / i);
}
Collections.reverse(ls2);
for (int b : ls2)
if (b != ls1.get(ls1.size() - 1))
ls1.add(b);
return ls1;
}
public static void sort(int[] arr) {
//because Arrays.sort() uses quicksort which is dumb
//Collections.sort() uses merge sort
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : arr)
ls.add(x);
Collections.sort(ls);
for (int i = 0; i < arr.length; i++)
arr[i] = ls.get(i);
}
public static long power(long x, long y, long p) {
//0^0 = 1
//Modular Exponentiation (Power in Modular Arithmetic)
// O(logy)
long res = 1L;
x = x % p;
while (y > 0) {
if ((y & 1) == 1)
res = (res * x) % p;
y >>= 1;
x = (x * x) % p;
}
return res;
}
public static void main(String hi[]) throws Exception {
FastScanner scn = new FastScanner();
//Write from here
int t=scn.nextInt();
while(t-->0)
{
String k=scn.next();
StringBuilder kb=new StringBuilder(k);
String s=scn.next();
int res=0;
for (int i = 1; i < s.length(); i++) {
String s1=s.substring(i-1,i);
String s2=s.substring(i,i+1);
res+=Math.abs(kb.indexOf(s2)-kb.indexOf(s1));
}
System.out.println(res);
}
}
}
class FastScanner {
//I don't understand how this works lmao
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1) return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
//returns Int
return (int) nextLong();
}
public int[] nextInts(int N) {
//returns array of integers of size N
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] nextLongs(int N) {
//returns array of Longs of size N
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public long nextLong() {
//return long
cnt = 1;
boolean neg = false;
if (c == NC) c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-') neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
//return double
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] nextDoubles(int N) {
//return array of doubles
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32) return true;
while (true) {
c = getChar();
if (c == NC) return false;
else if (c > 32) return true;
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 9a4364514815e1d73e464c612a2ce971 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
public static void print(int[] arr) {
//for debugging only
for (int x : arr)
System.out.print(x + " ");
System.out.println();
}
public static boolean isPrime(long n) {
if (n < 2) return false;
if (n == 2 || n == 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
long sqrtN = (long) Math.sqrt(n) + 1;
for (long i = 6L; i <= sqrtN; i += 6) {
if (n % (i - 1) == 0 || n % (i + 1) == 0) return false;
}
return true;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public static ArrayList<Integer> findDiv(int N) {
//gens all divisors of N
ArrayList<Integer> ls1 = new ArrayList<Integer>();
ArrayList<Integer> ls2 = new ArrayList<Integer>();
for (int i = 1; i <= (int) (Math.sqrt(N) + 0.00000001); i++)
if (N % i == 0) {
ls1.add(i);
ls2.add(N / i);
}
Collections.reverse(ls2);
for (int b : ls2)
if (b != ls1.get(ls1.size() - 1))
ls1.add(b);
return ls1;
}
public static void sort(int[] arr) {
//because Arrays.sort() uses quicksort which is dumb
//Collections.sort() uses merge sort
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : arr)
ls.add(x);
Collections.sort(ls);
for (int i = 0; i < arr.length; i++)
arr[i] = ls.get(i);
}
public static long power(long x, long y, long p) {
//0^0 = 1
//Modular Exponentiation (Power in Modular Arithmetic)
// O(logy)
long res = 1L;
x = x % p;
while (y > 0) {
if ((y & 1) == 1)
res = (res * x) % p;
y >>= 1;
x = (x * x) % p;
}
return res;
}
public static void main(String hi[]) throws Exception {
FastScanner scn = new FastScanner();
//Write from here
int t=scn.nextInt();
while(t-->0)
{
String k=scn.next();
StringBuilder kb=new StringBuilder(k);
String s=scn.next();
// System.out.println(kb+" "+s);
int res=0;
for (int i = 1; i < s.length(); i++) {
String s1=s.substring(i-1,i);
String s2=s.substring(i,i+1);
// System.out.println(kb.indexOf(s2)+" "+kb.indexOf(s1));
res+=Math.abs(kb.indexOf(s2)-kb.indexOf(s1));
}
System.out.println(res);
}
}
}
class FastScanner {
//I don't understand how this works lmao
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1) return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
//returns Int
return (int) nextLong();
}
public int[] nextInts(int N) {
//returns array of integers of size N
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] nextLongs(int N) {
//returns array of Longs of size N
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public long nextLong() {
//return long
cnt = 1;
boolean neg = false;
if (c == NC) c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-') neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
//return double
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] nextDoubles(int N) {
//return array of doubles
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32) return true;
while (true) {
c = getChar();
if (c == NC) return false;
else if (c > 32) return true;
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | c55a1a8256d0c7058fd80bc30acd788c | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.util.Collections.*;
public class javaTemplate{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
String keys=sc.next();
String s=sc.next();
ArrayList<Character> a= new ArrayList<>();
for(int i=0;i<26;i++){
a.add(keys.charAt(i));
}
//System.out.println(a);
int d=0,e=0;
for(int j=0;j<s.length()-1;j++){
d+=Math.abs(a.indexOf(s.charAt(j))-a.indexOf(s.charAt(j+1)));
//System.out.println(d);
}
System.out.println(d);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 263b57a8bd4b31dee07f2cc40dc56a4f | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | //package Div3;
import java.util.HashMap;
import java.util.Scanner;
public class q1 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
String keyboard=sc.next();
String input=sc.next();
HashMap<Character,Integer> map =new HashMap<>();
for(int i=0;i<keyboard.length();i++){
map.put(keyboard.charAt(i),i);
}
int len=0;
for(int i=1;i<input.length();i++){
len+=Math.abs(map.get(input.charAt(i))-map.get(input.charAt(i-1)));
}
System.out.println(len);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 8636cbef54f5a9142e35215ad2203e4f | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
// snippet
public class LinearKeyBoard {
// Question Link :
public static void main(String[] args) {
FastScanner sc=new FastScanner();
int T=sc.nextInt();
for (int tt=0; tt<T; tt++) {
String string = sc.next();
String string2 = sc.next();
int ans =0;
for (int i = 1; i < string2.length(); i++) {
char ch1 = string2.charAt(i);
char ch2 = string2.charAt(i-1);
ans+= Math.abs(string.indexOf(ch2)-string.indexOf(ch1));
}
System.out.println(ans);
}
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | b8858e17177ea4f4c301a3e85cfb8637 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes |
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.math.*;
import static java.lang.Math.min;
public class a1607A {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader bu = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(bu.readLine());
while (t-- > 0) {
char alp[] = bu.readLine().toCharArray();
int i, c[] = new int[26];
for(i=0;i<26;i++){
c[alp[i]-'a']=i;
}
char s[] = bu.readLine().toCharArray();
int ans=0,n=s.length;
for(i=1;i<n;i++){
ans+=Math.abs(c[s[i]-'a']- c[s[i-1]-'a']);
}
sb.append(ans+"\n");
}
System.out.println(sb);
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | d9140c2739396ab4aab2e13e8a0546d1 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | // package problemset;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.math.*;
import static java.lang.Math.min;
public class a1607A {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader bu = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(bu.readLine());
while (t-- > 0) {
String alpha = bu.readLine();
String res = bu.readLine();
ArrayList<Integer> ans = new ArrayList<>();
int pp = 0;
for (char c : res.toCharArray()) {
for (int i = 1; i <= 26; i++) {
if (alpha.charAt(i - 1) == c) {
ans.add(i);
break;
}
}
}
for (int i = 1; i < ans.size(); i++) {
pp += Math.abs(ans.get(i)-ans.get(i-1));
}
sb.append(pp).append("\n");
}
System.out.println(sb);
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 35311975c9e8ec65fb5dad9e0fa13b80 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class A_Linear_Keyboard {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t -- > 0){
String all = sc.next();
String word = sc.next();
char[] word_arr = word.toCharArray();
int count = 0;
int [] arr = new int[word_arr.length];
for(int i = 0; i < word_arr.length ;i++){
arr[i] = all.indexOf(word_arr[i]) + 1;
}
for (int i = 0; i + 1 < arr.length; i++){
count+= Math.abs(arr[i+1] - arr[i]);
}
System.out.println(count);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 65e39ed7d588d5ac42a037a5dc8db01a | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
s.nextLine();
int[] arr = new int[t];
for(int i=0; i<t; i++) {
String keyboard = s.nextLine();
String word = s.nextLine();
int distance = 0, lastIndex=-1;
for(int j=0; j<word.length(); j++) {
char letterNow = word.charAt(j);
for(int k=0; k<keyboard.length(); k++) {
if(lastIndex == -1 && keyboard.charAt(k) == letterNow) lastIndex = k;
else if(keyboard.charAt(k) == letterNow) {
distance += Math.abs(k-lastIndex);
lastIndex = k;
}
}
}
arr[i] = distance;
}
s.close();
for(int n : arr) {
System.out.println(n);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 11 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | a74a5f872acdb099c73f5d9269ed1677 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class Keyboard{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int r = sc.nextInt();
for(int i = 0; i < r; i++){
int holder = 0;
String keybaord = sc.next();
String word = sc.next();
int length = word.length();
int time = 0;
for(int e = 1; e < length+1; e++){
String what = word.substring(e-1, e);
int time1 = keybaord.indexOf(what)+1;
if(holder != 0){
time = time + Math.abs(time1 - holder);
}
holder = time1;
}
System.out.println(time);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | cba418fc13371d4b85da340359bdcbd9 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.*;import java.util.*;import java.util.stream.Stream;import java.util.stream.StreamSupport; public class MainClass { static PrintWriter out = new PrintWriter(System.out); static StringBuffer strb = new StringBuffer(); static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { int loop = 0; int b; loop = Integer.valueOf(in.readLine()); int spent = 0; char b2; char[] ints = new char[26];int[] ints2 = new int[26]; for (int i = 0; i < loop; i++) {in.read(ints, 0, 26);for (int j = 0; j < 26; j++) { ints2[ints[j] - 'a'] = j;}in.read(ints, 0, 3);b = ints[2];while ((b2 = (char) in.read()) != '\n' && b2 != 13) { spent += Math.abs(ints2[b - 'a'] - ints2[b2 - 'a']); b = b2;}in.read();strb.append(spent).append('\n');spent = 0; } out.write(strb.toString()); out.flush(); } public static class BufferedReader extends Reader { private Reader in; private char cb[]; private int nChars, nextChar; private static final int INVALIDATED = -2; private static final int UNMARKED = -1; private int markedChar = UNMARKED; private int readAheadLimit = 0; private boolean skipLF = false; private boolean markedSkipLF = false; private static int defaultCharBufferSize = 8192; private static int defaultExpectedLineLength = 80; public BufferedReader(Reader in, int sz) {super(in);if (sz <= 0) throw new IllegalArgumentException("Buffer size <= 0");this.in = in;cb = new char[sz];nextChar = nChars = 0; } public BufferedReader(Reader in) {this(in, defaultCharBufferSize); } private void ensureOpen() throws IOException {if (in == null) throw new IOException("Stream closed"); } private void fill() throws IOException {int dst;if (markedChar <= UNMARKED) { dst = 0;} else { int delta = nextChar - markedChar; if (delta >= readAheadLimit) {markedChar = INVALIDATED;readAheadLimit = 0;dst = 0; } else {if (readAheadLimit <= cb.length) { System.arraycopy(cb, markedChar, cb, 0, delta); markedChar = 0; dst = delta;} else { char ncb[] = new char[readAheadLimit]; System.arraycopy(cb, markedChar, ncb, 0, delta); cb = ncb; markedChar = 0; dst = delta;}nextChar = nChars = delta; }}int n;do { n = in.read(cb, dst, cb.length - dst);} while (n == 0);if (n > 0) { nChars = dst + n; nextChar = dst;} } public int read() throws IOException {synchronized (lock) { for (; ; ) {if (nextChar >= nChars) { fill(); if (nextChar >= nChars) return -1;}if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') { nextChar++; continue; }}return cb[nextChar++]; }} } private int read1(char[] cbuf, int off, int len) throws IOException {if (nextChar >= nChars) { if (len >= cb.length && markedChar <= UNMARKED && !skipLF) {return in.read(cbuf, off, len); } fill();}if (nextChar >= nChars) return -1;if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') {nextChar++;if (nextChar >= nChars) fill();if (nextChar >= nChars) return -1; }}int n = Math.min(len, nChars - nextChar);System.arraycopy(cb, nextChar, cbuf, off, n);nextChar += n;return n; } public int read(char cbuf[], int off, int len) throws IOException {synchronized (lock) { if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) {throw new IndexOutOfBoundsException(); } else if (len == 0) {return 0; } int n = read1(cbuf, off, len); if (n <= 0) return n; while ((n < len) && in.ready()) {int n1 = read1(cbuf, off + n, len - n);if (n1 <= 0) break;n += n1; } return n;} } public String readLine() throws IOException {StringBuilder s = null;int startChar;bufferLoop:for (; ; ) { int dst = 0; int n; do {n = in.read(cb, dst, cb.length - dst); } while (n == 0); if (n > 0) {nChars = dst + n;nextChar = dst; } boolean eol = false; char c = 0; int i; skipLF = false; charLoop: for (i = nextChar; i < nChars; i++) {c = cb[i];if ((c == '\n') || (c == '\r')) { eol = true; break charLoop;} } startChar = nextChar; nextChar = i; if (eol) {String str;if (s == null) { str = new String(cb, startChar, i - startChar);} else { s.append(cb, startChar, i - startChar); str = s.toString();}nextChar++;if (c == '\r') { skipLF = true;}return str; } s.append(cb, startChar, i - startChar);} } public long skip(long n) throws IOException {synchronized (lock) { long r = n; while (r > 0) {if (nextChar >= nChars) fill();if (nextChar >= nChars) /* EOF */ break;if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') { nextChar++; }}long d = nChars - nextChar;if (r <= d) { nextChar += r; r = 0; break;} else { r -= d; nextChar = nChars;} } return n - r;} } public boolean ready() throws IOException {synchronized (lock) { if (skipLF) {if (nextChar >= nChars && in.ready()) { fill();}if (nextChar < nChars) { if (cb[nextChar] == '\n') nextChar++; skipLF = false;} } return (nextChar < nChars) || in.ready();} } public boolean markSupported() {return true; } public void mark(int readAheadLimit) throws IOException {if (readAheadLimit < 0) { throw new IllegalArgumentException("Read-ahead limit < 0");}synchronized (lock) { this.readAheadLimit = readAheadLimit; markedChar = nextChar; markedSkipLF = skipLF;} } public void reset() throws IOException {synchronized (lock) { if (markedChar < 0)throw new IOException((markedChar == INVALIDATED) ? "Mark invalid" : "Stream not marked"); nextChar = markedChar; skipLF = markedSkipLF;} } public void close() throws IOException {synchronized (lock) { if (in == null)return; try {in.close(); } finally {in = null;cb = null; }} } public Stream<String> lines() {Iterator<String> iter = new Iterator<String>() { String nextLine = null; @Override public boolean hasNext() {if (nextLine != null) { return true;} else { try { nextLine = readLine(); return (nextLine != null); } catch (IOException e) { throw new UncheckedIOException(e); }} } @Override public String next() {if (nextLine != null || hasNext()) { String line = nextLine; nextLine = null; return line;} else { throw new NoSuchElementException();} }};return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED | Spliterator.NONNULL), false); } }} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 8b470b2168bcb67cde60553b0c779ec3 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.*;import java.util.*;import java.util.stream.Stream;import java.util.stream.StreamSupport; public class MainClass { static PrintWriter out = new PrintWriter(System.out); static StringBuffer strb = new StringBuffer(); static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { int loop = 0; int b; loop = Integer.valueOf(in.readLine()); int spent = 0; char b2; char[] ints = new char[26]; int[] ints2 = new int[26]; for (int i = 0; i < loop; i++) {in.read(ints, 0, 26);for (int j = 0; j < 26; j++) { ints2[ints[j] - 'a'] = j;}in.read(ints, 0, 3);b = ints[2];while ((b2 = (char) in.read()) != '\n' && b2 != 13) { spent += Math.abs(ints2[b - 'a'] - ints2[b2 - 'a']); b = b2;}in.read();strb.append(spent).append('\n');spent = 0; } out.write(strb.toString()); out.flush(); } public static class BufferedReader extends Reader { private Reader in; private char cb[]; private int nChars, nextChar; private static final int INVALIDATED = -2; private static final int UNMARKED = -1; private int markedChar = UNMARKED; private int readAheadLimit = 0; private boolean skipLF = false; private boolean markedSkipLF = false; private static int defaultCharBufferSize = 8192; private static int defaultExpectedLineLength = 80; public BufferedReader(Reader in, int sz) {super(in);if (sz <= 0) throw new IllegalArgumentException("Buffer size <= 0");this.in = in;cb = new char[sz];nextChar = nChars = 0; } public BufferedReader(Reader in) {this(in, defaultCharBufferSize); } private void ensureOpen() throws IOException {if (in == null) throw new IOException("Stream closed"); } private void fill() throws IOException {int dst;if (markedChar <= UNMARKED) { dst = 0;} else { int delta = nextChar - markedChar; if (delta >= readAheadLimit) {markedChar = INVALIDATED;readAheadLimit = 0;dst = 0; } else {if (readAheadLimit <= cb.length) { System.arraycopy(cb, markedChar, cb, 0, delta); markedChar = 0; dst = delta;} else { char ncb[] = new char[readAheadLimit]; System.arraycopy(cb, markedChar, ncb, 0, delta); cb = ncb; markedChar = 0; dst = delta;}nextChar = nChars = delta; }}int n;do { n = in.read(cb, dst, cb.length - dst);} while (n == 0);if (n > 0) { nChars = dst + n; nextChar = dst;} } public int read() throws IOException {synchronized (lock) { for (; ; ) {if (nextChar >= nChars) { fill(); if (nextChar >= nChars) return -1;}if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') { nextChar++; continue; }}return cb[nextChar++]; }} } private int read1(char[] cbuf, int off, int len) throws IOException {if (nextChar >= nChars) { if (len >= cb.length && markedChar <= UNMARKED && !skipLF) {return in.read(cbuf, off, len); } fill();}if (nextChar >= nChars) return -1;if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') {nextChar++;if (nextChar >= nChars) fill();if (nextChar >= nChars) return -1; }}int n = Math.min(len, nChars - nextChar);System.arraycopy(cb, nextChar, cbuf, off, n);nextChar += n;return n; } public int read(char cbuf[], int off, int len) throws IOException {synchronized (lock) { if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) {throw new IndexOutOfBoundsException(); } else if (len == 0) {return 0; } int n = read1(cbuf, off, len); if (n <= 0) return n; while ((n < len) && in.ready()) {int n1 = read1(cbuf, off + n, len - n);if (n1 <= 0) break;n += n1; } return n;} } public String readLine() throws IOException {StringBuilder s = null;int startChar;bufferLoop:for (; ; ) { int dst = 0; int n; do {n = in.read(cb, dst, cb.length - dst); } while (n == 0); if (n > 0) {nChars = dst + n;nextChar = dst; } boolean eol = false; char c = 0; int i; skipLF = false; charLoop: for (i = nextChar; i < nChars; i++) {c = cb[i];if ((c == '\n') || (c == '\r')) { eol = true; break charLoop;} } startChar = nextChar; nextChar = i; if (eol) {String str;if (s == null) { str = new String(cb, startChar, i - startChar);} else { s.append(cb, startChar, i - startChar); str = s.toString();}nextChar++;if (c == '\r') { skipLF = true;}return str; } s.append(cb, startChar, i - startChar);} } public long skip(long n) throws IOException {synchronized (lock) { long r = n; while (r > 0) {if (nextChar >= nChars) fill();if (nextChar >= nChars) /* EOF */ break;if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') { nextChar++; }}long d = nChars - nextChar;if (r <= d) { nextChar += r; r = 0; break;} else { r -= d; nextChar = nChars;} } return n - r;} } public boolean ready() throws IOException {synchronized (lock) { if (skipLF) {if (nextChar >= nChars && in.ready()) { fill();}if (nextChar < nChars) { if (cb[nextChar] == '\n') nextChar++; skipLF = false;} } return (nextChar < nChars) || in.ready();} } public boolean markSupported() {return true; } public void mark(int readAheadLimit) throws IOException {if (readAheadLimit < 0) { throw new IllegalArgumentException("Read-ahead limit < 0");}synchronized (lock) { this.readAheadLimit = readAheadLimit; markedChar = nextChar; markedSkipLF = skipLF;} } public void reset() throws IOException {synchronized (lock) { if (markedChar < 0)throw new IOException((markedChar == INVALIDATED) ? "Mark invalid" : "Stream not marked"); nextChar = markedChar; skipLF = markedSkipLF;} } public void close() throws IOException {synchronized (lock) { if (in == null)return; try {in.close(); } finally {in = null;cb = null; }} } public Stream<String> lines() {Iterator<String> iter = new Iterator<String>() { String nextLine = null; @Override public boolean hasNext() {if (nextLine != null) { return true;} else { try { nextLine = readLine(); return (nextLine != null); } catch (IOException e) { throw new UncheckedIOException(e); }} } @Override public String next() {if (nextLine != null || hasNext()) { String line = nextLine; nextLine = null; return line;} else { throw new NoSuchElementException();} }};return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED | Spliterator.NONNULL), false); } }} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 2e4bf6d337f50aa8f374b91106acd7ae | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.*;import java.util.*;import java.util.stream.Stream;import java.util.stream.StreamSupport; public class MainClass { static PrintWriter out = new PrintWriter(System.out); static StringBuffer strb = new StringBuffer(); static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { int loop = 0; int b; loop = Integer.valueOf(in.readLine()); int spent = 0; char b2; char[] ints = new char[26]; int[] ints2 = new int[26]; for (int i = 0; i < loop; i++) {in.read(ints, 0, 26);for (int j = 0; j < 26; j++) { ints2[ints[j] - 'a'] = j;}in.read(ints, 0, 3);b = ints[2];while ((b2 = (char) in.read()) != '\n' && b2 != 13) { spent += Math.abs(ints2[b - 'a'] - ints2[b2 - 'a']); b = b2;}in.read();strb.append(spent).append('\n');spent = 0; } out.write(strb.toString()); out.flush(); } public static class BufferedReader extends Reader { private Reader in; private char cb[]; private int nChars, nextChar; private static final int INVALIDATED = -2; private static final int UNMARKED = -1; private int markedChar = UNMARKED; private int readAheadLimit = 0; private boolean skipLF = false; private boolean markedSkipLF = false; private static int defaultCharBufferSize = 8192; private static int defaultExpectedLineLength = 80; public BufferedReader(Reader in, int sz) {super(in);if (sz <= 0) throw new IllegalArgumentException("Buffer size <= 0");this.in = in;cb = new char[sz];nextChar = nChars = 0; } public BufferedReader(Reader in) {this(in, defaultCharBufferSize); } private void ensureOpen() throws IOException {if (in == null) throw new IOException("Stream closed"); } private void fill() throws IOException {int dst;if (markedChar <= UNMARKED) { dst = 0;} else { int delta = nextChar - markedChar; if (delta >= readAheadLimit) {markedChar = INVALIDATED;readAheadLimit = 0;dst = 0; } else {if (readAheadLimit <= cb.length) { System.arraycopy(cb, markedChar, cb, 0, delta); markedChar = 0; dst = delta;} else { char ncb[] = new char[readAheadLimit]; System.arraycopy(cb, markedChar, ncb, 0, delta); cb = ncb; markedChar = 0; dst = delta;}nextChar = nChars = delta; }}int n;do { n = in.read(cb, dst, cb.length - dst);} while (n == 0);if (n > 0) { nChars = dst + n; nextChar = dst;} } public int read() throws IOException {synchronized (lock) { for (; ; ) {if (nextChar >= nChars) { fill(); if (nextChar >= nChars) return -1;}if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') { nextChar++; continue; }}return cb[nextChar++]; }} } private int read1(char[] cbuf, int off, int len) throws IOException {if (nextChar >= nChars) { if (len >= cb.length && markedChar <= UNMARKED && !skipLF) {return in.read(cbuf, off, len); } fill();}if (nextChar >= nChars) return -1;if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') {nextChar++;if (nextChar >= nChars) fill();if (nextChar >= nChars) return -1; }}int n = Math.min(len, nChars - nextChar);System.arraycopy(cb, nextChar, cbuf, off, n);nextChar += n;return n; } public int read(char cbuf[], int off, int len) throws IOException {synchronized (lock) { if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) {throw new IndexOutOfBoundsException(); } else if (len == 0) {return 0; } int n = read1(cbuf, off, len); if (n <= 0) return n; while ((n < len) && in.ready()) {int n1 = read1(cbuf, off + n, len - n);if (n1 <= 0) break;n += n1; } return n;} } public String readLine() throws IOException {StringBuilder s = null;int startChar;bufferLoop:for (; ; ) { int dst = 0; int n; do {n = in.read(cb, dst, cb.length - dst); } while (n == 0); if (n > 0) {nChars = dst + n;nextChar = dst; } boolean eol = false; char c = 0; int i; skipLF = false; charLoop: for (i = nextChar; i < nChars; i++) {c = cb[i];if ((c == '\n') || (c == '\r')) { eol = true; break charLoop;} } startChar = nextChar; nextChar = i; if (eol) {String str;if (s == null) { str = new String(cb, startChar, i - startChar);} else { s.append(cb, startChar, i - startChar); str = s.toString();}nextChar++;if (c == '\r') { skipLF = true;}return str; } s.append(cb, startChar, i - startChar);} } public long skip(long n) throws IOException {synchronized (lock) { long r = n; while (r > 0) {if (nextChar >= nChars) fill();if (nextChar >= nChars) /* EOF */ break;if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') { nextChar++; }}long d = nChars - nextChar;if (r <= d) { nextChar += r; r = 0; break;} else { r -= d; nextChar = nChars;} } return n - r;} } public boolean ready() throws IOException {synchronized (lock) { if (skipLF) {if (nextChar >= nChars && in.ready()) { fill();}if (nextChar < nChars) { if (cb[nextChar] == '\n') nextChar++; skipLF = false;} } return (nextChar < nChars) || in.ready();} } public boolean markSupported() {return true; } public void mark(int readAheadLimit) throws IOException {if (readAheadLimit < 0) { throw new IllegalArgumentException("Read-ahead limit < 0");}synchronized (lock) { this.readAheadLimit = readAheadLimit; markedChar = nextChar; markedSkipLF = skipLF;} } public void reset() throws IOException {synchronized (lock) { if (markedChar < 0)throw new IOException((markedChar == INVALIDATED) ? "Mark invalid" : "Stream not marked"); nextChar = markedChar; skipLF = markedSkipLF;} } public void close() throws IOException {synchronized (lock) { if (in == null)return; try {in.close(); } finally {in = null;cb = null; }} } public Stream<String> lines() {Iterator<String> iter = new Iterator<String>() { String nextLine = null; @Override public boolean hasNext() {if (nextLine != null) { return true;} else { try { nextLine = readLine(); return (nextLine != null); } catch (IOException e) { throw new UncheckedIOException(e); }} } @Override public String next() {if (nextLine != null || hasNext()) { String line = nextLine; nextLine = null; return line;} else { throw new NoSuchElementException();} }};return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED | Spliterator.NONNULL), false); } }} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | d69bcedf00a263effded854f7e2c3695 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Coder {
static StringBuffer str=new StringBuffer();
static int n;
static Map<Character, Integer> m=new HashMap<>();
static char c[];
static char s[];
static void solve(){
int ans=0;
for(int i=0;i<26;i++){
m.put(c[i], i+1);
}
for(int i=0;i<s.length-1;i++){
ans+=Math.abs(m.get(s[i])-m.get(s[i+1]));
}
str.append(ans).append("\n");
}
public static void main(String[] args) throws java.lang.Exception {
BufferedReader bf;
PrintWriter pw;
boolean lenv=false;
if(lenv){
bf = new BufferedReader(
new FileReader("input.txt"));
pw=new PrintWriter(new
BufferedWriter(new FileWriter("output.txt")));
}else{
bf = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
}
int q = Integer.parseInt(bf.readLine().trim());
while (q-- > 0) {
c=bf.readLine().trim().toCharArray();
s=bf.readLine().trim().toCharArray();
solve();
}
pw.print(str);
pw.flush();
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | b535f70603066c42dfbc3cdd86d5f5e1 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class MainClass {
static PrintWriter out = new PrintWriter(System.out);
static StringBuffer strb = new StringBuffer();
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
int loop = 0;
int b;
loop = Integer.valueOf(in.readLine());
int spent = 0;
char b2;
char[] ints = new char[26];
int[] ints2 = new int[26];
for (int i = 0; i < loop; i++) {
in.read(ints, 0, 26);
for (int j = 0; j < 26; j++) {
ints2[ints[j] - 'a'] = j;
}
in.read(ints, 0, 3);
b = ints[2];
while ((b2 = (char) in.read()) != '\n' && b2 != 13) {
spent += Math.abs(ints2[b - 'a'] - ints2[b2 - 'a']);
b = b2;
}
in.read();
strb.append(spent).append('\n');
spent = 0;
}
out.write(strb.toString());
out.flush();
}
public static class BufferedReader extends Reader {
private Reader in;
private char cb[];
private int nChars, nextChar;
private static final int INVALIDATED = -2;
private static final int UNMARKED = -1;
private int markedChar = UNMARKED;
private int readAheadLimit = 0;
private boolean skipLF = false;
private boolean markedSkipLF = false;
private static int defaultCharBufferSize = 8192;
private static int defaultExpectedLineLength = 80;
public BufferedReader(Reader in, int sz) {
super(in);
if (sz <= 0)
throw new IllegalArgumentException("Buffer size <= 0");
this.in = in;
cb = new char[sz];
nextChar = nChars = 0;
}
public BufferedReader(Reader in) {
this(in, defaultCharBufferSize);
}
private void ensureOpen() throws IOException {
if (in == null)
throw new IOException("Stream closed");
}
private void fill() throws IOException {
int dst;
if (markedChar <= UNMARKED) {
dst = 0;
} else {
int delta = nextChar - markedChar;
if (delta >= readAheadLimit) {
markedChar = INVALIDATED;
readAheadLimit = 0;
dst = 0;
} else {
if (readAheadLimit <= cb.length) {
System.arraycopy(cb, markedChar, cb, 0, delta);
markedChar = 0;
dst = delta;
} else {
char ncb[] = new char[readAheadLimit];
System.arraycopy(cb, markedChar, ncb, 0, delta);
cb = ncb;
markedChar = 0;
dst = delta;
}
nextChar = nChars = delta;
}
}
int n;
do {
n = in.read(cb, dst, cb.length - dst);
} while (n == 0);
if (n > 0) {
nChars = dst + n;
nextChar = dst;
}
}
public int read() throws IOException {
synchronized (lock) {
for (; ; ) {
if (nextChar >= nChars) {
fill();
if (nextChar >= nChars)
return -1;
}
if (skipLF) {
skipLF = false;
if (cb[nextChar] == '\n') {
nextChar++;
continue;
}
}
return cb[nextChar++];
}
}
}
private int read1(char[] cbuf, int off, int len) throws IOException {
if (nextChar >= nChars) {
if (len >= cb.length && markedChar <= UNMARKED && !skipLF) {
return in.read(cbuf, off, len);
}
fill();
}
if (nextChar >= nChars) return -1;
if (skipLF) {
skipLF = false;
if (cb[nextChar] == '\n') {
nextChar++;
if (nextChar >= nChars)
fill();
if (nextChar >= nChars)
return -1;
}
}
int n = Math.min(len, nChars - nextChar);
System.arraycopy(cb, nextChar, cbuf, off, n);
nextChar += n;
return n;
}
public int read(char cbuf[], int off, int len) throws IOException {
synchronized (lock) {
if ((off < 0) || (off > cbuf.length) || (len < 0) ||
((off + len) > cbuf.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
int n = read1(cbuf, off, len);
if (n <= 0) return n;
while ((n < len) && in.ready()) {
int n1 = read1(cbuf, off + n, len - n);
if (n1 <= 0) break;
n += n1;
}
return n;
}
}
public String readLine() throws IOException {
StringBuilder s = null;
int startChar;
bufferLoop:
for (; ; ) {
int dst = 0;
int n;
do {
n = in.read(cb, dst, cb.length - dst);
} while (n == 0);
if (n > 0) {
nChars = dst + n;
nextChar = dst;
}
boolean eol = false;
char c = 0;
int i;
skipLF = false;
charLoop:
for (i = nextChar; i < nChars; i++) {
c = cb[i];
if ((c == '\n') || (c == '\r')) {
eol = true;
break charLoop;
}
}
startChar = nextChar;
nextChar = i;
if (eol) {
String str;
if (s == null) {
str = new String(cb, startChar, i - startChar);
} else {
s.append(cb, startChar, i - startChar);
str = s.toString();
}
nextChar++;
if (c == '\r') {
skipLF = true;
}
return str;
}
s.append(cb, startChar, i - startChar);
}
}
public long skip(long n) throws IOException {
synchronized (lock) {
long r = n;
while (r > 0) {
if (nextChar >= nChars)
fill();
if (nextChar >= nChars) /* EOF */
break;
if (skipLF) {
skipLF = false;
if (cb[nextChar] == '\n') {
nextChar++;
}
}
long d = nChars - nextChar;
if (r <= d) {
nextChar += r;
r = 0;
break;
} else {
r -= d;
nextChar = nChars;
}
}
return n - r;
}
}
public boolean ready() throws IOException {
synchronized (lock) {
if (skipLF) {
if (nextChar >= nChars && in.ready()) {
fill();
}
if (nextChar < nChars) {
if (cb[nextChar] == '\n')
nextChar++;
skipLF = false;
}
}
return (nextChar < nChars) || in.ready();
}
}
public boolean markSupported() {
return true;
}
public void mark(int readAheadLimit) throws IOException {
if (readAheadLimit < 0) {
throw new IllegalArgumentException("Read-ahead limit < 0");
}
synchronized (lock) {
this.readAheadLimit = readAheadLimit;
markedChar = nextChar;
markedSkipLF = skipLF;
}
}
public void reset() throws IOException {
synchronized (lock) {
if (markedChar < 0)
throw new IOException((markedChar == INVALIDATED)
? "Mark invalid"
: "Stream not marked");
nextChar = markedChar;
skipLF = markedSkipLF;
}
}
public void close() throws IOException {
synchronized (lock) {
if (in == null)
return;
try {
in.close();
} finally {
in = null;
cb = null;
}
}
}
public Stream<String> lines() {
Iterator<String> iter = new Iterator<String>() {
String nextLine = null;
@Override
public boolean hasNext() {
if (nextLine != null) {
return true;
} else {
try {
nextLine = readLine();
return (nextLine != null);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
@Override
public String next() {
if (nextLine != null || hasNext()) {
String line = nextLine;
nextLine = null;
return line;
} else {
throw new NoSuchElementException();
}
}
};
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(
iter, Spliterator.ORDERED | Spliterator.NONNULL), false);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 623d777d1d00d6fd2f4189e6ced09118 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
public class MainClass {
public static InputStream in = (System.in);
final static PrintWriter out = new PrintWriter(System.out);
final static StringBuffer strb = new StringBuffer();
public static void main(String[] args) throws IOException {
int loop = 0;
int b;
while ((b = (char) in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
int spent = 0;
char b2;
byte[] ints = new byte[26];
int[] ints2 = new int[26];
for (int i = 0; i < loop; i++) {
in.read(ints, 0, 26);
for (int j = 0; j < 26; j++) {
ints2[ints[j] - 'a'] = j;
}
in.read(ints, 0, 3);
b = ints[2];
while ((b2 = (char) in.read()) != '\n' && b2 != 13) {
spent += Math.abs(ints2[b - 'a'] - ints2[b2 - 'a']);
b = b2;
}
in.read();
strb.append(spent).append('\n');
spent = 0;
}
out.write(strb.toString());
out.flush();
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 6ee40e7071c4aa613a5df835f5b1ff1d | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
public class MainClass {
public static InputStreamReader in = new InputStreamReader(System.in);
final static HashMap<Character, Integer> map = new HashMap<>();
final static PrintWriter out = new PrintWriter(System.out);
final static StringBuffer strb = new StringBuffer();
public static void main(String[] args) throws IOException {
int loop = 0;
char b;
while ((b = (char) in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
int spent = 0;
char b2;
char[] ints = new char[26];
for (int i = 0; i < loop; i++) {
in.read(ints,0,26);
for (int j = 0; j < 26; j++) {
map.put(ints[j], j);
}
in.read(ints,0,3);
b = ints[2];
while ((b2 = (char)in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
in.read();
strb.append(spent).append('\n');
spent = 0;
}
out.write(strb.toString());
out.flush();
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 807f0ef98e1b3d08d9a7242ad6dbbd18 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
public class MainClass {
public static InputStream in = System.in;
final static HashMap<Integer, Integer> map = new HashMap<>();
final static PrintWriter out = new PrintWriter(System.out);
final static StringBuffer strb = new StringBuffer();
public static void main(String[] args) throws IOException {
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
int spent = 0;
int b2;
byte[] ints = new byte[26];
for (int i = 0; i < loop; i++) {
in.read(ints,0,26);
for (int j = 0; j < 26; j++) {
map.put((int) ints[j], j);
}
in.read(ints,0,3);
b = ints[2];
while ((b2 = in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
in.read();
strb.append(spent).append('\n');
spent = 0;
}
out.write(strb.toString());
out.flush();
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | b9e32448a6f778cef1a8d78df8e50378 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
public class MainClass {
public static InputStream in = System.in;
final static HashMap<Integer, Integer> map = new HashMap<>();
final static PrintWriter out = new PrintWriter(System.out);
final static StringBuffer strb = new StringBuffer();
public static void main(String[] args) throws IOException {
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
int spent = 0;
int b2;
for (int i = 0; i < loop; i++) {
for (int j = 0; j < 26; j++) {
map.put(in.read(), j);
}
in.read();
in.read();
b = in.read();
while ((b2 = in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
in.read();
strb.append(spent).append('\n');
spent = 0;
}
out.write(strb.toString());
out.flush();
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | ad1990b694a5516a3e677a8c1d3cc90f | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
public class MainClass {
final static InputStream in = System.in;
final static HashMap<Integer, Integer> map = new HashMap<>();
final static OutputStream out = System.out;
public static void main(String[] args) throws IOException {
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
int spent = 0;
int b2;
for (int i = 0; i < loop; i++) {
for (int j = 0; j < 26; j++) {
map.put(in.read(), j);
}
in.read();
in.read();
b = in.read();
while ((b2 = in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
in.read();
out.write((spent + "\n").getBytes(StandardCharsets.UTF_8));
spent = 0;
}
out.flush();
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 92b436e54b64b5a5cea4c413176df764 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
public class MainClass {
public static InputStream in = System.in;
final static HashMap<Integer, Integer> map = new HashMap<>();
final static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
int spent = 0;
int b2;
for (int i = 0; i < loop; i++) {
for (int j = 0; j < 26; j++) {
map.put(in.read(), j);
}
in.read();
in.read();
b = in.read();
while ((b2 = in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
in.read();
out.print(spent);
out.print('\n');
spent = 0;
}
out.flush();
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 9f46265d9ad7623fccd1fca32c013103 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
public class MainClass {
final static InputStream in = System.in;
final static HashMap<Integer, Integer> map = new HashMap<>();
final static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
int j = 0;
int spent = 0;
int b2;
for (int i = 0; i < loop; i++) {
while ((b = in.read()) != 13) {
map.put(b, j++);
}
j = 0;
in.read();
b = in.read();
while ((b2 = in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
out.print(spent);
out.print('\n');
spent = 0;
}
out.flush();
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 1d67556c8a86ddb0eec5ed833a62e30d | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
public class MainClass {
final static InputStream in = System.in;
final static HashMap<Integer, Integer> map = new HashMap<>();
final static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
int j = 0;
int spent = 0;
int b2;
for (int i = 0; i < loop; i++) {
while ((b = in.read()) != 13) {
map.put(b, j++);
}
j = 0;
in.read();
b = in.read();
while ((b2 = in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
out.println(spent);
spent = 0;
}
out.flush();
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 5635679d340f43c3e33b96f528a2eecc | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
public class MainClass {
final static InputStream in = System.in;
final static HashMap<Integer, Integer> map = new HashMap<>();
final static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
int j = 0;
int spent = 0;
int b2;
for (int i = 0; i < loop; i++) {
while ((b = in.read()) != 13) {
map.put(b, j++);
}
j = 0;
in.read();
b = in.read();
while ((b2 = in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
out.println(spent);
out.flush();
spent = 0;
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | f6274265afd484d037a777a215410cc5 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
public class MainClass {
final static InputStream in = System.in;
final static HashMap<Integer, Integer> map = new HashMap<>();
public static void main(String[] args) throws IOException {
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
int j = 0;
int spent = 0;
int b2;
for (int i = 0; i < loop; i++) {
while ((b = in.read()) != 13) {
map.put(b, j++);
}
j = 0;
in.read();
b = in.read();
while ((b2 = in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
System.out.println(spent);
spent = 0;
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 34d198c2cb6a47c3348cf3a4417d67f2 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
public class MainClass {
final static byte[] DigitOnes = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
};
final static byte[] DigitTens = {
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
'2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
'3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
'4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
'5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
'6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
'7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
'8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
'9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
};
final static byte[] digits = {
'0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'a', 'b',
'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z'
};
final static int[] sizeTable = {9, 99, 999, 9999, 99999, 999999, 9999999,
99999999, 999999999, Integer.MAX_VALUE};
public static void main(String[] args) throws IOException {
InputStream in = System.in;
OutputStream out = System.out;
HashMap<Integer, Integer> map = new HashMap<>();
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
for (int i = 0; i < loop; i++) {
int j = 0;
while ((b = in.read()) != 13) {
map.put(b, j++);
}
in.read();
int spent = 0;
b = in.read();
int b2;
while ((b2 = in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
int size = (spent < 0) ? stringSize(-spent) + 1 : stringSize(spent);
byte[] buf = new byte[size];
getChars(spent, size, buf);
out.write(buf);
out.write('\n');
out.flush();
}
}
static int stringSize(int x) {
for (int i = 0; ; i++)
if (x <= sizeTable[i])
return i + 1;
}
static void getChars(int i, int index, byte[] buf) {
int q, r;
int charPos = index;
while (i >= 65536) {
q = i / 100;
r = i - ((q << 6) + (q << 5) + (q << 2));
i = q;
buf[--charPos] = DigitOnes[r];
buf[--charPos] = DigitTens[r];
}
for (; ; ) {
q = (i * 52429) >>> (16 + 3);
r = i - ((q << 3) + (q << 1));
buf[--charPos] = digits[r];
i = q;
if (i == 0) break;
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | c72f72116ba8d0b8a4e15c8ded7d2ebc | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
public class MainClass {
public static void main(String[] args) throws IOException {
InputStream in = System.in;
HashMap<Integer, Integer> map = new HashMap<>();
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
int j = 0;
int spent = 0;
int b2;
for (int i = 0; i < loop; i++) {
while ((b = in.read()) != 13) {
map.put(b, j++);
}
j = 0;
in.read();
b = in.read();
while ((b2 = in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
b2 = 0;
System.out.println(spent);
spent = 0;
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 31b70e5d805ee6e6ce532e701d43d6b0 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
public class MainClass {
public static void main(String[] args) throws IOException {
InputStream in = System.in;
HashMap<Integer, Integer> map = new HashMap<>();
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
for (int i = 0; i < loop; i++) {
int j = 0;
while ((b = in.read()) != 13) {
map.put(b, j++);
}
in.read();
int spent = 0;
b = in.read();
int b2;
while ((b2 = in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b) - map.get(b2));
b = b2;
}
System.out.println(spent);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | a5b8f4130a512d0b150ed2f113d3fd56 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
public class MainClass {
public static void main(String[] args) throws IOException {
InputStream in = System.in;
HashMap<Character, Integer> map = new HashMap<>();
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
for (int i = 0; i < loop; i++) {
int b3;
int j = 0;
while ((b3 = in.read()) != 13) {
map.put((char) b3, j++);
}
in.read();
int spent = 0;
char b1 = (char) in.read();
char b2;
while ((b2 = (char) in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b1) - map.get(b2));
b1 = b2;
}
System.out.println(spent);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 11db4be358a1ee0bd8ecaf895b19f6ea | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
public class MainClass {
static InputStream in = System.in;
static HashMap<Character, Integer> map = new HashMap<>();
public static void main(String[] args) throws IOException {
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
for (int i = 0; i < loop; i++) {
int b3;
int j = 0;
while ((b3 = in.read()) != 13) {
map.put((char) b3, j++);
}
in.read();
int spent = 0;
char b1 = (char) in.read();
char b2;
while ((b2 = (char) in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b1) - map.get(b2));
b1 = b2;
}
System.out.println(spent);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 7c0f430fdd507384aad7e45e570bf444 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
public class MainClass {
static InputStream in = System.in;
public static void main(String[] args) throws IOException {
HashMap<Character, Integer> map = new HashMap<>();
int loop = 0;
int b;
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
for (int i = 0; i < loop; i++) {
int b3;
int j = 0;
while ((b3 = in.read()) != 13) {
map.put((char) b3, j++);
}
in.read();
int spent = 0;
char b1 = (char) in.read();
char b2;
while ((b2 = (char) in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b1) - map.get(b2));
b1 = b2;
}
System.out.println(spent);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 936a2753ca7f082d7448fdb06621e121 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
public class MainClass {
static InputStream in = System.in;
public static void main(String[] args) throws IOException {
HashMap<Character, Integer> map = new HashMap<>();
int loop = 0;
int b;
while (in.available() < 0) {
}
while ((b = in.read()) != 13) {
loop *= 10;
loop += b - 48;
}
in.read();
for (int i = 0; i < loop; i++) {
int b3;
int j = 0;
while ((b3 = in.read()) != 13) {
map.put((char) b3, j++);
}
in.read();
int spent = 0;
char b1 = (char) in.read();
char b2;
while (in.available() > 0 && (b2 = (char) in.read()) != '\n' && b2 != 13) {
spent += Math.abs(map.get(b1) - map.get(b2));
b1 = b2;
}
System.out.println(spent);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | e875c209e276354dcc7de4b950c0f6c6 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class A{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t= sc.nextInt();
sc.nextLine();
while(t-->0){
char[] c = sc.nextLine().toCharArray();
char[] c2 = sc.nextLine().toCharArray();
int[] pos = new int[26];
// System.out.println(c);
// System.out.println(c2);
for (int i = 0; i < 26; i++) pos[c[i]-'a'] = i;
int ans = 0;
for (int i = 0; i < c2.length-1; i++) {
ans += Math.abs(pos[c2[i]-'a']-pos[c2[i+1]-'a']);
}
System.out.println(ans);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | b2c1defa9e7d8856853deba275c3cc2a | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
public class main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
while(T--!=0){
String alph =sc.next();
String s =sc.next();
int sum=0;
for(int i=1; i<s.length(); i++){
sum+=Math.abs(alph.indexOf(s.charAt(i))-alph.indexOf(s.charAt(i-1)));
}
System.out.println(sum);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | d80c2582103cf6eebff059bb0e7f2a09 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class BitClass {
public static void main(String [] args) throws NumberFormatException, IOException {
Scanner sc = new Scanner(System.in);
int len = sc.nextInt();
while(len > 0) {
String s = sc.next();
String find = sc.next();
int sum = 0;
int [] arr = new int[find.length()];
for(int i = 0;i < find.length(); i++) {
arr[i] = s.indexOf(find.charAt(i)) + 1;
}
if(arr.length > 1) {
int num = findAbsSum(arr,arr.length);
sum = sum + num;
System.out.print(sum);
System.out.println();
} else
System.out.println("0");
len--;
}
}
static int findAbsSum(int arr[],int k) {
int sum =0;
for(int i = 0 ;i< k -1 ;i++) {
sum = sum + Math.abs(arr[i+1] - arr[i]);
}
return sum;
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 14e63c463e57069afb519c1a757d4624 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class TaskA {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
scanner.nextLine();
for (int j=0; j<t; j++){
String s1 = scanner.nextLine();
String s2 = scanner.nextLine();
List<Integer> list = new ArrayList<>();
int index = 0;
int i=0;
while (i<26) {
if (s2.charAt(index) == s1.charAt(i)){
list.add(i+1);
index++;
i=0;
}else {
i++;
}
if (index== s2.length()){
break;
}
}
int res = 0;
for (int k=0; k<list.size()-1; k++){
res += Math.abs(list.get(k+1) - list.get(k));
}
System.out.println(res);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 2c43fc955bd7a07c84ee5ba592343a43 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class Solution {
int[]result1(int n,String q[],String q1[]){
int []result=new int[n];
int sum=1;
int sum1=0;
for(int i=0;i<n;i++){
char[]q2=q[i].toCharArray();
char[]q3=q1[i].toCharArray();
for(int k=0;k<q3.length;k++){
for (int j=0;j<26;j++){
if(q2[j]==q3[k]){
sum1=sum;
sum=j+1;
if(k>0) {
sum1 = sum - sum1;
if (sum1 < 0) {
sum1 = -sum1;
}
result[i] += sum1;
// System.out.println(result[i] + "第" + k + "ci");
}
}
}
}
}
// System.out.println(result[0]);
for (int i=0;i<n;i++){
System.out.println(result[i]);
}
return result;
}
public static void main(String[] args) {
// int n=5;
//
// String []q={"abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopqrstuvwxyz","qwertyuiopasdfghjklzxcvbnm","qwertyuiopasdfghjklzxcvbnm"};
// String []q1={"hello","i","codeforces","qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq","abacaba"};
Scanner scanner=new Scanner(System.in);
int n= scanner.nextInt();
String []q=new String[n];
String []q1=new String[n];
for (int i=0;i<n;i++){
q[i]=scanner.next();
q1[i]=scanner.next();
}
Solution s= new Solution();
s.result1(n,q,q1);
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | ee356fc0aee1c60b0097d8c7c2824dfb | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
import java.util.ArrayList;
public class LinearKeyboard {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int p = 0; p < t; p++) {
String s = sc.next(), s1 = sc.next();
int y = 0, k = 0;
List<Integer> list = new ArrayList<>();
for (int j = 0; j < s1.length(); j++) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == s1.charAt(j)) {
list.add(i+1);
break;
}
}
}
for (int i = 0; i < list.size()-1; i++) {
k = list.get(i) - list.get(i + 1);
y += Math.abs(k);
}
System.out.println(y);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 731352c621fdc5d437433ae7d87b7701 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
import java.util.ArrayList;
public class LinearKeyboard {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int p = 0; p < t; p++) {
String s = sc.next(), s1 = sc.next();
int y = 0, k = 0;
List<Integer> list = new ArrayList<>();
for (int j = 0; j < s1.length(); j++) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == s1.charAt(j)) {
list.add(i+1);
}
}
}
for (int i = 0; i < list.size()-1; i++) {
k = list.get(i) - list.get(i + 1);
y += Math.abs(k);
}
System.out.println(y);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | b635fbbad65b6d8396610d8e6cbdb5df | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | /******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main(String[] args) {
ArrayList<Integer> arr= new ArrayList<>();
Scanner sc = new Scanner(System.in);
int test_case= sc.nextInt();
HashMap<String, Integer> map= new HashMap<>();
int distance;
for(int i=0;i<test_case;i++)
{ distance=0;
String alphabet= sc.next();
String value="";
for(int j=0;j<26;j++)
{ value=alphabet.substring(j,j+1);
map.put(value,j+1);
}
String input= sc.next();
if(input.length()==1)
{
distance=0;
}
else{
int previous_element=0;
int current_element=0;
previous_element=map.get(input.substring(0,1));
// System.out.println(previous_element);
for(int k=1;k<input.length();k++ )
{
current_element=map.get(input.substring(k,k+1));
if(previous_element==current_element)
{
distance+=0;
previous_element=current_element;
}
else{
distance+=Math.abs(previous_element-current_element);
previous_element=current_element;
}
}
}
// System.out.println(distance);
arr.add(distance);
// break;
}
for(int i : arr)
{
System.out.println(i);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 8d8a80f83bac6f01f8fb4a5388a02276 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
public class CodeforcesTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testcases = sc.nextInt();
for(int t=0;t<testcases;t++) {
String s = sc.next();
String word = sc.next();
int ans = linearKeyboard(s, word);
System.out.println(ans);
}
sc.close();
}
public static int linearKeyboard(String s, String word) {
HashMap<Character, Integer> map = new HashMap<Character, Integer>();
int index = 1;
for (int i = 0; i < s.length(); i++) {
map.put(s.charAt(i), index);
index++;
}
int time = 0;
for (int i = 1; i < word.length(); i++) {
int first = map.get(word.charAt(i - 1));
int second = map.get(word.charAt(i));
time += (Math.abs(first - second));
}
return time;
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 0b18eff2a012ec771946403f6838cf4c | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[]args) {
Scanner sc = new Scanner(System.in);
int tests = sc.nextInt();
for(int t = 0; t < tests; t++) {
String alp = sc.next();
String s = sc.next();
int steps = 0;
for(int i = 0; i < (s.length() - 1); i++) {
char a = s.charAt(i);
char b = s.charAt(i+1);
int pos1 = alp.indexOf(a);
int pos2 = alp.indexOf(b);
steps += Math.abs(pos2 - pos1);
}
System.out.println(steps);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | fcf7f9131eff4671178485e3b144c54b | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class LinearKeyboard {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
while (t-- > 0) {
int res = 0;
String k = sc.nextLine();
String w = sc.nextLine();
int[] arr = new int[130];
for (int i = 0; i < 26; i++) {
int temp = k.charAt(i);
arr[temp] = i;
}
for (int i = 1; i < w.length(); i++) {
res += Math.abs(arr[w.charAt(i)] - arr[w.charAt(i-1)]);
}
System.out.println(res);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 0e22b0e58865b33456f0e9f10aab5601 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
in.nextLine();
while (t-->0) {
String str1 = in.nextLine();
String str2 = in.nextLine();
int sum ;
int res = 0;
for (int i = 0; i < str2.length() - 1; i++) {
sum = Math.abs(str1.indexOf(str2.charAt(i)) - str1.indexOf(str2.charAt(i+1)));
res += sum;
}
System.out.println(res);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | daf768d553762a53b3251e6ba3a94e31 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes |
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import javax.management.RuntimeErrorException;
public class CodeforcesQuestions {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t-->0)
{
String s1=s.next();
String ans=s.next();
int a=0;
if(ans.length()==1 || ans.length()==0)
{
System.out.println("0");
continue;
}
for(int i=1;i<ans.length();i++)
{
//System.out.println(s1.indexOf(ans.charAt(i-1)));
a=a+Math.abs(s1.indexOf(ans.charAt(i-1)) - s1.indexOf(ans.charAt(i)));
//System.out.println(a);
}
System.out.println(a);
}
// Scanner s=new Scanner(System.in);
// int t=s.nextInt();
//
// while(t-->0)
// {
// long max=Integer.MIN_VALUE;
// String s1=s.next();
// int n=s1.length();
//
// for(int i=0;i<n-1;i++)
// {
// int a=s1.charAt(i)-'0'+s1.charAt(i+1)-'0';
// String a1=Integer.toString(a);
// //System.out.println("a1 "+a1 );
// String s2="";
// if(i+2<n)
// {
// s2=s1.substring(0,i)+a1+s1.substring(i+2);
// //System.out.println("s2 is equall to"+s2);
// }
// else
// {
// s2=s1.substring(0,i)+a1;
// //System.out.println("s2 is equall to"+s2);
// }
// System.out.println("5433454");
// long ans=Integer.parseInt(s2);
// System.out.println(ans);
// int m=s2.length()-1;
//// int ans=0;
//// for(int j=0;j<s2.length();j++)
//// {
//// System.out.println(s2.charAt(i)-'0');
//// ans=ans+(int)(s2.charAt(i)-'0')*(int)Math.pow(10, m-i);
//// System.out.println("ans "+ ans);
//// }
//
// //System.out.println(ans);
// if(ans>max)
// max=ans;
//
// }
//
// System.out.println(max);
//
//
// }
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 2352771224881c81b8f60bddce1817c9 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Problem_1607A {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
Map<Character, Integer> map = new HashMap<>();
for (int i = 0; i < t; i++) {
char[] keys = scanner.next().toCharArray();
for (int j = 0; j < keys.length; j++) {
map.put(keys[j], j);
}
char[] characters = scanner.next().toCharArray();
int ans = 0;
for (int j = 1; j < characters.length; j++) {
ans += Math.abs(map.get(characters[j]) - map.get(characters[j-1]));
}
System.out.println(ans);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 9ae87160e10603174e4a6ee82bc0f5b3 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Problem_1607A {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
String keyboard, word;
Map<Character, Integer> map = new HashMap<>();
int distance;
while (n-- > 0) {
keyboard = scanner.next();
for (int i = 0; i < 26; i++) {
map.put(keyboard.charAt(i), i);
}
word = scanner.next();
distance = 0;
for (int i = 1; i < word.length(); i++) {
distance += Math.abs(map.get(word.charAt(i)) - map.get(word.charAt(i - 1)));
}
System.out.println(distance);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 9291b9595d85c3ad8ac620e0019ba1eb | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while (t != 0) {
String alphaOrder = in.next();
String word = in.next();
int time = 0;
for(int i = 0; i < word.length()-1; i ++) {
time += Math.abs(alphaOrder.indexOf(word.charAt(i)) - alphaOrder.indexOf(word.charAt(i+1)));
}
System.out.println(time);
t--;
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | d75fd8928c672b91aaa3f5ea7146c2bf | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String[] args){
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-->0){
String str = scn.next();
String s = scn.next();
if(s.length()<=1){
System.out.println(0);
continue;
}
Map<Character,Integer> map = new HashMap<>();
for(int i=0;i<str.length();i++){
char c= str.charAt(i);
map.put(c,i+1);
}
char last = s.charAt(0);
int ans=0;
// System.out.println(str);
// System.out.println(s);
// System.out.println(map);
for(int i=1;i<s.length();i++){
char c= s.charAt(i);
int d = Math.abs(map.get(c)-map.get(last));
ans+=d;
last =c;
}
System.out.println(ans);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 1ad80cdbc7bb0f5eb1e262a771066b27 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Stack;
public class Solution {
// static int ans=0;
static int[] nodeColors;
static boolean[] visited;
static String[][] neighborstring;
static List<Integer>[] startIndices;
static int[] edgesToPrint;
static int mod=998244353;
static int[] parents;
static HashSet<Integer> cycleSet;
static PriorityQueue<Integer> [] neighborPriority;
static int [] minPointsToEnterRoom;
static int [] maxPointsToEnterRoom;
static int [] pointOfEachRoom;
static List<Integer>[] neighbors;
static int[][] memo;
public static void main(String[] args) throws IOException {
// BufferedReader bufferedReader = new BufferedReader(new FileReader("./input.txt") );
//
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in) );
int tests= Integer.parseInt(bufferedReader.readLine());
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < tests; i++) {
String board = bufferedReader.readLine();
String word = bufferedReader.readLine();
int [] cache = new int[26];
for (int j = 0; j < board.length(); j++) {
char c = board.charAt(j);
cache[ c - 'a'] = j;
}
int ans =0;
int start = cache [word.charAt(0) - 'a'];
for (int j = 1; j < word.length(); j++) {
int current = cache [word.charAt(j) - 'a'];
ans += Math.abs( start - current );
start = current;
}
stringBuilder.append(ans +"\n");
}
System.out.println(stringBuilder.toString());}} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 8752b1528061997af20244aedd33080b | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class LinearKeyboard {
static final int MAXN = 26;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int TC = Integer.parseInt(br.readLine());
while (TC-- > 0) {
String keyboard = br.readLine();
int[] indexes = new int[MAXN];
for (int i = 0; i < MAXN; ++i) {
int j = getIndex(keyboard.charAt(i));
indexes[j] = i;
}
String word = br.readLine();
int time = 0;
for (int i = 1; i < word.length(); ++i)
time += Math.abs(
indexes[getIndex(word.charAt(i-1))] - indexes[getIndex(word.charAt(i))]);
pw.println(time);
}
pw.close();
}
static int getIndex(char ch) {
return ch - 'a';
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | b8f23ef546079e76248e5a84caf71382 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
public final class Practice {
public static void main(String[] args) throws Exception {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
sc.nextLine();
while(t-->0) {
String keys=sc.nextLine();
String s=sc.nextLine();
HashMap<Character,Integer>hm=new HashMap<Character,Integer>();
int kl=keys.length(),sl=s.length();
for(int i=0;i<kl;i++) {
hm.put(keys.charAt(i), i+1);
}
int res=0;
for(int i=1;i<sl;i++) {
res+=(Math.abs(hm.get(s.charAt(i))-hm.get(s.charAt(i-1))));
}
System.out.println(res);
// System.out.println("hey");
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | caf58b596ea5913616c8dde2442004d4 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class CodeForces {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
while(t-- > 0){
String keyBoard = sc.nextLine();
String word = sc.nextLine();
int cost=0, prevIndex=keyBoard.indexOf(word.charAt(0));
for(int i=1; i<word.length(); i++){
char c = word.charAt(i);
cost= cost + Math.abs(keyBoard.indexOf(c)-prevIndex);
prevIndex = keyBoard.indexOf(c);
}
System.out.println(cost);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | a6b58a31077f818048c990ffc4aadcd6 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int j=0; j<T; j++){
String a=sc.next();
String s=sc.next();
int n=s.length();
int ans=0;
for(int i=0; i<n-1; i++){
char c1=s.charAt(i);
char c2=s.charAt(i+1);
int p1=a.indexOf(c1);
int p2=a.indexOf(c2);
int d=Math.abs(p2-p1);
ans+=d;
}
System.out.println(ans);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 70fb3c726bf03700f739331ac5a7dd23 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes |
import static java.lang.Math.abs;
import java.util.Scanner;
/**
*
* @author HP
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input=new Scanner(System.in);
int t=input.nextInt();
for(int tt=0;tt<t;tt++){
String string =input.next();
String str=input.next();
int s=string.indexOf(str.charAt(0));
int ans=0;
for(int i=1;i<str.length();i++){
int e=string.indexOf(str.charAt(i));
ans+=abs(s-e);
s=e;
}
System.out.println(ans);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 69ae245058c87887b017511e3878dfb5 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef {
private static int solve(int n, String dict, String str) {
HashMap<Character,Integer> map = new HashMap<>();
for (int i=0; i<26; i++){
map.put(dict.charAt(i),i+1);
}
int ans = 0;
for (int i = 1; i < n; i++) {
ans += Math.abs(map.get(str.charAt(i-1))-map.get(str.charAt(i)));
}
return ans;
}
public static void main (String[] args) throws java.lang.Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(reader.readLine());
while (t-- > 0) {
//String[] firstLine = reader.readLine().split(" ");
//int n = Integer.parseInt(firstLine[0]);
// int[] arr = convertToIntArray(reader.readLine().split(" "));
String dict = reader.readLine();
String str = reader.readLine();
int n = str.length();
int ans = solve(n, dict, str);
System.out.println(ans);
}
}
public static int[] convertToIntArray(String[] str) {
int[] arr = new int[str.length];
for(int i = 0; i < str.length; i++) {
arr[i] = Integer.parseInt(str[i]);
}
return arr;
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | e6af989d211f9c2f0fd9a65ccd5af09a | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
public class linA {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int ans = 0;
String answer = "";
for (int i = 0; i < a; i++) {
String alphabet = in.next();
String s = in.next();
int l = 0;
ans = 0;
int[] arr = new int[26];
for (int j = 0; j < alphabet.length(); j++) {
arr[alphabet.charAt(j) - 'a'] = j;
}
for (int q = 0; q < s.length() - 1; q++) {
ans += Math.abs((arr[s.charAt(q) - 'a']) - (arr[s.charAt(q + 1) - 'a']));
}
answer += Integer.toString(ans) + "\n";
}
System.out.print(answer);
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | c7a427a3e56f29678d65000f745e11f8 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testCaseNumber = Integer.valueOf(scanner.nextLine());
while(testCaseNumber-- > 0) {
int answer = 0;
String sourceString = scanner.nextLine();
String targetString = scanner.nextLine();
char[] sourceChars = sourceString.toCharArray();
char[] targetChars = targetString.toCharArray();
int[] sourceMap = new int[26];
for (int i = 0; i < sourceChars.length; i++) {
sourceMap[sourceChars[i] - 'a'] = i;
}
int preIndex = -1;
for (int i = 0; i < targetChars.length; i++) {
int curIndex = sourceMap[targetChars[i] - 'a'];
if(preIndex == -1)
preIndex = curIndex;
answer += Math.abs(curIndex - preIndex);
preIndex = curIndex;
}
System.out.println(answer);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 40bb741e0faa30274e65f3735504284f | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.*;
public class A {
public static FastScanner sc;
public static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void solve(int t) {
String s=sc.next();
String s2=sc.next();
HashMap<Character,Integer> hm = new HashMap<>();
for(int i=0;i<s.length();i++) {
hm.put(s.charAt(i),i);
}
long ans=0;
for(int i=1;i<s2.length();i++) {
ans+=Math.abs( hm.get(s2.charAt(i))-hm.get(s2.charAt(i-1)) );
}
System.out.println(ans);
}
public static void main(String[] args) {
sc = new FastScanner();
int t=sc.nextInt();
for(int i=1;i<=t;i++) solve(i);
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 0b105c2d0c9f999ab9a5e856028091e6 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class keyboard {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int test_cases = sc.nextInt();
while(2 * test_cases-- > 0){
String keyboard = sc.next();
String word = sc.next();
int steps = 0 ;
for (int i = 0; i < word.length()-1; i++) {
char CURRENTLETTER = word.charAt(i);
char NEXTLETTER= word.charAt(i + 1);
int C1 = keyboard.indexOf(CURRENTLETTER);
int C2 = keyboard.indexOf(NEXTLETTER);
steps = steps + Math.abs(C1- C2);
}
System.out.println(steps);
}
sc.close();
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 7641e42f9c3e260fd991843c86354c7a | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-- > 0){
String l=sc.next();
String s=sc.next();
// System. out. println(l);
Map<Character, Integer> m=new HashMap<>();
for(int i=0; i<l.length(); i++){
int x=i;
m.put(l.charAt(i),x+1);
}
int sum=0;
for(int i=1; i<s.length(); i++){
int x=m.get(s.charAt(i-1));
int y=m.get(s.charAt(i));
sum=sum+Math.abs(y-x);
}
System.out.println(sum);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 7726464fc160dc1016b71c3beaa43bb9 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class codeforcesA{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static int gcd(int a,int b){if(b==0){return a;}return gcd(b,a%b);}
public static void main(String args[]){
FastReader sc=new FastReader();
int t=sc.nextInt();
while(t-->0){
StringBuilder sb=new StringBuilder();
String s=sc.nextLine();
String s1=sc.nextLine();
int ar[]=new int[26];
for(int i=0;i<26;i++){ar[s.charAt(i)-'a']=i;}
int ini=ar[s1.charAt(0)-'a'];
long ans=0;
for(int i=0;i<s1.length();i++){
ans+=Math.abs(ini-ar[s1.charAt(i)-'a']);ini=ar[s1.charAt(i)-'a'];
}
System.out.println(ans);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | ad2d17135c94a1581c073cbd740f635c | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
public class esep
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
while(n-->0)
{
String s = sc.nextLine();
String q = sc.nextLine();
long res = 0;
for(int i = 1; i < q.length() ; ++i)
{
res += Math.abs(s.indexOf(q.charAt(i))-s.indexOf(q.charAt(i-1)));
}
System.out.println(res);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 6020d59087cd7c4e84277b36a2c2dccd | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
public class esep
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
while(n-->0)
{
String s = sc.nextLine();
ArrayList<Character> list = new ArrayList<>();
for(Character i : s.toCharArray())
{
list.add(i);
}
String q = sc.nextLine();
long res = 0;
for(int i = 1; i < q.length() ; ++i)
{
res += Math.abs(list.indexOf(q.charAt(i))-list.indexOf(q.charAt(i-1)));
}
System.out.println(res);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 0dd7946bd74e4b4dc6c8def415c9bde3 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes |
import java.util.Hashtable;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int t;
t=input.nextInt();
Hashtable<Character,Integer>map=new Hashtable<>();
while (t-- >0) {
String characters = input.next();
for (int i = 0; i < 26; i++) {
map.put(characters.charAt(i),i);
}
String word = input.next();
int sum = 0;
for (int i = 0; i < word.length(); i++) {
if (i + 1 < word.length()) sum += Math.abs(map.get(word.charAt(i)) - map.get(word.charAt(i + 1)));
}
System.out.println(sum);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 2e05920082cb35a530fbed6dcdd6e675 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | /********
* @author Brennan Cox
*
********/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public Main() {
FastScanner input = new FastScanner(System.in);
StringBuilder output = new StringBuilder();
int t = input.nextInt();
for (int i = 0; i < t; i++) {
char[] arr = input.next().toCharArray();
//Create a keyboard that acts as a hashmap from char -> int
int[] keyboard = new int[26];
for (int j = 0; j < keyboard.length; j++) {
//this character is in position j
keyboard[arr[j] - 'a'] = j;
}
//make= the string to be made
char[] make = input.next().toCharArray();
int time = 0;
//initial has no effect on time
int at = keyboard[make[0] - 'a'];
for (int j = 1; j < make.length; j++) {
//get the position of char
int nextAt = keyboard[make[j] - 'a'];
//get difference of positions
time+= Math.abs(at - nextAt);
at = nextAt;
}
output.append(time + "\n");
}
System.out.println(output);
}
public static void main(String[] args) {
new Main();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(Reader in) {
br = new BufferedReader(in);
}
public FastScanner(InputStream in) {
this(new InputStreamReader(in));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() { return Double.parseDouble(next());}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 15104ab5853102e6a2e1fcfb42be119a | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | /********
* @author Brennan Cox
*
********/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public Main() {
FastScanner input = new FastScanner(System.in);
StringBuilder output = new StringBuilder();
int t = input.nextInt();
for (int i = 0; i < t; i++) {
char[] arr = input.next().toCharArray();
int[] keyboard = new int[26];
for (int j = 0; j < keyboard.length; j++) {
keyboard[arr[j] - 'a'] = j;
}
char[] make = input.next().toCharArray();
int time = 0;
int at = keyboard[make[0] - 'a'];
for (int j = 1; j < make.length; j++) {
int nextAt = keyboard[make[j] - 'a'];
time+= Math.abs(at - nextAt);
at = nextAt;
}
output.append(time + "\n");
}
System.out.println(output);
}
public static void main(String[] args) {
new Main();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(Reader in) {
br = new BufferedReader(in);
}
public FastScanner(InputStream in) {
this(new InputStreamReader(in));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() { return Double.parseDouble(next());}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 39deef15b4c69ac52a19b9c840f60548 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes |
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t!=0) {
String keyboard = s.next();
String word = s.next();
int frequency[] = new int[256];
for(int i = 0; i<26;i++) {
frequency[keyboard.charAt(i)] = i + 1;
}
int ans = 0;
for(int i = 0; i<word.length() - 1; i++) {
ans = ans + Math.abs(frequency[word.charAt(i + 1)] - frequency[word.charAt(i)]);
}
System.out.println(ans);
t--;
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 0646a9e7560428052803a1ffac9927df | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Board {
public static void main(String[] args) {
FastReader f = new FastReader();
int x = f.nextInt();
for (int i = 0; i < x; i++) {
char[] alphabet = f.next().toCharArray();
char[] key = f.next().toCharArray();
Map<Integer, Character> b = new TreeMap<>();
for (int j = 0; j < 26; j++) {
b.put(j, alphabet[j]);
}
int sum = 0;
int current = 0;
int previous = 0;
int pomni = 0;
for (int j = 0; j < key.length; j++) {
for (Map.Entry<Integer, Character> e: b.entrySet()) {
if (key[j] == e.getValue()){
current = e.getKey();
sum += Math.abs(current - previous);
previous = e.getKey();
}
if (key[0] == e.getValue()){
pomni = e.getKey();
}
}
}
sum -= pomni;
System.out.println(sum);
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | e20b95827e6a9b16ae3cf66bc0756921 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Solution
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int t= Integer.parseInt(br.readLine());
while(t-->0){
String str1 = new String(br.readLine());
String str2 = new String(br.readLine());
char ch1[]=str1.toCharArray();
char ch2[]=str2.toCharArray();
HashMap<Character,Integer> ar=new HashMap<>();
for(int i=0;i<str1.length();i++){
ar.put(ch1[i],i+1);
}
int s=0;
for(int i=0;i<str2.length()-1;i++){
s+=Math.abs(ar.get(ch2[i])-ar.get(ch2[i+1]));
}
bw.write(s+"\n");
}
br.close();
bw.close();
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | f5644b9bc4a2e0d1ffeb680379f369ef | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String o = in.nextLine();
int n = Integer.parseInt(o);
for (int k = 0; k < n; k++) {
ArrayList<Integer> idx = new ArrayList<Integer>();
String s = in.nextLine();
String c = in.nextLine();
for (int i = 0; i < c.length(); i++) {
idx.add(s.indexOf(c.charAt(i)));
}
int sum = 0;
for (int i = 1; i < idx.size(); i++) {
sum += Math.abs(idx.get(i - 1) - idx.get(i));
}
System.out.println(sum);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | abbcfd4da6d99e9e173621317540c177 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
public class LinearKeyboard {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while (t-->0){
String s=sc.next();
String s1=sc.next();
HashMap<Character,Integer>map=new HashMap<>();
for(int i=0;i<s.length();i++){
map.put(s.charAt(i),i);
}
int count =0;
for(int i=0;i<s1.length()-1;i++){
int x=map.get(s1.charAt(i+1));
int y=map.get(s1.charAt(i));
count +=Math.abs((x-y));
}
System.out.println(count);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 6cf2a98815eff2e12d4265b1b22621cb | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.LinkedList;
import java.util.*;
import java.util.StringTokenizer;
public class C {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader s=new FastReader();
int n=s.nextInt();
while(n-->0){
String R=s.next();
char d[]=R.toCharArray();
int A[]=new int[26];
for(int i=0;i<26;i++){
A[(int)d[i]-97]=i;;
}
String S=s.next();
char q[]=S.toCharArray();
int ans=0;
for(int i=0;i<q.length-1;i++){
ans+=(int)Math.abs(A[(int)q[i]-97]-A[(int)q[i+1]-97]);
}
System.out.println(ans+"");
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 8203ec826d6d7de8e6dbf5af070a662c | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.LinkedList;
import java.util.*;
import java.util.StringTokenizer;
public class C {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader s=new FastReader();
int n=s.nextInt();
while(n-->0){
String R=s.next();
char d[]=R.toCharArray();
int A[]=new int[26];
for(int i=0;i<26;i++){
A[(int)d[i]-97]=i;;
}
String S=s.next();
char q[]=S.toCharArray();
int ans=0;
for(int i=0;i<q.length-1;i++){
ans+=(int)Math.abs(A[(int)q[i]-97]-A[(int)q[i+1]-97]);
}
System.out.println(ans);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 3ed72706a4e2d6bc896970060420a2ac | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class Linear
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int test=sc.nextInt();
sc.nextLine();
while(test>0)
{
String s=sc.nextLine();
String p=sc.nextLine();
HashMap<Character,Integer> map=new HashMap<Character,Integer>();
for(int i=0; i<=25; i++)
{
map.put(s.charAt(i),i);
}
//System.out.println(map);
int ans=0;
for(int i=1; i<p.length(); i++)
{
ans=ans+Math.abs(map.get(p.charAt(i-1))-map.get(p.charAt(i)));
}
System.out.println(ans);
test--;
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | f94f7a48b61ca551e6e5bf9f7595257a | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class LinearKeyBoard {
public static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int tc = scanner.nextInt();
while (tc-->0){
String keyType = scanner.next();
String string= scanner.next();
int ans = 0;
if (keyType.equals("abcdefghijklmnopqrstuvwxyz")) {
for (int i = 0; i < string.length(); i++) {
for (int j = i; j < string.length() - 1; j++) {
ans = ans + (int) (Math.abs(string.charAt(j + 1) - string.charAt(j)));
break;
}
}
}else {
// char[] array = keyType.toCharArray();
// ArrayList<Integer> list = new ArrayList<>();
// for (int i =0;i<50;i++) {
// for (int j = 0; j < keyType.length(); j++) {
// if (array[i] == string.charAt(i)){
// list.add(j);
// break;
// }
// }
// }
// System.out.println(list);
// for (int i =0;i< list.size()-1;i++){
// ans = ans + Math.abs(list.get(i+1)- list.get(i));
// }
// }
for (int i =0;i<string.length()-1;i++){
ans = ans + Math.abs(keyType.indexOf(string.charAt(i+1))- keyType.indexOf(string.charAt(i)));
}
}
System.out.println(ans);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 2fe3c00808e979c11964c027a45fbf21 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class Main{
public static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int tc = scanner.nextInt();
while (tc-->0){
String keyType = scanner.next();
scanner.nextLine();
String string= scanner.next();
int ans = 0;
if (keyType.equals("abcdefghijklmnopqrstuvwxyz")) {
for (int i = 0; i < string.length(); i++) {
for (int j = i; j < string.length() - 1; j++) {
ans = ans + (int) (Math.abs(string.charAt(j + 1) - string.charAt(j)));
break;
}
}
}else {
int [] array = new int[keyType.length()];
for (int i =0;i<keyType.length();i++){
array[keyType.charAt(i)-'a']=i;
}
for (int i = 0; i < string.length()-1; i++) {
ans = ans + Math.abs(array[string.charAt(i+1)-'a']- array[string.charAt(i)-'a']);
}
}
System.out.println(ans);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | de2aecb1db5b504ad27a0839ef712fe5 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | /*
stream Butter!
eggyHide eggyVengeance
I need U
xiao rerun when
*/
import static java.lang.Math.*;
import java.util.*;
import java.io.*;
import java.math.*;
public class x1607A
{
public static void main(String hi[]) throws Exception
{
BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(infile.readLine());
int T = Integer.parseInt(st.nextToken());
StringBuilder sb = new StringBuilder();
while(T-->0)
{
char[] line = infile.readLine().toCharArray();
int[] loc = new int[26];
for(int i=0; i < 26; i++)
loc[line[i]-'a'] = i;
char[] arr = infile.readLine().toCharArray();
int res = 0;
for(int i=1; i < arr.length; i++)
res += abs(loc[arr[i]-'a']-loc[arr[i-1]-'a']);
sb.append(res+"\n");
}
System.out.print(sb);
}
public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception
{
int[] arr = new int[N];
st = new StringTokenizer(infile.readLine());
for(int i=0; i < N; i++)
arr[i] = Integer.parseInt(st.nextToken());
return arr;
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 800e7d5ac28419226749e50fe8fe5a16 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class poblem1607
{
static Scanner sc = new Scanner(System.in);
public static void main(String[] args)
{
int t = sc.nextInt();
sc.nextLine();
//~ sc.dfnextLine();
for(int i = 0; i < t; i++)
{
solve();
}
}
public static void solve()
{
int tot = 0;
String str2 = sc.nextLine();
List<Character> alb = new ArrayList<Character>();
alb.add('0');
for(int i = 0; i < str2.length(); i++)
alb.add(str2.charAt(i));
String str = sc.nextLine();
int f = alb.indexOf(str.charAt(0));
for(int i = 1; i < str.length(); i++)
{
int s = alb.indexOf(str.charAt(i));
tot += Math.abs(s-f);
f = s;
}
System.out.println(tot);
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 54ce16801001f9887446762d002d86fc | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class poblem1607
{
static Scanner sc = new Scanner(System.in);
public static void main(String[] args)
{
int t = sc.nextInt();
sc.nextLine();
for(int i = 0; i < t; i++)
{
solve();
}
}
public static void solve()
{
int tot = 0;
String str = sc.nextLine();
String str1 = sc.nextLine();
for(int i = 0 ; i < str1.length()-1; i++)
{
String tp = "",tp2 = "";
tp += str1.charAt(i);
tp2 += str1.charAt(i+1);
if(str.contains(tp))
{
tot += Math.abs((str.indexOf(tp)+1)-(str.indexOf(tp2)+1));
}
}
System.out.println(tot);
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | ddbd2fdddf8a34669a5b9c8e0563a0ee | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class hm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
String a = sc.next();
String s = sc.next();
int cost = 0;
for(int i = 0; i < s.length()-1;i++) {
cost += Math.abs(a.indexOf(s.charAt(i)) - a.indexOf(s.charAt(i+1)));
}
System.out.println(cost);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 78a946230261202e9535acc59e444121 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class Main {
public static int get(String str, String str1){
int sum = 0;
int[] pos = new int[30];
char[] ch = str.toCharArray();
for(int i = 0; i < 26; i++){
pos[(int)ch[i]-'a'] = i;
}
char[] ch2 = str1.toCharArray();
int num = pos[(int)ch2[0]-'a'];
for(int i = 0; i < ch2.length; i++){
sum += cut(num,pos[(int)ch2[i]-'a']);
num = pos[(int)ch2[i]-'a'];
}
return sum;
}
public static int cut(int x, int y){
if (x >= y) return x-y;
else return y-x;
}
public static void main (String[] args){
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(true){
if (t == 0) break;
t --;
String s = scan.next();
String s1 = scan.next();
int ans = get(s,s1);
System.out.println(ans);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 83e6650eba5937f72ff484709f797e14 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes |
import java.util.*;
public class contest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0){
t--;
String format = sc.next(),
str = sc.next();
int prev=0;
for(int i=0;i<26;i++){
if(format.charAt(i)==str.charAt(0)){
prev = i;
break;
}
}
int ans=0;
for(int i=1;i<str.length();i++){
for(int j=0;j<26;j++){
if(str.charAt(i) == format.charAt(j)){
ans+= Math.abs(j-prev);
prev=j;
break;
}
}
}
System.out.println(ans);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | c3c6d0c1321282967d2c8104d72a5f9e | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | //package round753;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
//import round748.A.FastReader;
public class A {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader sc = new FastReader();
int t = sc.nextInt();
for(int i = 1;i<=t;i++) {
String s1 = sc.nextLine(); // keyboard
String s2 = sc.nextLine(); // word
int a = s1.indexOf(s2.charAt(0)) + 1;
int ans = 0;
for(int j = 1;j<s2.length();j++) {
ans+=Math.abs((s1.indexOf(s2.charAt(j))+1)-a);
a = s1.indexOf(s2.charAt(j)) + 1;
}
System.out.println(ans);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 4b6cc46418dce7900dc3cefe37f55d71 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class TaskA {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
private void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
for(int i=0;i<n;i++){
int res=0;
String keyBoard=in.next();
String s=in.next();
for(int k=0;k<s.length()-1;k++){
res+=Math.abs((keyBoard.indexOf(s.charAt(k))+1) -(keyBoard.indexOf(s.charAt(k+1))+1));
}
out.println(res);
}
out.flush();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 96048e16a3aefc6779b55d930157c910 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | //package div3_753;
import java.util.HashMap;
import java.util.Scanner;
public class LinearKeyboard_A {
protected int time(String keyboard,String key) {
if(key.length()<=1)
return 0;
// HashMap<Character,Integer> keyMap=new HashMap<>();
int res=0;
// for(int i=0;i<keyboard.length();i++)
// keyMap.put(keyboard.charAt(i),i+1);
for(int i=0;i<key.length()-1;i++)
res+=Math.abs(keyboard.indexOf(key.charAt(i))-keyboard.indexOf(key.charAt(i+1)));
return res;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int test_case=in.nextInt();
LinearKeyboard_A obj=new LinearKeyboard_A();
while(test_case-->0) {
String keyboard=in.next();
String key=in.next();
int res=obj.time(keyboard, key);
System.out.println(res);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 88fbffeea88e5b45fdc06ed385c2b2a2 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | //package div3_753;
import java.util.HashMap;
import java.util.Scanner;
public class LinearKeyboard_A {
protected int time(String keyboard,String key) {
if(key.length()<=1)
return 0;
HashMap<Character,Integer> keyMap=new HashMap<>();
int res=0;
for(int i=0;i<keyboard.length();i++)
keyMap.put(keyboard.charAt(i),i+1);
for(int i=0;i<key.length()-1;i++)
res+=Math.abs(keyMap.get(key.charAt(i))-keyMap.get(key.charAt(i+1)));
return res;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int test_case=in.nextInt();
LinearKeyboard_A obj=new LinearKeyboard_A();
while(test_case-->0) {
String keyboard=in.next();
String key=in.next();
int res=obj.time(keyboard, key);
System.out.println(res);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 10e0d5de7ab15ea7654df002985342e5 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
public class latin{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t= Integer.parseInt(sc.nextLine());
while(t > 0){
String latin = sc.nextLine();
String s = sc.nextLine();
int n = s.length();
int ans = 0;
for(int i=0;i<n-1;i++){
int val1 = latin.indexOf(s.charAt(i))+1;
int val2 = latin.indexOf(s.charAt(i+1))+1;
ans += Math.abs(val1 - val2);
}
System.out.println(ans);
t--;
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 6c02becfac8a70a67f8c53fda5af94da | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class LinearKeyboard {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int t = cin.nextInt();
cin.nextLine();
while(t != 0){
String keyboard = cin.nextLine();
String letter = cin.nextLine();
int time = 0;
for(int i = 0; i < letter.length() - 1; i++)
time += Math.abs(keyboard.indexOf(letter.charAt(i + 1)) - keyboard.indexOf(letter.charAt(i)));
System.out.println(time);
t--;
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | ebe527d454ffe0915a24ecc1a072b30e | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
public class p1607A
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
while(n-- > 0)
{
char [] in = scan.next().toCharArray();
HashMap<Character,Integer> map = new HashMap<Character,Integer>();
for (int i = 0; i < in.length; i++)
{
map.put(in[i],i);
}
char [] string = scan.next().toCharArray();
int ind = map.get(string[0]), total = 0;
for (int i = 1; i < string.length; i++)
{
total += Math.abs(ind - map.get(string[i]));
ind = map.get(string[i]);
}
System.out.println(total);
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | d33c9438fc0d4453fe22daba40547a10 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.Scanner;
public class Keyboard {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String keyboard ="";
String word ="";
int time =0;
int repeats = input.nextInt();
for (int x=0; x<repeats; x++) {
keyboard = input.next();
word= input.next();
for (int n=0; n<word.length()-1; n++) {
time+=Math.abs((keyboard.indexOf(word.charAt(n+1))-(keyboard.indexOf(word.charAt(n)))));
}
System.out.println(time);
time=0;
}
}
} | Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 1e6b0a0a1bd5824feb34482b91dc2d49 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class LinKeyboard { //800 String implementation
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int t = Integer.parseInt(st.nextToken());
for(int i=0; i<t; i++) {
st = new StringTokenizer(br.readLine());
String keyboard = st.nextToken();
st = new StringTokenizer(br.readLine());
String s = st.nextToken();
int moves = 0;
for(int a=0; a<s.length()-1; a++)
moves += Math.abs(keyboard.indexOf(s.charAt(a+1))-keyboard.indexOf(s.charAt(a)));
pw.println(moves);
}
pw.close();
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 3ab14d7e23cac5ece06bd86e08fedc28 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class LinKeyboard { //800 String implementation
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int t = Integer.parseInt(st.nextToken());
for(int i=0; i<t; i++) {
st = new StringTokenizer(br.readLine());
String keyboard = st.nextToken();
st = new StringTokenizer(br.readLine());
String s = st.nextToken();
int moves = 0;
for(int a=0; a<s.length()-1; a++)
moves += Math.abs(keyboard.indexOf(s.charAt(a+1))-keyboard.indexOf(s.charAt(a)));
System.out.println(moves);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 2f81a12ab4bf3c6ec3ecfb15982c99f9 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes |
import java.util.Scanner;
public class LinearKeyboard {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for (int i = 0; i < T; i++) {
String keyboard = in.next();
String stringToType = in.next();
System.out.println(calculateTime(keyboard, stringToType));
}
}
public static int calculateTime(String keyboard, String string) {
int sum = 0;
for (int i = 0; i < string.length()-1; i++) {
sum += Math.abs(keyboard.indexOf(string.charAt(i)) - keyboard.indexOf(string.charAt(i+1)));
}
return sum;
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 454c5d9540487220e1b72730a24b3422 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
public class Solution {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
String key = sc.next();
String word = sc.next();
HashMap<Character, Integer> map = new HashMap<>();
for(int i = 0; i< key.length(); i++){
map.put(key.charAt(i), i);
}
int count = 0;
int prev = map.getOrDefault(word.charAt(0),0);
for(int i = 1; i< word.length();i++){
int curr = map.getOrDefault(word.charAt(i), 0);
count+= Math.abs(curr-prev);
prev = curr;
}
System.out.println(count);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output | |
PASSED | 220ae8fd6509430a221a17cf0caeebe8 | train_108.jsonl | 1635863700 | You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t--!=0){
String str=sc.next();
int a[]=new int[26];
for(int i=0;i<str.length();i++){
a[str.charAt(i)-'a']=i;
}
int sum=0;
String st2=sc.next();
for(int i=1;i<st2.length();i++){
sum=sum+Math.abs(a[st2.charAt(i)-'a']-a[st2.charAt(i-1)-'a']);
}
System.out.println(sum);
}
}
}
| Java | ["5\nabcdefghijklmnopqrstuvwxyz\nhello\nabcdefghijklmnopqrstuvwxyz\ni\nabcdefghijklmnopqrstuvwxyz\ncodeforces\nqwertyuiopasdfghjklzxcvbnm\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\nqwertyuiopasdfghjklzxcvbnm\nabacaba"] | 1 second | ["13\n0\n68\n0\n74"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | 7f9853be7ac857bb3c4eb17e554ad3f1 | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters. | 800 | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.