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 | b457bb1e47ea35252f8df44434ce337c | train_002.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (xβ<βy) from the set, such that yβ=βxΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.text.*;
public class cf275c {
static BufferedReader br;
static Scanner sc;
static PrintWriter out;
public static void initA() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
//br = new BufferedReader(new FileReader("input.txt"));
sc = new Scanner(System.in);
//out = new PrintWriter("output.txt");
out = new PrintWriter(System.out);
} catch (Exception e) {
}
}
public static void initB() {
try {
br = new BufferedReader(new FileReader("input.txt"));
sc = new Scanner(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
} catch (Exception e) {
}
}
public static String getString() {
try {
return br.readLine();
} catch (Exception e) {
}
return "";
}
public static Integer getInt() {
try {
return Integer.parseInt(br.readLine());
} catch (Exception e) {
}
return 0;
}
public static Long[] getIntArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Long temp2[] = new Long[n];
for (int i = 0; i < n; i++) {
temp2[i] = Long.parseLong(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static String[] getStringArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
String temp2[] = new String[n];
for (int i = 0; i < n; i++) {
temp2[i] = (temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static int getMax(Integer[] ar) {
int t = ar[0];
for (int i = 0; i < ar.length; i++) {
if (ar[i] > t) {
t = ar[i];
}
}
return t;
}
public static void print(Object a) {
out.println(a);
}
public static void printf(String s, Object... a) {
out.printf(s, a);
}
public static int nextInt() {
return sc.nextInt();
}
public static double nextDouble() {
return sc.nextDouble();
}
public static void main(String[] ar) {
initA();
solve();
out.flush();
}
public static void solve() {
Long[] xx = getIntArr();
long n = xx[0];
long k = xx[1];
if(k==1){
print(n);
return;
}
Long data[] = getIntArr();
Arrays.sort(data);
HashSet<Long> all = new HashSet<Long>(Arrays.asList(data));
ArrayList<Long> hps = new ArrayList<Long>();
for (Long d : data) {
//printf("HAPUS %s\n", d*k);
if (Collections.binarySearch(hps, d)<0) {
all.remove(d * k);
hps.add(d * k);
}
}
print(all.size());
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 6 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1ββ€βnββ€β105,β1ββ€βkββ€β109). The next line contains a list of n distinct positive integers a1,βa2,β...,βan (1ββ€βaiββ€β109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1,βa2,β...,βan}. | standard output | |
PASSED | aa43b7b6be6307f42d00a8e74a3ce020 | train_002.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (xβ<βy) from the set, such that yβ=βxΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.text.*;
public class cf275c {
static BufferedReader br;
static Scanner sc;
static PrintWriter out;
public static void initA() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
//br = new BufferedReader(new FileReader("input.txt"));
sc = new Scanner(System.in);
//out = new PrintWriter("output.txt");
out = new PrintWriter(System.out);
} catch (Exception e) {
}
}
public static void initB() {
try {
br = new BufferedReader(new FileReader("input.txt"));
sc = new Scanner(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
} catch (Exception e) {
}
}
public static String getString() {
try {
return br.readLine();
} catch (Exception e) {
}
return "";
}
public static Integer getInt() {
try {
return Integer.parseInt(br.readLine());
} catch (Exception e) {
}
return 0;
}
public static Long[] getIntArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Long temp2[] = new Long[n];
for (int i = 0; i < n; i++) {
temp2[i] = Long.parseLong(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static String[] getStringArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
String temp2[] = new String[n];
for (int i = 0; i < n; i++) {
temp2[i] = (temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static int getMax(Integer[] ar) {
int t = ar[0];
for (int i = 0; i < ar.length; i++) {
if (ar[i] > t) {
t = ar[i];
}
}
return t;
}
public static void print(Object a) {
out.println(a);
}
public static void printf(String s, Object... a) {
out.printf(s, a);
}
public static int nextInt() {
return sc.nextInt();
}
public static double nextDouble() {
return sc.nextDouble();
}
public static void main(String[] ar) {
initA();
solve();
out.flush();
}
public static void solve() {
Long[] xx = getIntArr();
long n = xx[0];
long k = xx[1];
if(k==1){
print(n);
return;
}
Long data[] = getIntArr();
Arrays.sort(data);
HashSet<Long> all = new HashSet<Long>(Arrays.asList(data));
HashSet<Long> hps = new HashSet<Long>();
for (Long d : data) {
//printf("HAPUS %s\n", d*k);
if (!hps.contains(d)) {
all.remove(d * k);
hps.add(d * k);
}
}
print(all.size());
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 6 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1ββ€βnββ€β105,β1ββ€βkββ€β109). The next line contains a list of n distinct positive integers a1,βa2,β...,βan (1ββ€βaiββ€β109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1,βa2,β...,βan}. | standard output | |
PASSED | f1bff3659d9452a601970e1c452e3f2d | train_002.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (xβ<βy) from the set, such that yβ=βxΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.text.*;
public class cf275c {
static BufferedReader br;
static Scanner sc;
static PrintWriter out;
public static void initA() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
//br = new BufferedReader(new FileReader("input.txt"));
sc = new Scanner(System.in);
//out = new PrintWriter("output.txt");
out = new PrintWriter(System.out);
} catch (Exception e) {
}
}
public static void initB() {
try {
br = new BufferedReader(new FileReader("input.txt"));
sc = new Scanner(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
} catch (Exception e) {
}
}
public static String getString() {
try {
return br.readLine();
} catch (Exception e) {
}
return "";
}
public static Integer getInt() {
try {
return Integer.parseInt(br.readLine());
} catch (Exception e) {
}
return 0;
}
public static Long[] getIntArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Long temp2[] = new Long[n];
for (int i = 0; i < n; i++) {
temp2[i] = Long.parseLong(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static String[] getStringArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
String temp2[] = new String[n];
for (int i = 0; i < n; i++) {
temp2[i] = (temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static int getMax(Integer[] ar) {
int t = ar[0];
for (int i = 0; i < ar.length; i++) {
if (ar[i] > t) {
t = ar[i];
}
}
return t;
}
public static void print(Object a) {
out.println(a);
}
public static void printf(String s, Object... a) {
out.printf(s, a);
}
public static int nextInt() {
return sc.nextInt();
}
public static double nextDouble() {
return sc.nextDouble();
}
public static void main(String[] ar) {
initA();
solve();
out.flush();
}
public static void solve() {
Long[] xx = getIntArr();
long n = xx[0];
long k = xx[1];
Long data[] = getIntArr();
Arrays.sort(data);
HashSet<Long> all = new HashSet<Long>(Arrays.asList(data));
HashSet<Long> hps = new HashSet<Long>();
for (Long d : data) {
//printf("HAPUS %s\n", d*k);
if (!hps.contains(d) && d!=d*k) {
all.remove(d * k);
hps.add(d * k);
}
}
print(all.size());
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 6 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1ββ€βnββ€β105,β1ββ€βkββ€β109). The next line contains a list of n distinct positive integers a1,βa2,β...,βan (1ββ€βaiββ€β109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1,βa2,β...,βan}. | standard output | |
PASSED | c039570853d01abadcfa681aa61a7cb8 | train_002.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (xβ<βy) from the set, such that yβ=βxΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class b {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
Set<Long> vals = new HashSet<Long>();
List<Long> as = new ArrayList<Long>();
int n = sc.nextInt();
long k = sc.nextLong();
for (int i = 0; i < n; i++) {
as.add(sc.nextLong());
}
Collections.sort(as);
int cnt = 0;
for (int i = 0; i < as.size(); i++) {
Long next = as.get(i);
if(vals.contains(next)){
continue;
}
cnt ++;
vals.add(next* k);
}
System.out.println(cnt);
// out.flush();
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 6 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1ββ€βnββ€β105,β1ββ€βkββ€β109). The next line contains a list of n distinct positive integers a1,βa2,β...,βan (1ββ€βaiββ€β109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1,βa2,β...,βan}. | standard output | |
PASSED | add31629dd50dd77962cd8b99ad61f2e | train_002.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (xβ<βy) from the set, such that yβ=βxΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
public class b {
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
long k = Long.parseLong(st.nextToken());
st = new StringTokenizer(br.readLine());
// long[] arr = new long[n];
List<Integer> list = new ArrayList<Integer>();
for(int i=0; i<n; ++i) {
// arr[i] = Integer.parseInt(st.nextToken());
list.add(Integer.parseInt(st.nextToken())) ;
}
Set<Long> set = new HashSet<Long>();
int cnt =0;
// Arrays.sort(arr);
Collections.sort(list);
for(int i=0; i<n; ++i) {
// long value = arr[i];
long value = list.get(i);
if(set.contains(value)) {
continue;
}
cnt++;
set.add(value*k);
}
System.out.println(cnt);;
}
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 6 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1ββ€βnββ€β105,β1ββ€βkββ€β109). The next line contains a list of n distinct positive integers a1,βa2,β...,βan (1ββ€βaiββ€β109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1,βa2,β...,βan}. | standard output | |
PASSED | cdfc266bf3192efe3ba43f4d33360471 | train_002.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (xβ<βy) from the set, such that yβ=βxΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
public class b {
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
long k = Long.parseLong(st.nextToken());
st = new StringTokenizer(br.readLine());
// int[] arr = new int[n];
List<Integer> list = new ArrayList<Integer>();
for(int i=0; i<n; ++i) {
// arr[i] = Integer.parseInt(st.nextToken());
list.add(Integer.parseInt(st.nextToken())) ;
}
Set<Long> set = new HashSet<Long>();
int cnt =0;
// Arrays.sort(arr);
Collections.sort(list);
for(int i=0; i<n; ++i) {
// long value = arr[i];
long value = list.get(i);
if(set.contains(value)) {
continue;
}
cnt++;
set.add(value*k);
}
System.out.println(cnt);;
}
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 6 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1ββ€βnββ€β105,β1ββ€βkββ€β109). The next line contains a list of n distinct positive integers a1,βa2,β...,βan (1ββ€βaiββ€β109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1,βa2,β...,βan}. | standard output | |
PASSED | 7a1dc7b69021e1f3be3df6f73923b485 | train_002.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (xβ<βy) from the set, such that yβ=βxΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
public class b {
public static void main2(String[] args) {
}
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
long k = Long.parseLong(st.nextToken());
st = new StringTokenizer(br.readLine());
int[] arr = new int[n];
// List<Integer> list = new ArrayList<Integer>();
for(int i=0; i<n; ++i) {
arr[i] = Integer.parseInt(st.nextToken());
// list.add(Integer.parseInt(st.nextToken())) ;
}
Set<Long> set = new HashSet<Long>();
int cnt =0;
Arrays.sort(arr);
// Collections.sort(list);
for(int i=0; i<n; ++i) {
long value = arr[i];
// long value = list.get(i);
if(set.contains(value)) {
continue;
}
cnt++;
set.add(value*k);
}
System.out.println(cnt);;
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 6 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1ββ€βnββ€β105,β1ββ€βkββ€β109). The next line contains a list of n distinct positive integers a1,βa2,β...,βan (1ββ€βaiββ€β109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1,βa2,β...,βan}. | standard output | |
PASSED | a87625c1cfc6c1fc5541bdd307942d37 | train_002.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (xβ<βy) from the set, such that yβ=βxΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;
/**
* Works good for CF
* @author cykeltillsalu
*/
public class C {
//some local config
static boolean test = false;
static String testDataFile = "testdata.txt";
static String feedFile = "feed.txt";
CompetitionType type = CompetitionType.CF;
private static String ENDL = "\n";
// solution
private void solve() throws Throwable {
Set<Long> vals = new HashSet<Long>();
List<Long> as = new ArrayList<Long>();
int n = iread();
long k = lread();
for (int i = 0; i < n; i++) {
as.add(lread());
}
Collections.sort(as);
int cnt = 0;
for (int i = 0; i < as.size(); i++) {
Long next = as.get(i);
if(vals.contains(next)){
continue;
}
cnt ++;
vals.add(next* k);
}
System.out.println(cnt);
out.flush();
}
public int iread() throws Exception {
return Integer.parseInt(wread());
}
public double dread() throws Exception {
return Double.parseDouble(wread());
}
public long lread() throws Exception {
return Long.parseLong(wread());
}
public String wread() throws IOException {
StringBuilder b = new StringBuilder();
int c;
c = in.read();
while (c >= 0 && c <= ' ')
c = in.read();
if (c < 0)
return "";
while (c > ' ') {
b.append((char) c);
c = in.read();
}
return b.toString();
}
public static void main(String[] args) throws Throwable {
if(test){ //run all cases from testfile:
BufferedReader testdataReader = new BufferedReader(new FileReader(testDataFile));
String readLine = testdataReader.readLine();
int casenr = 0;
out: while (true) {
BufferedWriter w = new BufferedWriter(new FileWriter(feedFile));
if(!readLine.equalsIgnoreCase("input")){
break;
}
while (true) {
readLine = testdataReader.readLine();
if(readLine.equalsIgnoreCase("output")){
break;
}
w.write(readLine + "\n");
}
w.close();
System.out.println("Answer on case "+(++casenr)+": ");
new C().solve();
System.out.println("Expected answer: ");
while (true) {
readLine = testdataReader.readLine();
if(readLine == null){
break out;
}
if(readLine.equalsIgnoreCase("input")){
break;
}
System.out.println(readLine);
}
System.out.println("----------------");
}
testdataReader.close();
} else { // run on server
new C().solve();
}
out.close();
}
public C() throws Throwable {
if (test) {
in = new BufferedReader(new FileReader(new File(feedFile)));
}
}
InputStreamReader inp = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(inp);
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
enum CompetitionType {CF, OTHER};
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 6 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1ββ€βnββ€β105,β1ββ€βkββ€β109). The next line contains a list of n distinct positive integers a1,βa2,β...,βan (1ββ€βaiββ€β109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1,βa2,β...,βan}. | standard output | |
PASSED | c8880358fd000b95b6b8f2543efd38c4 | train_002.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (xβ<βy) from the set, such that yβ=βxΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
public class C275C {
static StreamTokenizer in;
static int nextInt() throws IOException{
in.nextToken();
return (int) in.nval;
}
public static void main(String[] args) throws IOException{
in = new StreamTokenizer(new InputStreamReader(System.in));
// HashSet<Integer> h = new HashSet<Integer>();
int n = nextInt(), k = nextInt();
int[] b = new int[n];
int[] h = new int[n];
for (int i = 0; i < n; i++){
b[i] = nextInt();
}
int len = 0;
sort(b,0,n - 1);
int ans = 0;
for (int i = 0; i < n; i++){
int a = b[i];
// System.out.println(b[i]);
if (Arrays.binarySearch(h, 0, len, a) >=0 ){
ans++;
} else {
int mod = a % k;
if ((mod != 0) || (mod == 0 && Arrays.binarySearch(h, 0, len, a / k) < 0)){
h[len++] = a;
ans++;
}
}
}
System.out.println(ans);
}
static Random rand = new Random();
static void sort(int[] a, int l, int r){
int i = l, j = r;
int x = a[l + rand.nextInt(r - l + 1)];
do{
while (a[i] < x) i++;
while (x < a[j]) j--;
if (i <= j){
int t = a[i]; a[i] = a[j]; a[j] = t;
i++; j--;
}
}while (i <= j);
if (i < r) sort(a,i,r);
if (l < j) sort(a,l,j);
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 6 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1ββ€βnββ€β105,β1ββ€βkββ€β109). The next line contains a list of n distinct positive integers a1,βa2,β...,βan (1ββ€βaiββ€β109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1,βa2,β...,βan}. | standard output | |
PASSED | c41d6f2d74636e01f0dbcfad5a0e46d3 | train_002.jsonl | 1276182000 | In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We should remind you that a string is called a palindrome if it can be read the same way both from left to right and from right to left. Here are examples of such strings: Β«eyeΒ», Β«popΒ», Β«levelΒ», Β«abaΒ», Β«deedΒ», Β«racecarΒ», Β«rotorΒ», Β«madamΒ». Nick started to look carefully for all palindromes in the text that they were reading in the class. For each occurrence of each palindrome in the text he wrote a pair β the position of the beginning and the position of the ending of this occurrence in the text. Nick called each occurrence of each palindrome he found in the text subpalindrome. When he found all the subpalindromes, he decided to find out how many different pairs among these subpalindromes cross. Two subpalindromes cross if they cover common positions in the text. No palindrome can cross itself.Let's look at the actions, performed by Nick, by the example of text Β«babbΒ». At first he wrote out all subpalindromes:β’ Β«bΒ» β 1..1 β’ Β«babΒ» β 1..3 β’ Β«aΒ» β 2..2 β’ Β«bΒ» β 3..3 β’ Β«bbΒ» β 3..4 β’ Β«bΒ» β 4..4 Then Nick counted the amount of different pairs among these subpalindromes that cross. These pairs were six: 1. 1..1 cross with 1..3 2. 1..3 cross with 2..2 3. 1..3 cross with 3..3 4. 1..3 cross with 3..4 5. 3..3 cross with 3..4 6. 3..4 cross with 4..4 Since it's very exhausting to perform all the described actions manually, Nick asked you to help him and write a program that can find out the amount of different subpalindrome pairs that cross. Two subpalindrome pairs are regarded as different if one of the pairs contains a subpalindrome that the other does not. | 128 megabytes | import java.io.*;
//import java.util.*;
import java.math.BigInteger;
public class Main {
static long mod = 51123987;
static int[] findPal(String str, int offset){
int N = str.length(), L = -1, R = -1;
int[] res = new int[N - offset];
for(int i = 0; i < N - offset; i++){
if(i < R){
res[i] = Math.min(R - i, res[L + R - i - offset]);
}
while(i - res[i] - (offset == 0 ? 1 : 0) >= 0 && i + res[i] + 1 < N && str.charAt(i - res[i] - (offset == 0 ? 1 : 0)) == str.charAt(i + res[i] + 1)){
res[i]++;
}
if(i + res[i] > R){
L = i - res[i] + offset;
R = i + res[i];
}
}
return res;
}
public static void main(String[] args) throws java.lang.Exception {
BufferedReader kek = new BufferedReader(new InputStreamReader(System.in));
//Scanner skek = new Scanner(System.in);
PrintWriter outkek = new PrintWriter(System.out);
int N = Integer.parseInt(kek.readLine());
String input = kek.readLine();
long res = 0, starts = 0, ends = 0, sum = 0;;
int[] temp1 = findPal(input, 1);
int[] temp2 = findPal(input, 0);
long[] degBeg = new long[N + 2];
long[] degEnd = new long[N + 2];
for(int offset = 1; offset > -1; offset--){
for(int i = 0; i < N - offset; i++){
degBeg[i - (offset == 1 ? temp1[i] : temp2[i]) + offset]++;
degBeg[i + 1]--;
degEnd[i + (offset == 1 ? 2 : 1)]++;
degEnd[i + (offset == 1 ? temp1[i] : temp2[i]) + 2]--;
}
}
long big = BigInteger.valueOf(2).modInverse(BigInteger.valueOf(mod)).longValue();
for(int i = 0; i <= N; i++){
starts = mod(starts + degBeg[i]);
ends = mod(ends + degEnd[i]);
sum = mod(sum - ends);
res = mod(res + mod(sum * starts) + mod(mod(starts * (starts - 1)) * big));
sum = mod(sum + starts);
}
outkek.println(res);
kek.close();
outkek.close();
}
static long mod(long l){
l %= mod;
while(l < 0){
l += mod;
}
return l;
}
} | Java | ["4\nbabb", "2\naa"] | 2 seconds | ["6", "2"] | null | Java 7 | standard input | [
"strings"
] | 1322a0f1c38f8de56f840fc7e2f14a54 | The first input line contains integer n (1ββ€βnββ€β2Β·106) β length of the text. The following line contains n lower-case Latin letters (from a to z). | 2,900 | In the only line output the amount of different pairs of two subpalindromes that cross each other. Output the answer modulo 51123987. | standard output | |
PASSED | 177a9b95362441e42a4283b69cca2317 | train_002.jsonl | 1276182000 | In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We should remind you that a string is called a palindrome if it can be read the same way both from left to right and from right to left. Here are examples of such strings: Β«eyeΒ», Β«popΒ», Β«levelΒ», Β«abaΒ», Β«deedΒ», Β«racecarΒ», Β«rotorΒ», Β«madamΒ». Nick started to look carefully for all palindromes in the text that they were reading in the class. For each occurrence of each palindrome in the text he wrote a pair β the position of the beginning and the position of the ending of this occurrence in the text. Nick called each occurrence of each palindrome he found in the text subpalindrome. When he found all the subpalindromes, he decided to find out how many different pairs among these subpalindromes cross. Two subpalindromes cross if they cover common positions in the text. No palindrome can cross itself.Let's look at the actions, performed by Nick, by the example of text Β«babbΒ». At first he wrote out all subpalindromes:β’ Β«bΒ» β 1..1 β’ Β«babΒ» β 1..3 β’ Β«aΒ» β 2..2 β’ Β«bΒ» β 3..3 β’ Β«bbΒ» β 3..4 β’ Β«bΒ» β 4..4 Then Nick counted the amount of different pairs among these subpalindromes that cross. These pairs were six: 1. 1..1 cross with 1..3 2. 1..3 cross with 2..2 3. 1..3 cross with 3..3 4. 1..3 cross with 3..4 5. 3..3 cross with 3..4 6. 3..4 cross with 4..4 Since it's very exhausting to perform all the described actions manually, Nick asked you to help him and write a program that can find out the amount of different subpalindrome pairs that cross. Two subpalindrome pairs are regarded as different if one of the pairs contains a subpalindrome that the other does not. | 128 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class E {
static BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
static StringTokenizer st = new StringTokenizer("");
static int nextInt() throws Exception {
return Integer.parseInt(next());
}
static String next() throws Exception {
while (true) {
if (st.hasMoreTokens()) {
return st.nextToken();
}
String s = br.readLine();
if (s == null) {
return null;
}
st = new StringTokenizer(s);
}
}
static int mod = 51123987;
public static int[] longestOddPlaindrome(char[] str) {
int[] res = new int[str.length];
int startFrom = 1;
int i = 0;
loop: for (; i + startFrom < str.length; i++) {
int before = i - startFrom;
int after = i + startFrom;
while (before >= 0 && after < str.length
&& str[before] == str[after]) {
before--;
after++;
}
before++;
after--;
res[i] = after - before + 1;
for (int j = 1; j + i <= after; j++) {
int toBePrefix = (i - j) - before;
if (res[i - j] / 2 >= toBePrefix) {
startFrom = toBePrefix + 1;
i = i + j - 1;
continue loop;
} else {
res[i + j] = res[i - j];
}
}
startFrom = 1;
}
if (i < str.length) {
res[i] = 2 * (startFrom - 1) + 1;
}
for (int j = 1; i + j < str.length; j++) {
res[i + j] = Math.min(res[i - j],
2 * (str.length - (i + j) - 1) + 1);
}
return res;
}
public static int[] longestEvenPlaindrome(char[] str) {
// res[i] length of longest even palindrome whose first half ends at i
int[] res = new int[str.length];
int startFrom = 0;
int i = 0;
loop: for (; i + 1 + startFrom < str.length; i++) {
int before = i - startFrom;
int after = i + 1 + startFrom;
while (before >= 0 && after < str.length
&& str[before] == str[after]) {
before--;
after++;
}
before++;
after--;
res[i] = after - before + 1;
for (int j = 1; i - j >= before; j++) {
int toBePrefix = (i - j) - before + 1;
if (res[i - j] / 2 >= toBePrefix) {
startFrom = toBePrefix;
i = i + j - 1;
continue loop;
} else {
res[i + j] = res[i - j];
}
}
startFrom = 0;
}
if (i < str.length) {
res[i] = 2 * (startFrom);
}
for (int j = 1; i + j < str.length; j++) {
res[i + j] = Math.min(res[i - j], 2 * (str.length - (i + j + 1)));
}
return res;
}
public static void main(String[] args) throws Exception {
nextInt();
char[] str = next().toCharArray();
long total = 0;
int[] start = new int[str.length];
int[] end = new int[str.length];
int[] longestOdd = longestOddPlaindrome(str);
int[] longestEven = longestEvenPlaindrome(str);
for (int i = 0; i < longestOdd.length; i++) {
int maxOdd = longestOdd[i] / 2;
int minRange = i - maxOdd;
int maxRange = i;
start[minRange]++;
if (maxRange < start.length - 1) {
start[maxRange + 1]--;
}
minRange = i;
maxRange = i + maxOdd;
end[minRange]++;
if (maxRange < end.length - 1) {
end[maxRange + 1]--;
}
total = (total + ((longestOdd[i] + 1) / 2)) % mod;
}
for (int i = 0; i < longestEven.length; i++) {
int maxEven = longestEven[i] / 2;
if (maxEven > 0) {
int minRange = i - maxEven + 1;
int maxRange = i;
start[minRange]++;
if (maxRange < start.length - 1) {
start[maxRange + 1]--;
}
minRange = i + 1;
maxRange = i + maxEven;
end[minRange]++;
if (maxRange < end.length - 1) {
end[maxRange + 1]--;
}
}
total = (total + (longestEven[i] / 2)) % mod;
}
BigInteger two = new BigInteger("2");
BigInteger inv2 = two.modInverse(BigInteger.valueOf(mod)).mod(
BigInteger.valueOf(mod));
total = (((total) * (total - 1 + mod)) % mod * inv2.longValue()) % mod;
long sumEnd = 0;
long curElem = 0;
long sumSt = start[0];
for (int i = 0; i < end.length - 1; i++) {
curElem = (curElem + end[i]) % mod;
sumEnd = (sumEnd + curElem) % mod;
sumSt = (sumSt + start[i + 1]) % mod;
total = (total - (sumEnd * sumSt) % mod + mod) % mod;
}
System.out.println(total);
}
}
| Java | ["4\nbabb", "2\naa"] | 2 seconds | ["6", "2"] | null | Java 7 | standard input | [
"strings"
] | 1322a0f1c38f8de56f840fc7e2f14a54 | The first input line contains integer n (1ββ€βnββ€β2Β·106) β length of the text. The following line contains n lower-case Latin letters (from a to z). | 2,900 | In the only line output the amount of different pairs of two subpalindromes that cross each other. Output the answer modulo 51123987. | standard output | |
PASSED | 3ba3d32981ed3bae2423d7982de6a707 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | //package MyPackage.YourPack.kfjf;
import java.util.Scanner;
public class ComplexNotBoringMfldfdd {
public static void main(String []args){
Scanner scan=new Scanner(System.in);
String fk=scan.next();
String sk=scan.next();
String text=scan.next();
for(int i=0;i<text.length();i++)
{
char ch=text.charAt(i);
if(ch>='a'&&ch<='z')
{
System.out.print(sk.charAt(fk.indexOf(ch)));
}
else if(ch<='9'&&ch>='0')
System.out.print(ch);
else {
ch=(char)(ch+32);
ch=sk.charAt(fk.indexOf(ch));
ch=(char)(ch-32);
System.out.print(ch);
}
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 65b53419255cd3421987b7d015578cf4 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | //Author: Mo Abjal, MJP Rohilkhand University Bareilly, UP, India 2018.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////********************//////////////////////////////////////////////
/////////////////////////////////////////* SOLUTION *//////////////////////////////////////////////
/////////////////////////////////////////********************//////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
public class Main{
public static StringTokenizer token = new StringTokenizer("");
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static PrintWriter output = new PrintWriter(System.out);
public static void main(String[] afzal) throws Exception {
String s = ns();
String t = ns();
String text = ns();
for(int i=0;i<text.length();i++){
int x = s.indexOf(text.charAt(i));
if(x>=0){
output.print(t.charAt(x));
}
else if(x==-1){
x = s.indexOf((char)(((int)text.charAt(i))+32));
if(x>=0)
output.print((char)((int)t.charAt(x)-32));
else output.print(text.charAt(i));
}
}
output.close();
/*int A = ni();
int B = ni();
int C = ni();
String ans = "";
if(C>=A || C>=B)
if(C%A==0){
ans = "YES";
}
else if(C%B==0){
ans = "YES";
}
else if((C-A)%B==0){
ans = "YES";
}
else if((C-B)%A==0){
ans = "YES";
}
else{
ans = "NO";
}
else ans = "NO";
output.println(ans); output.close();*/
/*int N = ni();
for(int i=0;i<N;i++){
int count=0;
int L = ni();
int v = ni();
int l = ni();
int r = ni();
if(1%v==0) count++;
if(l%v==0) count++;
if(r%v==0) count++;
if(L%v==0) count++;
count+=l/v;
count+=(L-r)/v;
int x = (L-(r-l+1))/v;
output.println(count);
}
output.close();*/
/*int N = ni();
boolean flag = true;
int x = N;
while(x>0){
if(x%10==0 || x%10==1){
}
else{
flag = false; break;
}
x/=10;
}
if(flag){
output.println("1\n"+N); output.close(); return;
}
String temp = "";
int count = 1;
for(int i=0;count<=ps(N).length();i++){
temp+="1"; count++;
}
if(temp=="") temp="1";
int test = pi(temp);
int ans=0;
int A[] = new int[N+5];
int j=0;
//output.println(test);
while(N>0){
if(N>=test){
A[j] = test; N-=test; ans++;
j++;
//System.out.println(A[j]+" ");
}
else if(test%10==0 && (test/10)%10==1){
test-=9;
}
else if(test%10==1 && (test/10)%10==0){
test-=90;
}
else if(test%10==1 && (test/10)%10==1){
test--;
}
}
output.println(ans);
for(int i=0;A[i+1]!=0;i++){
output.print(A[i]+" ");
}
output.println(test); output.close();*/
}
public static String pc(char c){
return Character.toString(c);
}
public static Integer pci(char c){
return pi(Character.toString(c));
}
public static Integer pi(String str){
return Integer.parseInt(str);
}
public static Long pl(String str){
return Long.parseLong(str);
}
public static String ps(Integer N){
return Integer.toString(N);
}
public static char[] pcc(String str){
return str.toCharArray();
}
public static Integer ni() throws IOException{
if(!token.hasMoreElements()){
token = new StringTokenizer(br.readLine());
}
return Integer.parseInt(token.nextToken());
}
public static Long nl() throws IOException{
if(!token.hasMoreElements()){
token = new StringTokenizer(br.readLine());
}
return Long.parseLong(token.nextToken());
}
public static Double nd() throws IOException{
if(!token.hasMoreElements()){
token = new StringTokenizer(br.readLine());
}
return Double.parseDouble(token.nextToken());
}
public static String ns() throws IOException{
return new StringTokenizer(br.readLine()).nextToken();
}
public static Integer[] ai(int N) throws IOException{
Integer A[] = new Integer[N];
token = new StringTokenizer(br.readLine());
for(int i=0;i<A.length;i++){
A[i] = pi(token.nextToken());
}
return A;
}
public static long[] al(int N) throws IOException{
long A[] = new long[N];
token = new StringTokenizer(br.readLine());
for(int i=0;i<N;i++){
A[i] = Long.parseLong(token.nextToken());
}
return A;
}
public static char[][] acc(int N,int M) throws IOException{
char C[][] = new char[N][M];
for(int i=0;i<N;i++){
token = new StringTokenizer(br.readLine());
String s = token.nextToken();
for(int j=0;j<M;j++){
C[i][j] = s.charAt(j);
}
}
return C;
}
public static String[] as(int N) throws IOException{
String S[] = new String[N];
token = new StringTokenizer(br.readLine());
for(int i=0;i<S.length;i++){
S[i] = token.nextToken();
}
return S;
}
public static long fact(long N){
long fact = 1;
for(int i=1;i<=N;i++){
fact = fact * i;
}
return fact;
}
public static BigInteger factB(int N){
BigInteger b = new BigInteger("1");
for(int i=1;i<=N;i++){
b = b.multiply(BigInteger.valueOf(i));
}
return b;
}
public static long sod(long N){
long sum = 0;
while(N>0){
long x = N%10;
sum = sum + x;
N = N/10;
}
return sum;
}
public static Integer cd(long N){
int count=0;
while(N>0){
N = N/10; count++;
}
return count=0;
}
}
class Pair implements Comparable{
int a,b;
public Pair(int a,int b){
this.a = a;
this.b = b;
}
public int compareTo(Object p){
Pair pa = (Pair)p;
if(this.a==pa.a) return this.b - pa.b;
return this.a - pa.a;
}
}
//Copyright Reserved - Mo Abjal.
/*
import java.util.Arrays;
import java.util.Scanner;
public class MockvitD {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int d=sc.nextInt();
Boss[]a=new Boss[n];
for(int i=0;i<n;i++){
a[i]=new Boss(sc.nextInt(),sc.nextInt());
}
Arrays.sort(a);
int i=0,j=0;
long sum=0,ans=-1l;
for(i=0;i<n;i++){
sum=sum+a[i].f;
if(a[i].m-a[j].m>=d){
sum=sum-a[j].f;
j++;
}
ans=Math.max(sum,ans);
}
System.out.println(ans);
}
}*/ | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 5edc561147199d58c045797cdfd8d134 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class firstProb {
private static Scanner s;
public static void main(String[] args){
s = new Scanner(System.in);
Map<String,Integer> key1=new HashMap<String,Integer>();
Map<Integer,String> key2=new HashMap<Integer,String>();
String first = s.next();
String second = s.next();
for (int i=0;i<first.length();i++)
key1.put( Character.toString(first.charAt(i)),i);
for (int j=0;j<second.length();j++)
key2.put(j, Character.toString(second.charAt(j)));
String test=s.next();
String result ="";
for(int k=0;k<test.length();k++)
{
//key1.get(Character.toString(test.charAt(k)));
if(Character.isUpperCase(test.charAt(k)))
result=result+key2.get(key1.get(Character.toString(test.charAt(k)).toLowerCase())).toUpperCase();
else if(Character.isDigit(test.charAt(k)) )
result=result+test.charAt(k);
else
result=result+key2.get(key1.get(Character.toString(test.charAt(k))));
}
System.out.println(result);
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 3969a489ee68677b665eeac27b9aad44 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class firstProb {
private static Scanner s;
public static void main(String[] args){
s = new Scanner(System.in);
Map<String,Integer> key1=new HashMap<String,Integer>();
Map<Integer,String> key2=new HashMap<Integer,String>();
String first = s.next();
String second = s.next();
for (int i=0;i<first.length();i++)
key1.put( Character.toString(first.charAt(i)),i);
for (int j=0;j<second.length();j++)
key2.put(j, Character.toString(second.charAt(j)));
String test=s.next();
String result ="";
for(int k=0;k<test.length();k++)
{
//key1.get(Character.toString(test.charAt(k)));
if(Character.isUpperCase(test.charAt(k)))
result=result+key2.get(key1.get(Character.toString(test.charAt(k)).toLowerCase())).toUpperCase();
else if(Character.isDigit(test.charAt(k)) )
result=result+test.charAt(k);
else
result=result+key2.get(key1.get(Character.toString(test.charAt(k))));
}
System.out.println(result);
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 6b5c54cf670ee500b62e0fdf94562bb1 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class Keyboard_Layouts {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
String type1 = scan.nextLine();
String type2 = scan.nextLine();
String s = scan.nextLine();
char [] S = s.toCharArray();
String result = new String();
boolean isUpper;
for(int i = 0; i<s.length(); i++) {
isUpper = false;
if(!Character.isLowerCase(S[i])) {
isUpper = true;
S[i] = Character.toLowerCase(S[i]);
}
if (type1.indexOf(S[i]) >= 0) {
S[i] = type2.charAt(type1.indexOf(S[i]));
if (isUpper)
S[i] = Character.toUpperCase(S[i]);
result += S[i];
} else {
result += S[i];
}
}
System.out.println(result);
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 413b7185e0cc932eca1aa8f62ac8d773 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes |
import java.util.Scanner;
public class stick {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String lay1 = sc.next();
String lay2 = sc.next();
String word1 = sc.next();
String word2 = new String();
int i=0,j=0;
char c;
for(i=0;i<word1.length();i++) {
c=word1.charAt(i);
if(Character.isDigit(c)) {
word2 += c;
}
else {
for(j=0;j<26;j++) {
if (c == lay1.charAt(j) || Character.toLowerCase(c) == lay1.charAt(j)) {
if(Character.isUpperCase(c)){
word2 += Character.toUpperCase(lay2.charAt(j));
}
else {
word2 += lay2.charAt(j);
}
break;
}
}
}
}
word2.trim();
System.out.println(word2);
return ;
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 68cfd1d32f602a4f5e17df70041e27e5 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
String ss = in.nextLine();
int a[] = new int[26];
for(int i=0; i<26; i++){
a[s.charAt(i)-'a'] = i;
}
String sss = in.nextLine();
for(int i=0; i<sss.length(); i++){
if(sss.charAt(i)-'0'<10 && sss.charAt(i)-'0'>=0){
System.out.print(sss.charAt(i)+"");
}
else if(sss.charAt(i)>=97){
System.out.print(ss.charAt(a[sss.charAt(i)-'a'])+"");
}
else if(sss.charAt(i)>=65){
System.out.print((char)(ss.charAt(a[sss.charAt(i)+32-'a'])-32)+"");
}
}
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | fffb541ab7cd502a4adfbb9f99ef3171 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.HashMap;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author newkobra
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
public void solve(int testNumber, Scanner in, PrintWriter out) {
String first = in.nextLine();
String second = in.nextLine();
HashMap<Character, Character> map = new HashMap<>();
for (int i = 0; i < 26; i++) {
map.put(first.charAt(i), second.charAt(i));
}
String input = in.nextLine();
for (int i = 0; i < input.length(); i++) {
if (!Character.isAlphabetic(input.charAt(i))) {
out.print(input.charAt(i));
continue;
}
boolean toUpperCase = Character.isUpperCase(input.charAt(i));
Character letter = Character.toLowerCase(input.charAt(i));
Character result = map.get(letter);
if (toUpperCase) {
out.print(Character.toUpperCase(result));
} else {
out.print(result);
}
}
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 13360ae03cb04732d72f5df7793ac8ab | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.*;
public class KeyboardLayout {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
String a = s.next();
String b = s.next();
String para = s.next();
HashMap<Character, Character> map = Getlayout(a, b);
String res = "";
String result = SetLayout(para, map, res);
System.out.println(result);
}
public static String SetLayout(String p, HashMap<Character, Character> map, String s) {
for (int i = 0; i < p.length(); i++) {
char cc = p.charAt(i);
if (map.containsKey(cc)) {
s = s + map.get(cc);
} else {
s = s + cc;
}
}
return s;
}
public static HashMap<Character, Character> Getlayout(String a, String b) {
HashMap<Character, Character> map = new HashMap<>();
for (int i = 0; i < 26; i++) {
char ca = a.charAt(i);
char cb = b.charAt(i);
map.put(ca, cb);
map.put((char) (ca - 32), (char) (cb - 32));
}
return map;
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 85fe61011897a5a6b45b4e2eb0dde004 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.lang.String;
import java.util.Scanner;
import java.lang.Character;
public class TaskA{
public static void main(String args[]){
Scanner s = new Scanner(System.in);
String keyboard = s.next();
String reference = s.next();
String msg = s.next();
char msgformatedChars[] =new char[msg.length()];
for(int i = 0; i<msg.length(); i++){
if(Character.isLetter(msg.charAt(i))){
if(!Character.isLowerCase(msg.charAt(i))){
char current = Character.toLowerCase(msg.charAt(i));
msgformatedChars[i] = Character.toUpperCase( reference.charAt(keyboard.indexOf(current)) );
}else {
char current = Character.toLowerCase(msg.charAt(i));
msgformatedChars[i] = reference.charAt(keyboard.indexOf(msg.charAt(i)));
}
} else {
msgformatedChars[i] = msg.charAt(i);
}
}
String formatedStr = new String(msgformatedChars);
System.out.println(formatedStr);
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | e8388ab57833b637f2f46fa22925a2de | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class main {
public static void main(String[] args){
String l1,l2,word;
Scanner s = new Scanner(System.in);
l1 = s.next();
l2 = s.next();
word = s.next();
/*cin >> l1 >> l2 >> word;*/
/*l1 = "qwertyuiopasdfghjklzxcvbnm";
l2 = "veamhjsgqocnrbfxdtwkylupzi";
word = "TwccpQZAvb2017";*/
for(int i=0;i<word.length();i++){
char z = word.charAt(i);
Boolean x = true;
if(Character.isLowerCase(z)){
x = false;
}
Character c = Character.toLowerCase(word.charAt(i));
int y = l1.indexOf(c);
if(!Character.isDigit(c)){
if(!x) {
System.out.print(l2.charAt(y));
}else{
System.out.print(Character.toUpperCase(l2.charAt(y)));
}
}else {
System.out.print(word.charAt(i));
}
}
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | d31bb1e5a59544c3cdc314d814ea09bf | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class main {
public static void main(String[] args){
String l1,l2,word;
Scanner s = new Scanner(System.in);
l1 = s.next();
l2 = s.next();
word = s.next();
/*cin >> l1 >> l2 >> word;*/
/*l1 = "qwertyuiopasdfghjklzxcvbnm";
l2 = "veamhjsgqocnrbfxdtwkylupzi";
word = "TwccpQZAvb2017";*/
for(int i=0;i<word.length();i++){
char z = word.charAt(i);
Boolean x = true;
if(Character.isLowerCase(z)){
x = false;
}
Character c = Character.toLowerCase(word.charAt(i));
int y = l1.indexOf(c);
if(!Character.isDigit(c)){
if(!x) {
System.out.print(l2.charAt(y));
}else{
System.out.print(Character.toUpperCase(l2.charAt(y)));
}
}else{
System.out.print(word.charAt(i));
}
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | df8b02044cecdee6ac08f1023b57de7b | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class main {
public static void main(String[] args){
String l1,l2,word;
Scanner s = new Scanner(System.in);
l1 = s.next();
l2 = s.next();
word = s.next();
/*cin >> l1 >> l2 >> word;*/
/*l1 = "qwertyuiopasdfghjklzxcvbnm";
l2 = "veamhjsgqocnrbfxdtwkylupzi";
word = "TwccpQZAvb2017";*/
for(int i=0;i<word.length();i++){
char z = word.charAt(i);
Boolean x = true;
if(Character.isLowerCase(z)){
x = false;
}
Character c = Character.toLowerCase(word.charAt(i));
int y = l1.indexOf(c);
if(!Character.isDigit(c)) {
if(!x) {
System.out.print(l2.charAt(y));
}else{
System.out.print(Character.toUpperCase(l2.charAt(y)));
}
}else {
System.out.print(word.charAt(i));
}
}
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | b9b703cc4fd6ba1cd2991b0fd3112a7b | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class KeyboardLayouts {
public static void main(String[] args){
String l1,l2,word;
Scanner s = new Scanner(System.in);
l1 = s.next();
l2 = s.next();
word = s.next();
/*cin >> l1 >> l2 >> word;*/
/*l1 = "qwertyuiopasdfghjklzxcvbnm";
l2 = "veamhjsgqocnrbfxdtwkylupzi";
word = "TwccpQZAvb2017";*/
for(int i=0;i<word.length();i++){
char z = word.charAt(i);
Boolean x = true;
if(Character.isLowerCase(z)){
x = false;
}
Character c = Character.toLowerCase(word.charAt(i));
int y = l1.indexOf(c);
if(!Character.isDigit(c)) {
if(!x) {
System.out.print(l2.charAt(y));
}else{
System.out.print(Character.toUpperCase(l2.charAt(y)));
}
}else {
System.out.print(word.charAt(i));
}
}
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 3ad8ee772d938ec7508dc974087d1f72 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class main {
public static void main(String[] args){
String l1,l2,word;
Scanner s = new Scanner(System.in);
l1 = s.next();
l2 = s.next();
word = s.next();
/*cin >> l1 >> l2 >> word;*/
/*l1 = "qwertyuiopasdfghjklzxcvbnm";
l2 = "veamhjsgqocnrbfxdtwkylupzi";
word = "TwccpQZAvb2017";*/
for(int i=0;i<word.length();i++){
char z = word.charAt(i);
Boolean x = true;
if(Character.isLowerCase(z)){
x = false;
}
Character c = Character.toLowerCase(word.charAt(i));
int y = l1.indexOf(c);
if(!Character.isDigit(c)){
if(!x) {
System.out.print(l2.charAt(y));
}else{
System.out.print(Character.toUpperCase(l2.charAt(y)));
}
}else{
System.out.print(word.charAt(i));
}
}
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 406724358277312e4be50fd3d4a80f3b | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class main {
public static void main(String[] args){
String l1,l2,word;
Scanner s = new Scanner(System.in);
l1 = s.next();
l2 = s.next();
word = s.next();
/*cin >> l1 >> l2 >> word;*/
/*l1 = "qwertyuiopasdfghjklzxcvbnm";
l2 = "veamhjsgqocnrbfxdtwkylupzi";
word = "TwccpQZAvb2017";*/
for(int i=0;i<word.length();i++){
char z = word.charAt(i);
Boolean x = true;
if(Character.isLowerCase(z)){
x = false;
}
Character c = Character.toLowerCase(word.charAt(i));
int y = l1.indexOf(c);
if(!Character.isDigit(c)){
if(!x) {
System.out.print(l2.charAt(y));
}else {
System.out.print(Character.toUpperCase(l2.charAt(y)));
}
}else{
System.out.print(word.charAt(i));
}
}
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 1153ce0c9e9fe1a3809a4747f8e0a91f | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class KeyboardLayouts {
public static void main(String[] args) {
Scanner in= new Scanner(System.in);
String s1 = in.nextLine();
s1=s1.toLowerCase();
String s2 = in.nextLine();
s2=s2.toLowerCase();
String testNotChanged = in.nextLine();
String test=testNotChanged.toLowerCase();
String output="";
for(int i=0;i<test.length();i++){
if(s1.contains(test.charAt(i)+"")){
if(Character.isUpperCase(testNotChanged.charAt(i))){
output+=Character.toUpperCase(s2.charAt(s1.indexOf(test.charAt(i)+"")));
}
else
output+=s2.charAt(s1.indexOf(test.charAt(i)+""));
}
else{
output+=test.charAt(i);
}
}
System.out.println(output);
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 14e309adb6b79faaf5e84281131cbe87 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class KeyboardLayouts {
public static void main(String[] args) {
Scanner in= new Scanner(System.in);
String s1 = in.nextLine();
s1=s1.toLowerCase();
String s2 = in.nextLine();
s2=s2.toLowerCase();
String testNotChanged = in.nextLine();
String test=testNotChanged.toLowerCase();
String output="";
for(int i=0;i<test.length();i++){
if(s1.contains(test.charAt(i)+"")){
if(Character.isUpperCase(testNotChanged.charAt(i))){
output+=Character.toUpperCase(s2.charAt(s1.indexOf(test.charAt(i)+"")));
}
else
output+=s2.charAt(s1.indexOf(test.charAt(i)+""));
}
else{
output+=test.charAt(i);
}
}
System.out.println(output);
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 999a9bb834ee0ec0b1998c2ca8d5561c | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.io.*;
import java.util.*;
public class A764 {
public static void main(String [] args) {
InputStream inputReader = System.in;
OutputStream outputReader = System.out;
InputReader in = new InputReader(inputReader);
PrintWriter out = new PrintWriter(outputReader);
Algorithm solver = new Algorithm();
solver.solve(in, out);
out.close();
}
}
class Algorithm {
void solve(InputReader ir, PrintWriter pw) {
String line1 = ir.next(), line2 = ir.next(), line3 = ir.next(), result = "";
for (int i = 0; i < line3.length(); i++) {
if (line3.charAt(i) == line3.toUpperCase().charAt(i)) {
for (int j = 0; j < line1.length(); j++) {
if (line1.toUpperCase().charAt(j) == line3.charAt(i)) {
result = result + line2.toUpperCase().charAt(j);
break;
} else if (j == line1.length() - 1) {
result = result + line3.charAt(i);
}
}
} else {
for (int j = 0; j < line1.length(); j++) {
if (line1.charAt(j) == line3.charAt(i)) {
result = result + line2.charAt(j);
break;
} else if (j == line1.length() - 1) {
result = result + line3.charAt(i);
}
}
}
}
pw.print(result);
}
private static void Qsort(int[] array, int low, int high) {
int i = low;
int j = high;
int x = array[low + (high - low) / 2];
do {
while (array[i] < x) ++i;
while (array[j] > x) --j;
if (i <= j) {
int tmp = array[i];
array[i] = array[j];
array[j] = tmp;
i++;
j--;
}
} while (i <= j);
if (low < j) Qsort(array, low, j);
if (i < high) Qsort(array, i, high);
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
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();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | f014878570d55f88dfbe4f8034ebdb78 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.io.*;
import java.util.*;
public class A764 {
public static void main(String [] args) {
InputStream inputReader = System.in;
OutputStream outputReader = System.out;
InputReader in = new InputReader(inputReader);
PrintWriter out = new PrintWriter(outputReader);
Algorithm solver = new Algorithm();
solver.solve(in, out);
out.close();
}
}
class Algorithm {
void solve(InputReader ir, PrintWriter pw) {
String line1 = ir.next(), line2 = ir.next(), line3 = ir.next(), result = "";
int len = line1.length();
for (int i = 0; i < line3.length(); i++) {
if (line3.charAt(i) == line3.toUpperCase().charAt(i)) {
for (int j = 0; j < len; j++) {
if (line1.toUpperCase().charAt(j) == line3.charAt(i)) {
result = result + line2.toUpperCase().charAt(j);
break;
} else if (j == len - 1) {
result = result + line3.charAt(i);
}
}
} else {
for (int j = 0; j < len; j++) {
if (line1.charAt(j) == line3.charAt(i)) {
result = result + line2.charAt(j);
break;
} else if (j == len - 1) {
result = result + line3.charAt(i);
}
}
}
}
pw.print(result);
}
private static void Qsort(int[] array, int low, int high) {
int i = low;
int j = high;
int x = array[low + (high - low) / 2];
do {
while (array[i] < x) ++i;
while (array[j] > x) --j;
if (i <= j) {
int tmp = array[i];
array[i] = array[j];
array[j] = tmp;
i++;
j--;
}
} while (i <= j);
if (low < j) Qsort(array, low, j);
if (i < high) Qsort(array, i, high);
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
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();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 93e8b88f8248fa2f2d02b5c5d642e85a | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
//PLEASE HACK MY SOLUTION IT IS EASY TO UNDERSTAND
public static void main(String[] args) {
StdIn in = new StdIn();
String original=in.next();
String after=in.next();
String toTransform=in.next();
char[] transforms = new char[26];
for(int i=0; i<26; ++i)
transforms[original.charAt(i)-'a']=after.charAt(i);
String afterTransform="";
for(char c : toTransform.toCharArray())
if(c>='a')
afterTransform+=transforms[c-'a'];
else if(c>='A')
afterTransform+=(char)(transforms[c-'A']-32);
else
afterTransform+=c;
System.out.println(afterTransform);
}
interface Input {
public String next();
public String nextLine();
public int nextInt();
public long nextLong();
public double nextDouble();
}
static class StdIn implements Input {
final private int BUFFER_SIZE = 1 << 16;
final private int STRING_SIZE = 1 << 11;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public StdIn() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public StdIn(String filename) {
try{
din = new DataInputStream(new FileInputStream(filename));
} catch(Exception e) {
throw new RuntimeException();
}
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String next() {
byte[] buf = new byte[STRING_SIZE]; // string length
int cnt = 0, c;
while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
while (c != -1)
{
if (c == ' ' || c == '\n'||c=='\r')
break;
buf[cnt++] = (byte) c;
c=read();
}
return new String(buf, 0, cnt);
}
public String nextLine() {
byte[] buf = new byte[STRING_SIZE]; // line length
int cnt = 0, c;
while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
while (c != -1)
{
if (c == '\n'||c=='\r')
break;
buf[cnt++] = (byte) c;
c = read();
}
return new String(buf, 0, cnt);
}
public int nextInt() {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public int[] readIntArray(int n) {
int[] ar = new int[n];
for(int i=0; i<n; ++i)
ar[i]=nextInt();
return ar;
}
public long nextLong() {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() {
try{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
} catch(IOException e) {
throw new RuntimeException();
}
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 5d776079c9fe8bfffde80e06c43aebb4 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
*
* @author APELTOP
*/
public class B831 {
public static void main(String[] args) {
B831 b = new B831();
String str = new String();
Map<Character, Integer> map;
ArrayList array;
Scanner sc = new Scanner(System.in);
String FLine = sc.nextLine();
String SLine = sc.nextLine();
String TLine = sc.nextLine();
map = b.conversionToMap(FLine);
array = b.conversionToArray(SLine);
for (int i = 0; i < TLine.length(); i++) {
if (Character.isDigit(TLine.charAt(i))) {
str += TLine.charAt(i);
} else if (Character.isUpperCase(TLine.charAt(i)) == true) {
str += Character.toUpperCase(b.returnChar(b.returnIndex(Character.toLowerCase(TLine.charAt(i)), map), array));
} else if (b.returnIndex(TLine.charAt(i), map) == -1) {
continue;
} else {
str += b.returnChar(b.returnIndex(TLine.charAt(i), map), array);
}
}
System.out.println(str);
}
public char returnChar(int index, ArrayList array) {
return (char) array.get(index);
}
public int returnIndex(char ch, Map<Character, Integer> map) {
for (Map.Entry<Character, Integer> entry : map.entrySet()) {
Character key = entry.getKey();
Integer value = entry.getValue();
if (key.equals(ch)) {
return value;
}
}
return -1;
}
public ArrayList conversionToArray(String str) {
ArrayList array = new ArrayList();
for (int i = 0; i < str.length(); i++) {
array.add(str.charAt(i));
}
return array;
}
public Map<Character, Integer> conversionToMap(String str) {
int count = 0;
Map<Character, Integer> map = new HashMap<>();
for (int i = 0; i < str.length(); i++) {
map.put(str.charAt(i), count++);
}
return map;
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | e1b3f17bc79e331d76fa9a9551241c9f | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes |
import java.util.Scanner;
public class prob1 {
public String read (String firstLayout,String secLayout ,String txtLayout ) {
String ans = new String();
for (int i = 0 ; i<txtLayout.length();i++) {
for (int j =0;j<firstLayout.length() && Character.isLetter(txtLayout.charAt(i));j++) {
if (txtLayout.charAt(i)==firstLayout.charAt(j) || Character.toLowerCase(txtLayout.charAt(i)) == firstLayout.charAt(j)) {
if(Character.isLowerCase(txtLayout.charAt(i))) {
ans+=secLayout.charAt(j);}
else {
ans+= Character.toUpperCase(secLayout.charAt(j));
}
}
}
if (!Character.isLetter(txtLayout.charAt(i))) {
ans+=txtLayout.charAt(i);
}
}
return ans;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String first = in.nextLine();
String Sec = in.nextLine();
String txt = in.nextLine();
prob1 p1 = new prob1();
String out = p1.read(first, Sec, txt);
System.out.println(out);
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 639aef86e3d6af7103609784461c8512 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.LinkedList;
import java.util.Scanner;
public class KeyboardLayouts {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
char[] w = new char[26];
String key1 = s.nextLine();
String key2 = s.nextLine();
String word = s.nextLine();
for (int i = 0; i < 26; i++) {
if (key1.charAt(i) < 97) {
// upper case
w[key1.charAt(i) - 65] = key2.charAt(i);
} else {
// lower case
w[key1.charAt(i) - 97] = key2.charAt(i);
}
}
for (int i = 0; i < word.length(); i++) {
char z = word.charAt(i);
char x ;
if (z < 97 && z > 64) {
// upper case
x = w[z - 65];
System.out.print(Character.toUpperCase(x));
} else if (z >= 97 && z <= 123){
// lower case
x = w[z - 97];
System.out.print(x);
} else {
System.out.print(z);
}
}
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | a0ccd35e4fd191fe16cb79cd14137e90 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.LinkedList;
import java.util.Scanner;
public class KeyboardLayouts {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
char[] w = new char[26];
String key1 = s.nextLine();
String key2 = s.nextLine();
String word = s.nextLine();
for (int i = 0; i < 26; i++) {
if (key1.charAt(i) < 97) {
// upper case
w[key1.charAt(i) - 65] = key2.charAt(i);
} else {
// lower case
w[key1.charAt(i) - 97] = key2.charAt(i);
}
}
for (int i = 0; i < word.length(); i++) {
char z = word.charAt(i);
char x ;
if (z < 97 && z > 64) {
// upper case
x = w[z - 65];
System.out.print(Character.toUpperCase(x));
} else if (z >= 97 && z <= 123){
// lower case
x = w[z - 97];
System.out.print(x);
} else {
System.out.print(z);
}
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 4b04a6198f34d3c493710eed7b4baac1 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class test
{
public static void main(String [] args){
// int n=0;
// int m=0;
// Scanner scanner = new Scanner(System.in);
// n=scanner.nextInt();
// m=scanner.nextInt();
// int smallest=0;
// if (n>m){
// smallest=m;
// }
// else{
// smallest=n;
// }
// if(smallest%2==0){
// System.out.println("Malvika");
// }
// else{
// System.out.println("Akshat");
// }
Scanner scanner = new Scanner(System.in);
String first = scanner.next();
String second = scanner.next();
String sentence = scanner.next();
String finalSrrng="";
for (int i=0;i<sentence.length();i++){
if(Character.isDigit(sentence.charAt(i))==true){
finalSrrng+=sentence.charAt(i);
continue;
}
for (int j =0;j<26;j++){
if(sentence.charAt(i)==first.charAt(j)){
finalSrrng+=second.charAt(j);
break;
}
else if (Character.toLowerCase(sentence.charAt(i))==first.charAt(j)){
finalSrrng+=Character.toUpperCase(second.charAt(j));
break;
}
}
}
System.out.println(finalSrrng);
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 6c42f0f47c197fd30a31ab0ce5e1c6b8 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class keyboardLayout {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String x, y, z;
x = scan.nextLine();
y = scan.nextLine();
z = scan.nextLine();
for (int i = 0; i < z.length(); i++) {
for (int j = 0; j < x.length(); j++) {
Character c = z.charAt(i);
if (Character.toLowerCase(c) == x.charAt(j)) {
if (Character.isUpperCase(c)) {
System.out.print(Character.toUpperCase(y.charAt(j)));
} else {
System.out.print(y.charAt(j));
}
break;
} else if (Character.isDigit(c)) {
System.out.print(c);
break;
}
}
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | e1ce2c7db9e1cd8a74e457d9583f52eb | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class keyboardLayout {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String x, y, z;
x = scan.nextLine();
y = scan.nextLine();
z = scan.nextLine();
for (int i = 0; i < z.length(); i++) {
for (int j = 0; j < x.length(); j++) {
Character c = z.charAt(i);
if (Character.toLowerCase(c) == x.charAt(j)) {
if (Character.isUpperCase(c)) {
System.out.print(Character.toUpperCase(y.charAt(j)));
} else {
System.out.print(y.charAt(j));
}
break;
} else if (Character.isDigit(c)) {
System.out.print(c);
break;
}
}
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | ec07000d18dbb3b09059e448f1f4b7a5 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author KCc
*/
public class ACM2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String first ;
String second;
String req;
String req2 ;
Scanner s = new Scanner(System.in);
first = s.nextLine();
second = s.nextLine();
req = s.nextLine();
req2 = req;
StringBuilder res = new StringBuilder();
for (int i = 0 ; i < req.length(); i++){
if (Character.isDigit(req.charAt(i))){
res.append(req.charAt(i));
}
Character x = Character.toLowerCase(req.charAt(i));
int in = first.indexOf(x);
if (Character.isUpperCase(req2.charAt(i))){
res.append(Character.toUpperCase(second.charAt(in)));
}else if (Character.isLowerCase(req2.charAt(i))){
res.append(Character.toLowerCase(second.charAt(in)));
}
}
System.out.println(res.toString());
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 02652f4072f8287e9af059011d762dfc | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author KCc
*/
public class ACM2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String first ;
String second;
String req;
String req2 ;
Scanner s = new Scanner(System.in);
first = s.nextLine();
second = s.nextLine();
req = s.nextLine();
req2 = req;
StringBuilder res = new StringBuilder();
for (int i = 0 ; i < req.length(); i++){
if (Character.isDigit(req.charAt(i))){
res.append(req.charAt(i));
}
Character x = Character.toLowerCase(req.charAt(i));
int in = first.indexOf(x);
if (Character.isUpperCase(req2.charAt(i))){
res.append(Character.toUpperCase(second.charAt(in)));
}else if (Character.isLowerCase(req2.charAt(i))){
res.append(Character.toLowerCase(second.charAt(in)));
}
}
System.out.println(res.toString());
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | d037752f82a7aacef29aa293fbc0d6fd | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author KCc
*/
public class ACM2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String first ;
String second;
String req;
String req2 ;
Scanner s = new Scanner(System.in);
first = s.nextLine();
second = s.nextLine();
req = s.nextLine();
req2 = req;
StringBuilder res = new StringBuilder();
for (int i = 0 ; i < req.length(); i++){
if (Character.isDigit(req.charAt(i))){
res.append(req.charAt(i));
}
Character x = Character.toLowerCase(req.charAt(i));
int in = first.indexOf(x);
if (Character.isUpperCase(req2.charAt(i))){
res.append(Character.toUpperCase(second.charAt(in)));
}else if (Character.isLowerCase(req2.charAt(i))){
res.append(Character.toLowerCase(second.charAt(in)));
}
}
System.out.println(res.toString());
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | f8e5de84cf67c4f690d9de14b89fb76a | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class BKeyboardLayouts {
public static String result(String first, String second, String third){
char[] t = third.toCharArray();
String word = "";
char c;
boolean isUpper = false;
for(int i = 0; i < t.length; i++){
if(Character.isUpperCase(t[i])){
isUpper = true;
t[i] = Character.toLowerCase(t[i]);
}
if(Character.isDigit(t[i])){
word += t[i];
continue;
}
int index = first.indexOf(t[i]);
if(index != -1 && !isUpper){
word += second.charAt(index);
}else if(index != -1 && isUpper){
c = Character.toUpperCase(second.charAt(index));
word += c;
isUpper = false;
}
}
return word;
}
public static void main(String[] args) {
String f;
String s;
String t;
Scanner scan = new Scanner(System.in);
f = scan.nextLine();
s = scan.nextLine();
t = scan.nextLine();
System.out.println(BKeyboardLayouts.result(f, s, t));
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 3497c851daeda2dc3643cf99794422c0 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class BKeyboardLayouts {
public static String result(String first, String second, String third){
char[] t = third.toCharArray();
String word = "";
char c;
boolean isUpper = false;
for(int i = 0; i < t.length; i++){
if(Character.isUpperCase(t[i])){
isUpper = true;
t[i] = Character.toLowerCase(t[i]);
}
if(Character.isDigit(t[i])){
word += t[i];
continue;
}
int index = first.indexOf(t[i]);
if(index != -1 && !isUpper){
word += second.charAt(index);
}else if(index != -1 && isUpper){
c = Character.toUpperCase(second.charAt(index));
word += c;
isUpper = false;
}
}
return word;
}
public static void main(String[] args) {
String f;
String s;
String t;
Scanner scan = new Scanner(System.in);
f = scan.nextLine();
s = scan.nextLine();
t = scan.nextLine();
System.out.println(BKeyboardLayouts.result(f, s, t));
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 6662b17bb3d1cdd47f925ac8c4475143 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
/**
*
* @author myoun
*/
public class ProblemSolver {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input=new Scanner(System.in);
String first,second,result;
char F_layout[]=new char[30];
char S_layout[]=new char[30];
first=input.next();
second=input.next();
result=input.next();
char R_arr[]=new char[result.length()];
F_layout=first.toCharArray();
S_layout=second.toCharArray();
R_arr=result.toCharArray();
result="";
int index=0;
char l;
int upCase=0;
for (int i = 0; i <R_arr.length; i++)
{
if(Character.isDigit(R_arr[i]))
result+=R_arr[i];
else if(Character.isLetter(R_arr[i]))
{
l=R_arr[i];
for (int j = 0; j < F_layout.length; j++)
{
if(F_layout[j]==Character.toLowerCase(l))
{
index=j;
break;
}
}
if(Character.isUpperCase(l))
result+=Character.toUpperCase(S_layout[index]);
else
result+=S_layout[index];
}
}
System.out.println(result);
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 2858c59866094d5215995ccbe4b13f9a | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.*;
import java.lang.String;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char[] ch1=sc.next().toCharArray();
char[] ch2=sc.next().toCharArray();
char[] ch3=sc.next().toCharArray();
char[] ch4=new char[ch3.length];
int k=0;
for(int i=0;i<ch3.length;i++){
for(int j=0;j<ch1.length;j++){
if(k<ch3.length&&ch3[i]>='a'&& ch3[i]<='z'&&ch3[i]==ch1[j]){
ch4[k++]=ch2[j];break;
}
else if(k<ch3.length&&ch3[i]>='A'&& ch3[i]<='Z'&&((ch3[i]+"").toLowerCase()).charAt(0)==ch1[j]){
ch4[k++]=((ch2[j]+"").toUpperCase()).charAt(0);break;
}
else if(k<ch3.length&&ch3[i]>='0'&&ch3[i]<='9'){
ch4[k++]=ch3[i];break;}
}
}
for(int i=0;i<ch4.length;i++)
System.out.print(ch4[i]);
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 0aeb1b12509475b056c852fedacbde7f | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.*;
import java.lang.annotation.*;
public class Main
{
public static void main(String[] args)
{
String s1,s2,s3,s4="";
Scanner in = new Scanner(System.in);
s1 = in.nextLine();
s2 = in.nextLine();
s3 = in.nextLine();
if(s1.isEmpty() || s2.isEmpty() || s3.isEmpty())System.exit(0);
char temp[] = s3.toCharArray();
boolean savedCaseState[] = new boolean[s3.length()];
for(int i=0;i<s3.length();i++){
savedCaseState[i] = isLowerCase(temp[i]);
//// System.out.println(savedCaseState[i]);
}
for(int i=0;i<s3.length();i++){
char c[] = s3.toLowerCase().toCharArray();
int index;
char tempt = '\0';
if(s1.contains(c[i] +"")){
index = s1.indexOf(c[i]);
tempt = s2.charAt(index);
if(!savedCaseState[i]){
tempt = toUpperCase(tempt);
}else{
tempt = s2.charAt(index);
}
}else{
tempt = c[i];
}
s4 += tempt;
}
//for(boolean b : savedCaseState)System.out.println(b);
System.out.println(s4);
}
public final static boolean isLowerCase(char c){
if(c>='A'&&c<='Z'){
return false;
}else{
return true;
}
}
public final static char toUpperCase(char s){
int x = (int)s;
int sub = (int)'A' - (int)'a';
char z = (char)(x+sub);
return z;
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | b10c8d4f7ecf4a2e7efcab039001c14b | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
public class Competitive_1 {
public static void main(String[] args) {
FastReader in = new FastReader();
String l1=in.next(), l2=in.next();
HashMap<Character, Character> map = new HashMap<Character, Character>();
for(int i=0; i<26; i++){
map.put(l1.charAt(i), l2.charAt(i));
map.put((char)(l1.charAt(i)-('a'-'A')), (char)(l2.charAt(i)-('a'-'A')));
}
String s = in.next();
StringBuilder ss = new StringBuilder();
for(int i=0; i<s.length(); i++){
char x = map.get(s.charAt(i))!=null ? map.get(s.charAt(i)) : s.charAt(i);
ss.append(x);
}
System.out.println(ss.toString());
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 938829abee8fc1c1b18c6deb971d7486 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class KeyboardLayouts {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
String s1=cin.next();
String s2=cin.next();
String s3=cin.next();
int num;
for(int i=0;i<s3.length();i++) {
num=s1.indexOf(s3.charAt(i));
if(Character.isDigit(s3.charAt(i))) {
System.out.print(s3.charAt(i));
continue;
}
if(Character.isUpperCase(s3.charAt(i))) {
num=s1.indexOf(Character.toLowerCase(s3.charAt(i)));
System.out.print(Character.toUpperCase(s2.charAt(num)));
}
else
{
Character.toLowerCase(s2.charAt(num));
System.out.print(s2.charAt(num));
}
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 5b007fc8d4e8743c518ab1538bd938aa | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
public class prob2 {
public static void main(String []args){
Scanner s = new Scanner(System.in);
String first = s.nextLine();
String second = s.nextLine();
String input = s.nextLine();
char [] firstArr = new char[26];
char [] secondArr = new char[26];
String output = new String();
int diff = 'a' - 'A';
for( int i = 0; i < 26; i++){
firstArr[i] = first.charAt(i);
secondArr[i] = second.charAt(i);
}
for( int i = 0; i < input.length(); i++){
boolean found = false;
boolean capital = false;
char c = input.charAt(i);
if(!(c <= '9' && c >= '0')){
if (c >= 'A' && c <='Z'){
capital = true;
c = (char) (c - 'A' +'a');
}
int index = 0;
for( int i1 = 0; i1 < 26 && !found; i1++){
if(c == firstArr[i1]){
index = i1;
found = true;
}
}
char out = 'a';
if(capital){
out = (char) (secondArr[index] + 'A' - 'a' );
}else{
out = secondArr[index];
}
output += out + "";
}else{
output += c;
}
}
System.out.println(output);
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 6681d2277958d36a5caf82433da52781 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
public class prob2 {
public static void main(String []args){
Scanner s = new Scanner(System.in);
String first = s.nextLine();
String second = s.nextLine();
String input = s.nextLine();
char [] firstArr = new char[26];
char [] secondArr = new char[26];
String output = new String();
int diff = 'a' - 'A';
for( int i = 0; i < 26; i++){
firstArr[i] = first.charAt(i);
secondArr[i] = second.charAt(i);
}
for( int i = 0; i < input.length(); i++){
boolean found = false;
boolean capital = false;
char c = input.charAt(i);
if(!(c <= '9' && c >= '0')){
if (c >= 'A' && c <='Z'){
capital = true;
c = (char) (c - 'A' +'a');
}
int index = 0;
for( int i1 = 0; i1 < 26 && !found; i1++){
if(c == firstArr[i1]){
index = i1;
found = true;
}
}
char out = 'a';
if(capital){
out = (char) (secondArr[index] + 'A' - 'a' );
}else{
out = secondArr[index];
}
output += out + "";
}else{
output += c;
}
}
System.out.println(output);
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 13f8b48d92135dba52fc6c8aa2a18f78 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class TestCodeForcesPractise {
public static void main(String[] args) {
// System.out.println((char) (+('9' - 'a') + 'A'));
Scanner sc = new Scanner(System.in);
String a = sc.next();
sc.nextLine();
String b = sc.next();
char[] A = new char[26];
char[] B = new char[26];
sc.nextLine();
String c = sc.next();
int C[] = new int[26];
for (int i = 0; i < a.length(); i++) {
A[i] = a.charAt(i);
B[i] = b.charAt(i);
C[a.charAt(i) - 'a'] = i;
}
// System.out.println(Arrays.toString(C));
String ssp = "";
for (char cc : c.toCharArray()) {
if (cc >= 'a' && cc <= 'z') {
ssp += ("" + B[C[cc - 'a']]);
} else if (cc >= 'A' && cc <= 'Z') {
ssp += ("" + (char) (B[C[cc - 'A']] - 'a' + 'A'));
} else {
ssp += ("" + cc);
}
}
System.out.println(ssp);
}
}
// 7uduGUDUUDUgudu7
// 7uduGUDUUDUgudu7 | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | b7fa69749752236e3adee204d520f5ba | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
public void solve(int testNumber, Scanner in, PrintWriter out) {
String lay1 = in.nextLine();
String lay2 = in.nextLine();
String text = in.nextLine();
Map<Character, Character> m = new HashMap<>();
for (int i = 0; i < 26; i++) {
m.put(Character.toLowerCase(lay1.charAt(i)), Character.toLowerCase(lay2.charAt(i)));
}
for (char c : text.toCharArray()) {
if (Character.isDigit(c)) {
out.print(c);
} else {
boolean up = Character.isUpperCase(c);
char newc = m.get(Character.toLowerCase(c));
if (up) {
newc = Character.toUpperCase(newc);
}
out.print(newc);
}
}
out.println();
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 900ba922fdb6e8ae7e3fd10acd78c696 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class problemb {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
String s1 = scan.nextLine();
String s2 = scan.nextLine();
boolean b1= false;
String p="";
for(int i=0;i<s2.length();i++) {
char c = s2.charAt(i);
if(Character.isDigit(c)) {
p+=c;
}else {
//System.out.println(c);
if(Character.isLowerCase(c)) {
b1=false;
}else {
b1=true;
}
c = Character.toLowerCase(c);
//System.out.println(c);
int index = s.indexOf(c);
//System.out.println(index);
char c1 = s1.charAt(index);
//System.out.println(index+ "hello ");
if(b1) {
c1 = Character.toUpperCase(c1);
}else {
c1= Character.toLowerCase(c1);
}
p +=c1;
}
}
System.out.println(p);
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 3273c9c94c05f488b1bb437970df01ff | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class problemb {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
String s1 = scan.nextLine();
String s2 = scan.nextLine();
boolean b1= false;
String p="";
for(int i=0;i<s2.length();i++) {
char c = s2.charAt(i);
if(Character.isDigit(c)) {
p+=c;
}else {
//System.out.println(c);
if(Character.isLowerCase(c)) {
b1=false;
}else {
b1=true;
}
c = Character.toLowerCase(c);
//System.out.println(c);
int index = s.indexOf(c);
//System.out.println(index);
char c1 = s1.charAt(index);
//System.out.println(index+ "hello ");
if(b1) {
c1 = Character.toUpperCase(c1);
}else {
c1= Character.toLowerCase(c1);
}
p +=c1;
}
}
System.out.println(p);
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 575ad11c71b688b6a92b12fa99cb1b0c | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes |
import java.util.HashMap;
import java.util.Scanner;
/**
*
* @author arabtech
*/
public class Bletter {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String k1, k2, word, word2 = "";
HashMap<Character, Character> map = new HashMap<Character, Character>();
Scanner s = new Scanner(System.in);
k1 = s.next();
k2 = s.next();
word = s.next();
for (int i = 0; i < k1.length(); i++) {
map.put(k1.charAt(i), k2.charAt(i));
}
for (int i = 0; i < word.length(); i++) {
char c = word.charAt(i);
char c1;
try {
c1 = map.get(Character.toLowerCase(c));
if (Character.isUpperCase(c)) {
c1 = Character.toUpperCase(c1);
}
} catch (Exception e) {
c1 = word.charAt(i);
}
word2 += c1;
}
System.out.println(word2);
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 674f0c2831063fc7ca2a21492d734cc5 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes |
import java.util.*;
import java.math.*;
import java.io.*;
public class Session1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String f , e , ch ;
f = sc.next();
e = sc.next();
ch = sc.next();
for(int i = 0 ; i < ch.length();i++)
{
if(ch.charAt(i) =='0'||ch.charAt(i) =='1'||ch.charAt(i) =='2'||ch.charAt(i) =='3'||ch.charAt(i) =='4'||ch.charAt(i) =='5'||ch.charAt(i) =='6'||ch.charAt(i) =='7'||ch.charAt(i) =='8'||ch.charAt(i) =='9')
{
System.out.print(ch.charAt(i));
}
else{
for(int j = 0 ; j < f.length();j++)
{
char capt , small ;
capt = f.charAt(j);
small = f.charAt(j);
capt = Character.toUpperCase(capt);
small = Character.toLowerCase(small);
if(ch.charAt(i) == capt){
char t = e.charAt(j);
t = Character.toUpperCase(t);
System.out.print(t);
}
else if(ch.charAt(i) == small){
char t = e.charAt(j);
t = Character.toLowerCase(t);
System.out.print(t);
}
}
}
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | ef473e0fb2f1425e5ea5fabffb8bbaea | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Hashtable;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
public static boolean isNum(String a) {
return a.equals("1") || a.equals("2") || a.equals("3") || a.equals("4") || a.equals("5") || a.equals("6") || a.equals("7") || a.equals("8") || a.equals("9") || a.equals("0");
}
public void solve(int testNumber, Scanner sn, PrintWriter out) {
String[] a = sn.next().split("");
String[] b = sn.next().split("");
String[] c = sn.next().split("");
Hashtable<String, String> tabla = new Hashtable<String, String>();
for (int i = 0; i < a.length; i++) {
tabla.put(a[i], b[i]);
}
for (int i = 0; i < c.length; i++) {
String aux = c[i];
if (!c[i].toLowerCase().equals(aux) && !isNum(c[i])) {//mayuscula
out.print(tabla.get(c[i].toLowerCase()).toUpperCase());
} else {
if (isNum(c[i])) {
out.print(c[i]);
} else {
out.print(tabla.get(c[i]));
}
}
}
out.println();
}
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | fd96f80bf0ebedd90d2d785441958fff | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.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());
}
public String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static boolean ve(int [][] matris , int i, int j)
{
for (int k = 0; k < matris.length; k++) {
for (int k2 = 0; k2 < matris.length; k2++) {
if(matris[i][k]+ matris[k2][j] == matris[i][j] )
{
return true;
}
}
}
return false;
}
static int max = 10000001;
static int [] pri = new int[max+1];
public static void sieve()
{
pri[0] = 1;
pri[1] = 1;
for(int i=2; i <=1000; i++){
if(pri[i]!=0){continue;}
for(int j=2*i; j<=1000000; j+=i){
pri[j] = i;
}
}
}
public static void mos(String a[]){
for (String x : a){
System.out.print(x+" ");
}
System.out.println();
}
public static boolean isNum(String a){
return a.equals("1")||a.equals("2")||a.equals("3")||a.equals("4")||a.equals("5")||a.equals("6")||a.equals("7")||a.equals("8")||a.equals("9")||a.equals("0");
}
public static void main(String[] args)
{
Scanner sn = new Scanner(System.in);
String []a = sn.next().split("");
String []b = sn.next().split("");
String []c = sn.next().split("");
Hashtable<String, String> tabla = new Hashtable<String,String>();
for (int i = 0; i < a.length; i++) {
tabla.put(a[i],b[i]);
}
for (int i = 0; i < c.length; i++) {
String aux = c[i];
if(!c[i].toLowerCase().equals(aux)&&!isNum(c[i])){//mayuscula
System.out.print(tabla.get(c[i].toLowerCase()).toUpperCase());
}
else{
if(isNum(c[i])){
System.out.print(c[i]);
}
else{
System.out.print(tabla.get(c[i]));
}
}
}
System.out.println();
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 0bb255b93fff12096f1660adf7b2a3e6 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.*;
import java.io.*;
public class test{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
String s1=sc.next();
String s2=sc.next();
String text=sc.next();
HashMap<Character,Character> hm=new HashMap<Character,Character>();
for(int i=0;i<26;i++){
hm.put(s1.charAt(i),s2.charAt(i));
}
StringBuilder sb=new StringBuilder("");
for(int i=0;i<text.length();i++){
char c=text.charAt(i);
if((int)c>=(int)'a' && (int)c<=(int)'z')
sb.append(hm.get(text.charAt(i)));
else if((int)c>=(int)'A' && (int)c<=(int)'Z')
sb.append((char)((int)hm.get((char)((int)c-(int)'A'+(int)'a'))-(int)'a'+(int)'A'));
else sb.append(c);
}
System.out.print(sb);
}
} | Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | b0cfc1c1a54494fa598584107a97ba6a | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | import java.util.Scanner;
public class keyboardLayouts {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String layout1 = sc.nextLine();
String layout2 = sc.nextLine();
String input = sc.nextLine();
char [] result = new char [input.length()];
boolean [] capitals = new boolean [input.length()];
String lowercaseInput = input.toLowerCase();
for (int i = 0; i<input.length(); i++){
char letter = input.charAt(i);
if (Character.isDigit(letter)){
result[i] = letter;
capitals[i] = false;
}
else{
if (Character.isUpperCase(letter)){
capitals[i] = true;
result[i] = Character.toUpperCase((layout2.charAt((layout1.indexOf(lowercaseInput.charAt(i))))));
}
else{
capitals[i] = false;
result[i] = layout2.charAt((layout1.indexOf(letter)));
}
}
}
System.out.println(result);
sc.close();
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 8aa1d4a4b586fc55789f8b9877990da7 | train_002.jsonl | 1499958300 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. | 256 megabytes | /*
* Copyright (c) 2017 SSI Schaefer Noell GmbH
*
* $Id: Solution 6:47 PM $ / $HeadURL: $
*
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* @author <a href="mailto:ivan.rykov@ssi-schaefer.ru">ivan.rykov</a>
* @version $Revision: 1227 $, $Date: 2014-08-08 09:02:22 +0400 (Fri, 08 Aug 2014) $, $Author: ir $
*/
public class P {
private static void solve() {
String base = readString();
char[] res = readString().toCharArray();
char[] str = readString().toCharArray();
StringBuilder sb = new StringBuilder("");
for (int i = 0; i < str.length; i++) {
if (Character.isLetter(str[i])) {
if (Character.isUpperCase(str[i])) {
sb.append(Character.toUpperCase((res[base.indexOf(Character.toLowerCase(str[i]))])));
} else {
sb.append(res[base.indexOf(str[i])]);
}
} else {
sb.append(str[i]);
}
}
out.print(sb);
}
private static BufferedReader in;
private static PrintWriter out;
private static StringTokenizer tok;
public static void main(String[] args) {
init();
solve();
out.close();
}
private static void init() {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
tok = new StringTokenizer("");
}
private static String readString() {
while (!tok.hasMoreTokens()) {
try {
tok = new StringTokenizer(in.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return tok.nextToken();
}
private static int readInt() {
return Integer.parseInt(readString());
}
private static long readLong() {
return Long.parseLong(readString());
}
}
| Java | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | 1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | d6f01ece3f251b7aac74bf3fd8231a80 | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. | 800 | Print the text if the same keys were pressed in the second layout. | standard output | |
PASSED | 16c7ec20daccbb07299cb784ca6555ef | train_002.jsonl | 1578665100 | There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily Β β be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example: if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$; if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then: erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union; erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments. | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.TreeSet;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author xylenox
*/
public class e {
public static void main(String[] args) {
FS in = new FS(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-->0) {
int n = in.nextInt();
TreeSet<Integer> set = new TreeSet<>();
HashMap<Integer, Integer> vals = new HashMap<>();
int[] l = new int[n];
int[] r = new int[n];
for(int i = 0; i < n; i++) {
l[i] = 2*in.nextInt()+1;
r[i] = 2*in.nextInt()+2;
set.add(l[i]);
set.add(r[i]);
vals.putIfAbsent(l[i], 0);
vals.putIfAbsent(r[i], 0);
vals.put(l[i], vals.get(l[i])+1);
vals.put(r[i], vals.get(r[i])+1);
}
HashMap<Integer, Integer> map = new HashMap<>();
int size = set.size();
for(int i = 0; i < size; i++) map.put(set.pollFirst(), i);
Node node = new Node(0, map.size());
for(int i = 0; i < n; i++) {
node.upd(map.get(l[i]), map.get(r[i]), 1);
}
int max = 0;
int num = node.num(0, map.size());
for(int i = 0; i < n; i++) {
int le = map.get(l[i]);
int ri = map.get(r[i]);
int curr = node.num(le, ri);
int tmp = num-curr;
node.upd(le, ri, -1);
curr = node.num(le, ri);
if(vals.get(l[i]) == 1 && node.num(le, le+1) == 1) curr--;
if(vals.get(r[i]) == 1 && node.num(ri, ri+1) == 1) curr--;
max = Math.max(max, tmp+curr);
node.upd(le, ri, 1);
}
System.out.println(max);
}
out.close();
}
static class Node {
int l, r, min, numMin, propD;
Node left, right;
public Node(int le, int ri) {
l = le;
r = ri;
numMin = r-l;
if(l == r-1) return;
int mid = (l+r)/2;
left = new Node(l, mid);
right = new Node(mid, r);
}
public void prop() {
if(left == null) return;
left.min += propD;
left.propD += propD;
right.min += propD;
right.propD += propD;
propD = 0;
}
public void upd(int le, int ri, int diff) {
prop();
if(le >= r || ri <= l) return;
if(le <= l && ri >= r) {
propD += diff;
min += diff;
return;
}
left.upd(le, ri, diff);
right.upd(le, ri, diff);
min = Math.min(left.min, right.min);
numMin = 0;
if(left.min == min) numMin += left.numMin;
if(right.min == min) numMin += right.numMin;
}
public int num(int le, int ri) {
if(le >= ri) return 0;
prop();
if(le >= r || ri <= l) return 0;
if(le <= l && ri >= r) {
return min != 0 ? 0 : numMin;
}
return left.num(le, ri)+right.num(le, ri);
}
}
static class FS {
BufferedReader in;
StringTokenizer token;
public FS(InputStream st) {
in = new BufferedReader(new InputStreamReader(st));
}
public String next() {
if(token == null || !token.hasMoreElements()) {
try {
token = new StringTokenizer(in.readLine());
} catch(Exception e) {}
return next();
}
return token.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["3\n4\n1 4\n2 3\n3 6\n5 7\n3\n5 5\n5 5\n5 5\n6\n3 3\n1 1\n5 5\n1 5\n2 2\n4 4"] | 4 seconds | ["2\n1\n5"] | null | Java 8 | standard input | [
"dp",
"graphs",
"constructive algorithms",
"two pointers",
"sortings",
"data structures",
"trees",
"brute force"
] | 58d7066178839b400b08f39b680da140 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$)Β β the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment β a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. | 2,300 | Print $$$t$$$ integers β the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments. | standard output | |
PASSED | c60ed36759632b749b432c04700174a6 | train_002.jsonl | 1578665100 | There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily Β β be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example: if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$; if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then: erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union; erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments. | 256 megabytes | import java.util.*;
import java.io.*;
public class e {
public static void main(String[] Args)
throws Exception
{
FS sc = new FS(System.in);
int t = sc.nextInt();
while (t-->0) {
int n = sc.nextInt();
Pair[] ps = new Pair[n*2];
int c = 0;
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
ps[c] = new Pair();
ps[c].st = true;
ps[c].i = i;
ps[c].epoc = a;
c++;
ps[c] = new Pair();
ps[c].st = false;
ps[c].i = i;
ps[c].epoc = b;
c++;
}
Arrays.sort(ps);
int tmp = 0;
int over = 0;
int[] add = new int[n];
TreeSet<Integer> ts = new TreeSet<Integer>();
for (int i = 0; i < n*2; i++) {
if (ps[i].st){
over++;
ts.add(ps[i].i);
}
else{
ts.remove(ps[i].i);
over--;
}
if (over == 0)
tmp++;
if (over == 1 && ps[i+1].st && !ps[i].st)
add[ts.first()]++;
}
int max = 0;
for (int i = 0; i < n; i++)
if (max < add[i])
max = add[i];
if (tmp == n)
tmp--;
System.out.println(max + tmp);
}
}
public static class Pair implements Comparable<Pair>{
int epoc, i;
boolean st;
public int compareTo(Pair o) {
if (epoc == o.epoc && st && !o.st)
return -1;
if (epoc == o.epoc && o.st && !st)
return 1;
return epoc - o.epoc;
}
public String toString() {
return epoc +" " +st;
}
}
public static class FS {
StringTokenizer st;
BufferedReader br;
FS(InputStream in)
throws Exception
{
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer(br.readLine());
}
String next()
throws Exception
{
if (st.hasMoreTokens())
return st.nextToken();
st = new StringTokenizer(br.readLine());
return next();
}
int nextInt()
throws Exception
{
return Integer.parseInt(next());
}
long nextLong()
throws Exception
{
return Long.parseLong(next());
}
}
}
| Java | ["3\n4\n1 4\n2 3\n3 6\n5 7\n3\n5 5\n5 5\n5 5\n6\n3 3\n1 1\n5 5\n1 5\n2 2\n4 4"] | 4 seconds | ["2\n1\n5"] | null | Java 8 | standard input | [
"dp",
"graphs",
"constructive algorithms",
"two pointers",
"sortings",
"data structures",
"trees",
"brute force"
] | 58d7066178839b400b08f39b680da140 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$)Β β the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment β a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. | 2,300 | Print $$$t$$$ integers β the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments. | standard output | |
PASSED | 173dc566a120ccc186c143ed484a0ca0 | train_002.jsonl | 1578665100 | There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily Β β be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example: if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$; if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then: erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union; erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments. | 256 megabytes | import java.io.*;
import java.util.*;
public class E {
FastScanner scanner;
PrintWriter writer;
void solve() throws IOException {
scanner = new FastScanner(System.in);
writer = new PrintWriter(System.out);
int tests = scanner.nextInt();
for (int t = 0; t < tests; t++) {
int n = scanner.nextInt();
List<Point> pts = new ArrayList<>();
for (int i = 0; i < n; i++) {
int l = scanner.nextInt();
int r = scanner.nextInt();
Point openPoint = new Point(l, true);
Point closePoint = new Point(r, false);
closePoint.openPoint = openPoint;
pts.add(openPoint);
pts.add(closePoint);
}
List<Point> lsInit = new ArrayList<>();
Collections.sort(pts);
int c = 0;
for (Point p : pts) {
if (p.open) {
c++;
if (c == 1)
lsInit.add(p);
} else
c--;
}
Set<Point> ls = new HashSet<>();
for (Point p : pts) {
if (p.open) {
if (ls.size() == 1) {
Point prevOpen = ls.iterator().next();
prevOpen.diff++;
}
ls.add(p);
} else {
ls.remove(p.openPoint);
}
}
Map<Integer, Integer> cnts = new HashMap<>();
for (Point l : lsInit)
cnts.merge(l.x, 1, Integer::sum);
for (Point l : lsInit) {
if (cnts.get(l.x) == 1)
l.diff--;
}
int maxDiff = -1;
for (Point p : pts) {
if (p.open && p.diff > maxDiff)
maxDiff = p.diff;
}
writer.println(lsInit.size() + maxDiff);
}
writer.close();
}
static class Point implements Comparable<Point> {
int x;
boolean open;
Point openPoint;
int diff;
public Point(int x, boolean open) {
this.x = x;
this.open = open;
}
@Override
public int compareTo(Point o) {
if (x != o.x)
return Integer.compare(x, o.x);
else
return -Boolean.compare(open, o.open);
}
}
public static void main(String... args) throws IOException {
new E().solve();
}
static class FastScanner {
BufferedReader br;
StringTokenizer tokenizer;
FastScanner(String fileName) throws FileNotFoundException {
this(new FileInputStream(new File(fileName)));
}
FastScanner(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
String nextLine() throws IOException {
tokenizer = null;
return br.readLine();
}
String next() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
String line = br.readLine();
if (line == null) {
return null;
}
tokenizer = new StringTokenizer(line);
}
return tokenizer.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
}
| Java | ["3\n4\n1 4\n2 3\n3 6\n5 7\n3\n5 5\n5 5\n5 5\n6\n3 3\n1 1\n5 5\n1 5\n2 2\n4 4"] | 4 seconds | ["2\n1\n5"] | null | Java 8 | standard input | [
"dp",
"graphs",
"constructive algorithms",
"two pointers",
"sortings",
"data structures",
"trees",
"brute force"
] | 58d7066178839b400b08f39b680da140 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$)Β β the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment β a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. | 2,300 | Print $$$t$$$ integers β the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments. | standard output | |
PASSED | 676533a2c2806fcc26915b5999a470d7 | train_002.jsonl | 1578665100 | There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily Β β be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example: if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$; if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then: erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union; erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments. | 256 megabytes | import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
/*
ΠΡΠΎΠΊΡΠ°ΡΡΠΈΠ½ΠΈΡΡΡ
*/
public class Main {
static FastReader in;
static PrintWriter out;
static Random rand = new Random();
static final int INF = (int) (1e9 + 10);
static final int MOD = (int) (1e9 + 7);
static final int N = (int) (5e5 + 5);
static final int M = (int) (30);
static int n;
static long[][] a;
static int[] lol;
static PriorityQueue<Integer> pq;
static void solve() {
n = in.nextInt();
a = new long[n][2];
for (int i = 0; i < n; i++) {
a[i][0] = in.nextInt();
a[i][1] = in.nextInt();
}
Arrays.sort(a, (o1, o2) -> Long.compare(o1[0], o2[0]));
lol = new int[n];
pq = new PriorityQueue<>((o1, o2) -> Long.compare(a[o1][1], a[o2][1]));
for (int i = 0; i < n; i++) {
while (!pq.isEmpty() && a[pq.peek()][1] < a[i][0]) {
pq.poll();
}
if (pq.size() == 1) {
lol[pq.peek()]++;
}
if (pq.isEmpty()) {
lol[i]--;
}
pq.add(i);
}
int best = -1;
for (int i = 0; i < n; i++) {
if (best == -1 || lol[i] > lol[best]) {
best = i;
}
}
// out.println(best);
int ans = 0;
long max = -INF;
for (int i = 0; i < n; i++) {
if (i == best) continue;
if (a[i][0] > max) {
ans++;
}
max = Math.max(max, a[i][1]);
}
out.println(ans);
}
public static void main(String[] args) throws FileNotFoundException {
in = new FastReader(System.in);
// in = new FastReader(new FileInputStream("input.txt"));
out = new PrintWriter(System.out);
// out = new PrintWriter(new FileOutputStream("output.txt"));
int q = in.nextInt();
while (q-- > 0) {
solve();
}
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
Integer nextInt() {
return Integer.parseInt(next());
}
Long nextLong() {
return Long.parseLong(next());
}
Double nextDouble() {
return Double.parseDouble(next());
}
String next() {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(nextLine());
}
return st.nextToken();
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return s;
}
}
} | Java | ["3\n4\n1 4\n2 3\n3 6\n5 7\n3\n5 5\n5 5\n5 5\n6\n3 3\n1 1\n5 5\n1 5\n2 2\n4 4"] | 4 seconds | ["2\n1\n5"] | null | Java 8 | standard input | [
"dp",
"graphs",
"constructive algorithms",
"two pointers",
"sortings",
"data structures",
"trees",
"brute force"
] | 58d7066178839b400b08f39b680da140 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$)Β β the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment β a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. | 2,300 | Print $$$t$$$ integers β the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments. | standard output | |
PASSED | 3d6abc1ab2e0fcf35714dcb13a8e83a4 | train_002.jsonl | 1578665100 | There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily Β β be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example: if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$; if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then: erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union; erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments. | 256 megabytes | import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
/*
ΠΡΠΎΠΊΡΠ°ΡΡΠΈΠ½ΠΈΡΡΡ
*/
public class Main {
static FastReader in;
static PrintWriter out;
static Random rand = new Random();
static final int INF = (int) (1e9);
static final int MOD = (int) (1e9 + 7);
static final int N = (int) (5e5 + 5);
static final int M = (int) (30);
static int n;
static long[][] a;
static int[] lol;
static PriorityQueue<Integer> pq;
static void solve() {
n = in.nextInt();
a = new long[n][2];
for (int i = 0; i < n; i++) {
a[i][0] = in.nextInt();
a[i][1] = in.nextInt();
}
Arrays.sort(a, (o1, o2) -> Long.compare(o1[0], o2[0]));
lol = new int[n];
pq = new PriorityQueue<>((o1, o2) -> Long.compare(a[o1][1], a[o2][1]));
for (int i = 0; i < n; i++) {
while (!pq.isEmpty() && a[pq.peek()][1] < a[i][0]) {
pq.poll();
}
if (pq.size() == 1) {
lol[pq.peek()]++;
}
if (pq.isEmpty()) {
lol[i]--;
}
pq.add(i);
}
int best = -1;
for (int i = 0; i < n; i++) {
if (best == -1 || lol[i] > lol[best]) {
best = i;
}
}
// out.println(best);
int ans = 0;
long max = -INF * 2;
for (int i = 0; i < n; i++) {
if (i == best) continue;
if (a[i][0] > max) {
ans++;
}
max = Math.max(max, a[i][1]);
}
out.println(ans);
}
public static void main(String[] args) throws FileNotFoundException {
in = new FastReader(System.in);
// in = new FastReader(new FileInputStream("input.txt"));
out = new PrintWriter(System.out);
// out = new PrintWriter(new FileOutputStream("output.txt"));
int q = in.nextInt();
while (q-- > 0) {
solve();
}
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
Integer nextInt() {
return Integer.parseInt(next());
}
Long nextLong() {
return Long.parseLong(next());
}
Double nextDouble() {
return Double.parseDouble(next());
}
String next() {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(nextLine());
}
return st.nextToken();
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return s;
}
}
} | Java | ["3\n4\n1 4\n2 3\n3 6\n5 7\n3\n5 5\n5 5\n5 5\n6\n3 3\n1 1\n5 5\n1 5\n2 2\n4 4"] | 4 seconds | ["2\n1\n5"] | null | Java 8 | standard input | [
"dp",
"graphs",
"constructive algorithms",
"two pointers",
"sortings",
"data structures",
"trees",
"brute force"
] | 58d7066178839b400b08f39b680da140 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$)Β β the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment β a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. | 2,300 | Print $$$t$$$ integers β the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments. | standard output | |
PASSED | c128a853efa6606c1070e1b26f5043ba | train_002.jsonl | 1578665100 | There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily Β β be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example: if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$; if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then: erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union; erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments. | 256 megabytes | import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
/*
ΠΡΠΎΠΊΡΠ°ΡΡΠΈΠ½ΠΈΡΡΡ
*/
public class Main {
static FastReader in;
static PrintWriter out;
static Random rand = new Random();
static final int INF = (int) (1e9 + 10);
static final int MOD = (int) (1e9 + 7);
static final int N = (int) (5e5 + 5);
static final int M = (int) (30);
static int n;
static int[][] a;
static int[] lol;
static PriorityQueue<Integer> pq;
static void solve() {
n = in.nextInt();
a = new int[n][2];
for (int i = 0; i < n; i++) {
a[i][0] = in.nextInt();
a[i][1] = in.nextInt();
}
Arrays.sort(a, (o1, o2) -> Integer.compare(o1[0], o2[0]));
lol = new int[n];
pq = new PriorityQueue<>((o1, o2) -> Integer.compare(a[o1][1], a[o2][1]));
for (int i = 0; i < n; i++) {
while (!pq.isEmpty() && a[pq.peek()][1] < a[i][0]) {
pq.poll();
}
if (pq.size() == 1) {
lol[pq.peek()]++;
}
if (pq.isEmpty()) {
lol[i]--;
}
pq.add(i);
}
int best = -1;
for (int i = 0; i < n; i++) {
if (best == -1 || lol[i] > lol[best]) {
best = i;
}
}
// out.println(best);
int ans = 0, max = -INF;
for (int i = 0; i < n; i++) {
if (i == best) continue;
if (a[i][0] > max) {
ans++;
}
max = Math.max(max, a[i][1]);
}
out.println(ans);
}
public static void main(String[] args) throws FileNotFoundException {
in = new FastReader(System.in);
// in = new FastReader(new FileInputStream("input.txt"));
out = new PrintWriter(System.out);
// out = new PrintWriter(new FileOutputStream("output.txt"));
int q = in.nextInt();
while (q-- > 0) {
solve();
}
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
Integer nextInt() {
return Integer.parseInt(next());
}
Long nextLong() {
return Long.parseLong(next());
}
Double nextDouble() {
return Double.parseDouble(next());
}
String next() {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(nextLine());
}
return st.nextToken();
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return s;
}
}
} | Java | ["3\n4\n1 4\n2 3\n3 6\n5 7\n3\n5 5\n5 5\n5 5\n6\n3 3\n1 1\n5 5\n1 5\n2 2\n4 4"] | 4 seconds | ["2\n1\n5"] | null | Java 8 | standard input | [
"dp",
"graphs",
"constructive algorithms",
"two pointers",
"sortings",
"data structures",
"trees",
"brute force"
] | 58d7066178839b400b08f39b680da140 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$)Β β the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment β a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. | 2,300 | Print $$$t$$$ integers β the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments. | standard output | |
PASSED | 4abeca6cb7451706d1fd24770bafb382 | train_002.jsonl | 1578665100 | There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily Β β be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example: if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$; if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then: erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union; erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments. | 256 megabytes | import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.util.ArrayList;
import java.util.stream.*;
public class E {
public Object solve () {
int N = sc.nextInt();
int [][] A = sc.nextInts(N);
return solve(N, A);
}
Object solve(int N, int [][] A) {
int H = compress(A);
SumNode S = new SumNode(2*H);
for (int [] a : A) {
for (int i : rep(2))
a[i] *= 2;
S.add(1, a[0], a[1] + 1);
}
dfs(S, 0);
List<Integer> M = new ArrayList<>();
int res = 1;
for (int i : rep(1, L.size() - 1)) {
int [] a = L.get(i-1), b = L.get(i), c = L.get(i+1);
if (b[2] == 0)
++res;
if (a[2] > 1 && b[2] == 1 && c[2] > 1)
M.add(b[1]);
}
int Y = 0;
for (int [] b : L)
Y = max(Y, b[2]);
if (Y == 1)
return res - 1;
D = unboxed(M.toArray(new Integer [M.size()]));
int R = 0;
for (int i : rep(N)) {
int T = calc(A[i][0], A[i][1]);
R = max(R, T);
}
res += R;
return res;
}
int compress (int [][] A) {
Set<Integer> H = new HashSet<>();
for (int [] a : A)
for (int b : a)
H.add(b);
int [] b = unboxed(H.toArray(new Integer[H.size()])); sort(b);
Map<Integer, Integer> K = new HashMap<>();
for (int i : rep(b.length))
K.put(b[i], i);
for (int [] a : A)
for (int i : rep(2))
a[i] = K.get(a[i]);
return b.length;
}
List<int[]> L = new ArrayList<>();
int [] D, Z;
int calc (int x, int y) {
int N = D.length;
int p = -1, q = N, m;
while (q - p > 1) {
m = (p + q) / 2;
if (x < D[m])
q = m;
else
p = m;
}
int X = q;
p = -1; q = N;
while (q - p > 1) {
m = (p + q) / 2;
if (y > D[m])
p = m;
else
q = m;
}
int Y = q;
return Y - X;
}
void dfs (SumNode S, int V) {
V += S.X;
if (S.from + 1 == S.to) {
if (Z != null && Z[2] == V)
Z[1] = S.from;
else
L.add(Z = new int [] { S.from, S.from, V });
}
else {
dfs(S.L, V);
dfs(S.R, V);
}
}
private static final int CONTEST_TYPE = 2;
private static void init () {
}
private static int [] rep (int N) { return rep(0, N); }
private static int [] rep (int S, int T) { if (S >= T) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
private static int [] unboxed (Integer [] A) { return stream(A).mapToInt(x -> x).toArray(); }
private static class SumNode {
private final SumNode L, R;
private final int from, to, m;
private long X = 0;
public SumNode (int N) { this(0, N); }
public void add (long X, int from, int to) {
assert(from >= this.from && to <= this.to && from < to);
if (from == this.from && to == this.to)
this.X += X;
else {
if (from < m)
L.add(X, from, min(to, m));
if (to > m)
R.add(X, max(from, m), to);
}
}
private SumNode (int from, int to) {
assert(from < to);
this.from = from;
this.to = to;
m = (from + to) / 2;
if (m > from) {
L = new SumNode(from, m);
R = new SumNode(m, to);
} else
L = R = null;
}
}
//////////////////////////////////////////////////////////////////////////////////// OFF
private static IOUtils.MyScanner sc = new IOUtils.MyScanner();
private static class IOUtils {
public static class MyScanner {
public String next () { newLine(); return line[index++]; }
public int nextInt () { return Integer.parseInt(next()); }
public String nextLine () { line = null; return readLine(); }
public String [] nextStrings () { return split(nextLine()); }
public int[] nextInts () { return nextStream().mapToInt(Integer::parseInt).toArray(); }
public int[][] nextInts (int N) { return IntStream.range(0, N).mapToObj(i -> nextInts()).toArray(int[][]::new); }
//////////////////////////////////////////////
private boolean eol () { return index == line.length; }
private String readLine () {
try {
return r.readLine();
} catch (Exception e) {
throw new Error (e);
}
}
private final java.io.BufferedReader r;
private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
private MyScanner (java.io.BufferedReader r) {
try {
this.r = r;
while (!r.ready())
Thread.sleep(1);
start();
} catch (Exception e) {
throw new Error(e);
}
}
private String [] line;
private int index;
private void newLine () {
if (line == null || eol()) {
line = split(readLine());
index = 0;
}
}
private java.util.stream.Stream<String> nextStream () { return java.util.Arrays.stream(nextStrings()); }
private String [] split (String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
}
private static String build (Object o, Object ... A) { return buildDelim(" ", o, A); }
private static String buildDelim (String delim, Object o, Object ... A) {
StringBuilder b = new StringBuilder();
append(b, o, delim);
for (Object p : A)
append(b, p, delim);
return b.substring(min(b.length(), delim.length()));
}
//////////////////////////////////////////////////////////////////////////////////
private static java.text.DecimalFormat formatter = new java.text.DecimalFormat("#.#########");
private static void start () { if (t == 0) t = millis(); }
private static void append (java.util.function.Consumer<Object> f, java.util.function.Consumer<Object> g, final Object o) {
if (o.getClass().isArray()) {
int len = java.lang.reflect.Array.getLength(o);
for (int i = 0; i < len; ++i)
f.accept(java.lang.reflect.Array.get(o, i));
}
else if (o instanceof Iterable<?>)
((Iterable<?>)o).forEach(f::accept);
else
g.accept(o instanceof Double ? formatter.format(o) : o);
}
private static void append (final StringBuilder b, Object o, final String delim) {
append(x -> { append(b, x, delim); }, x -> b.append(delim).append(x), o);
}
private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
private static void print (Object o, Object ... A) {
String res = build(o, A);
if (DEBUG == 2)
err(res, '(', time(), ')');
if (res.length() > 0)
pw.println(res);
if (DEBUG == 1) {
pw.flush();
System.out.flush();
}
}
private static void err (Object o, Object ... A) { System.err.println(build(o, A)); }
private static int DEBUG;
private static void exit () {
String end = "------------------" + System.lineSeparator() + time();
switch(DEBUG) {
case 1: print(end); break;
case 2: err(end); break;
}
IOUtils.pw.close();
System.out.flush();
System.exit(0);
}
private static long t;
private static long millis () { return System.currentTimeMillis(); }
private static String time () { return "Time: " + (millis() - t) / 1000.0; }
private static void run (int N) {
try { DEBUG = Integer.parseInt(System.getProperties().get("DEBUG").toString()); }
catch (Throwable t) {}
for (int n = 1; n <= N; ++n) {
Object res = new E().solve();
if (res != null) {
@SuppressWarnings("all")
Object o = CONTEST_TYPE == 0 ? "Case #" + n + ": " + build(res) : res;
print(o);
}
}
exit();
}
}
////////////////////////////////////////////////////////////////////////////////////
public static void main (String[] args) {
init();
@SuppressWarnings("all")
int N = CONTEST_TYPE == 1 ? 1 : sc.nextInt();
IOUtils.run(N);
}
}
| Java | ["3\n4\n1 4\n2 3\n3 6\n5 7\n3\n5 5\n5 5\n5 5\n6\n3 3\n1 1\n5 5\n1 5\n2 2\n4 4"] | 4 seconds | ["2\n1\n5"] | null | Java 8 | standard input | [
"dp",
"graphs",
"constructive algorithms",
"two pointers",
"sortings",
"data structures",
"trees",
"brute force"
] | 58d7066178839b400b08f39b680da140 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$)Β β the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment β a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. | 2,300 | Print $$$t$$$ integers β the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments. | standard output | |
PASSED | 7fadeec06d713733d9367fd01e8e1052 | train_002.jsonl | 1578665100 | There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily Β β be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example: if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$; if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then: erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union; erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments. | 256 megabytes | import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.util.ArrayList;
import java.util.stream.*;
public class E {
public Object solve () {
int N = sc.nextInt();
int [][] A = sc.nextInts(N);
int H = compress(A);
SumNode S = new SumNode(2*H);
for (int [] a : A) {
for (int i : rep(2))
a[i] *= 2;
S.add(1, a[0], a[1] + 1);
}
dfs(S, 0);
List<int[]> L = new ArrayList<>(); int [] Z = null; int Y = 0;
for (int [] b : B) {
if (Z != null && Z[2] == b[2])
Z[1] = b[1];
else
L.add(Z = b);
Y = max(Y, b[2]);
}
List<Integer> M = new ArrayList<>();
int res = 1;
for (int i : rep(1, L.size() - 1)) {
int [] a = L.get(i-1), b = L.get(i), c = L.get(i+1);
if (b[2] == 0)
++res;
if (a[2] > 1 && b[2] == 1 && c[2] > 1)
M.add(b[1]);
}
if (Y == 1)
return res - 1;
D = unboxed(M.toArray(new Integer [M.size()]));
int R = 0;
for (int i : rep(N)) {
int T = calc(A[i][0], A[i][1]);
R = max(R, T);
}
res += R;
return res;
}
int compress (int [][] A) {
Set<Integer> H = new HashSet<>();
for (int [] a : A)
for (int b : a)
H.add(b);
int [] b = unboxed(H.toArray(new Integer[H.size()])); sort(b);
Map<Integer, Integer> K = new HashMap<>();
for (int i : rep(b.length))
K.put(b[i], i);
for (int [] a : A)
for (int i : rep(2))
a[i] = K.get(a[i]);
return b.length;
}
List<int[]> B = new ArrayList<>();
int [] D;
int calc (int x, int y) {
int N = D.length;
int p = -1, q = N, m;
while (q - p > 1) {
m = (p + q) / 2;
if (x < D[m])
q = m;
else
p = m;
}
int X = q;
p = -1; q = N;
while (q - p > 1) {
m = (p + q) / 2;
if (y > D[m])
p = m;
else
q = m;
}
int Y = q;
return Y - X;
}
void dfs(SumNode S, int V) {
V += S.X;
if (S.from + 1 == S.to)
B.add(new int [] { S.from, S.from, V });
else {
dfs(S.L, V);
dfs(S.R, V);
}
}
private static final int CONTEST_TYPE = 2;
private static void init () {
}
private static int [] rep (int N) { return rep(0, N); }
private static int [] rep (int S, int T) { if (S >= T) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
private static int [] unboxed (Integer [] A) { return stream(A).mapToInt(x -> x).toArray(); }
private static class SumNode {
private final SumNode L, R;
private final int from, to, m;
private long X = 0;
public SumNode (int N) { this(0, N); }
public void add (long X, int from, int to) {
assert(from >= this.from && to <= this.to && from < to);
if (from == this.from && to == this.to)
this.X += X;
else {
if (from < m)
L.add(X, from, min(to, m));
if (to > m)
R.add(X, max(from, m), to);
}
}
private SumNode (int from, int to) {
assert(from < to);
this.from = from;
this.to = to;
m = (from + to) / 2;
if (m > from) {
L = new SumNode(from, m);
R = new SumNode(m, to);
} else
L = R = null;
}
}
//////////////////////////////////////////////////////////////////////////////////// OFF
private static IOUtils.MyScanner sc = new IOUtils.MyScanner();
private static class IOUtils {
public static class MyScanner {
public String next () { newLine(); return line[index++]; }
public int nextInt () { return Integer.parseInt(next()); }
public String nextLine () { line = null; return readLine(); }
public String [] nextStrings () { return split(nextLine()); }
public int[] nextInts () { return nextStream().mapToInt(Integer::parseInt).toArray(); }
public int[][] nextInts (int N) { return IntStream.range(0, N).mapToObj(i -> nextInts()).toArray(int[][]::new); }
//////////////////////////////////////////////
private boolean eol () { return index == line.length; }
private String readLine () {
try {
return r.readLine();
} catch (Exception e) {
throw new Error (e);
}
}
private final java.io.BufferedReader r;
private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
private MyScanner (java.io.BufferedReader r) {
try {
this.r = r;
while (!r.ready())
Thread.sleep(1);
start();
} catch (Exception e) {
throw new Error(e);
}
}
private String [] line;
private int index;
private void newLine () {
if (line == null || eol()) {
line = split(readLine());
index = 0;
}
}
private java.util.stream.Stream<String> nextStream () { return java.util.Arrays.stream(nextStrings()); }
private String [] split (String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
}
private static String build (Object o, Object ... A) { return buildDelim(" ", o, A); }
private static String buildDelim (String delim, Object o, Object ... A) {
StringBuilder b = new StringBuilder();
append(b, o, delim);
for (Object p : A)
append(b, p, delim);
return b.substring(min(b.length(), delim.length()));
}
//////////////////////////////////////////////////////////////////////////////////
private static java.text.DecimalFormat formatter = new java.text.DecimalFormat("#.#########");
private static void start () { if (t == 0) t = millis(); }
private static void append (java.util.function.Consumer<Object> f, java.util.function.Consumer<Object> g, final Object o) {
if (o.getClass().isArray()) {
int len = java.lang.reflect.Array.getLength(o);
for (int i = 0; i < len; ++i)
f.accept(java.lang.reflect.Array.get(o, i));
}
else if (o instanceof Iterable<?>)
((Iterable<?>)o).forEach(f::accept);
else
g.accept(o instanceof Double ? formatter.format(o) : o);
}
private static void append (final StringBuilder b, Object o, final String delim) {
append(x -> { append(b, x, delim); }, x -> b.append(delim).append(x), o);
}
private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
private static void print (Object o, Object ... A) {
String res = build(o, A);
if (DEBUG == 2)
err(res, '(', time(), ')');
if (res.length() > 0)
pw.println(res);
if (DEBUG == 1) {
pw.flush();
System.out.flush();
}
}
private static void err (Object o, Object ... A) { System.err.println(build(o, A)); }
private static int DEBUG;
private static void exit () {
String end = "------------------" + System.lineSeparator() + time();
switch(DEBUG) {
case 1: print(end); break;
case 2: err(end); break;
}
IOUtils.pw.close();
System.out.flush();
System.exit(0);
}
private static long t;
private static long millis () { return System.currentTimeMillis(); }
private static String time () { return "Time: " + (millis() - t) / 1000.0; }
private static void run (int N) {
try { DEBUG = Integer.parseInt(System.getProperties().get("DEBUG").toString()); }
catch (Throwable t) {}
for (int n = 1; n <= N; ++n) {
Object res = new E().solve();
if (res != null) {
@SuppressWarnings("all")
Object o = CONTEST_TYPE == 0 ? "Case #" + n + ": " + build(res) : res;
print(o);
}
}
exit();
}
}
////////////////////////////////////////////////////////////////////////////////////
public static void main (String[] args) {
init();
@SuppressWarnings("all")
int N = CONTEST_TYPE == 1 ? 1 : sc.nextInt();
IOUtils.run(N);
}
}
| Java | ["3\n4\n1 4\n2 3\n3 6\n5 7\n3\n5 5\n5 5\n5 5\n6\n3 3\n1 1\n5 5\n1 5\n2 2\n4 4"] | 4 seconds | ["2\n1\n5"] | null | Java 8 | standard input | [
"dp",
"graphs",
"constructive algorithms",
"two pointers",
"sortings",
"data structures",
"trees",
"brute force"
] | 58d7066178839b400b08f39b680da140 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$)Β β the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment β a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. | 2,300 | Print $$$t$$$ integers β the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments. | standard output | |
PASSED | 343767c5b4022749eec3e736193e5515 | train_002.jsonl | 1578665100 | There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily Β β be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example: if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$; if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then: erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union; erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments. | 256 megabytes | import java.util.*;
import java.io.*;
import java.io.FileWriter;
import java.math.BigInteger;
import java.math.BigDecimal;
// Solution
public class Main
{
public static void main (String[] argv)
{
new Main();
}
boolean test = false;
final int[][] dirs8 = {{0,1}, {0,-1}, {-1,0}, {1,0}, {1,1},{1,-1},{-1,1},{-1,-1}};
final int[][] dirs4 = {{0,1}, {0,-1}, {-1,0}, {1,0}};
final int MOD = 1000000007; //998244353;
int[] fac;
int[] ifac;
int[] rfac;
int[] pow2;
int[] mobius;
int[] sieve;
int[][] factors;
final int hasEdge = 1;
final int builtEdge = 2;
final int errorEdge = 3;
int[][] b ;
boolean[] visited;
public Main() {
FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
//FastReader in = new FastReader(new BufferedReader(new FileReader("Main.in")));
int nt = in.nextInt();
//int nt = 1;
StringBuilder sb = new StringBuilder();
final int START = 0;
final int END = 1;
for (int iq = 0; iq < nt; iq++)
{
int n = in.nextInt();
//int[][] itvs = new int[n][2];
int n2 = n * 2;
int[][] events = new int[n2][3];
int[] cnts = new int[n];
int nSeg = 0;
for (int i = 0; i < n; i++)
{
int s = in.nextInt();
int e = in.nextInt();
events[i*2][0] = s;
events[i*2][1] = i;
events[i*2][2] = START;
events[i*2+1][0] = e;
events[i*2+1][1] = i;
events[i*2+1][2] = END;
}
int[] sk = new int[n];
int sz = 0;
boolean[] done = new boolean[n];
int flying = 0;
Arrays.sort(events, (x,y)->(x[0] != y[0] ? Integer.compare(x[0], y[0]) : x[2] - y[2]));
for (int i = 0, j = 0; i < n2; )
{
int x = events[i][0];
j = i;
boolean hasEnd = false;
//System.out.println("Woring on x = " + x);
while (j < n2 && events[j][0] == x)
{
if (events[j][2] == START)
{
flying++;
sk[sz++] = events[j][1];
//System.out.println("Start of interval " + events[j][1] + ", flying = " + flying);
}else {
hasEnd = true;
flying--;
int id = events[j][1];
done[id] = true;
//System.out.println("End of interval " + events[j][1] + ", flying = " + flying);
}
//update j
j++;
}
//System.out.println("flying = " + flying);
if (flying == 0) nSeg++;
else if (flying == 1 && hasEnd)
{
while (done[sk[sz-1]])
sz--;
int id = sk[sz-1];
//System.out.println("Flying = " + flying + ", id = " + id);
if (j < n2 && events[j][1] != id) {
cnts[id]++;
//System.out.println("cnts = " + cnts[id]);
}
}
//update i
i = j;
}
//System.out.println("nseg = " + nSeg);
int maxCnt = 0;
for (int v : cnts) maxCnt = Math.max(maxCnt, v);
int ans = maxCnt + nSeg;
if (nSeg == n) ans = n - 1;
sb.append(ans + "\n");
}
System.out.print(sb);
}
private void dfs(StringBuilder sb, int node, int par)
{
}
class Edge{
int p, q;
boolean used;
public Edge(int pp, int qq)
{
p = pp;
q = qq;
used = false;
}
}
class Node implements Comparable<Node>{
int id;
long gain;
public Node(int id, long gain)
{
this.id = id;
this.gain = gain;
}
@Override
public int compareTo(Node o){
return Long.compare(gain, o.gain);
}
}
private long[][] matIdentity(int n)
{
long[][] a = new long[n][n];
for (int i = 0; i < n; i++)
a[i][i] = 1;
return a;
}
private long[][] matPow(long[][] mat0, long p)
{
int n = mat0.length;
long[][] ans = matIdentity(n);
long[][] mat = matCopy(mat0);
while (p > 0)
{
if (p % 2 == 1){
ans = matMul(ans, mat);
}
p /= 2;
mat = matMul(mat, mat);
}
return ans;
}
private long[][] matCopy(long[][] a)
{
int n = a.length;
long[][] b = new long[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
b[i][j] = a[i][j];
return b;
}
private long[][] matMul(long[][] a, long[][] b)
{
int n = a.length;
long[][] c = new long[n][n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
for (int k = 0; k < n; k++)
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD;
}
}
return c;
}
private long[] matMul(long[][] a, long[] b)
{
int n = a.length;
long[] c = new long[n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
c[i] = (c[i] + a[i][j] * b[j]) % MOD;
}
return c;
}
class Mark implements Comparable<Mark> {
int type, h;
long x;
public Mark(int h, long x, int type)
{
this.h = h;
this.x = x;
this.type = type;
}
@Override
public int compareTo(Mark o)
{
if (this.x == o.x) return type - o.type; // let end comes before start
return Long.compare(x, o.x);
}
}
private boolean coLinear(int[] p, int[] q, int[] r)
{
return 1L * (p[1] - r[1]) * (q[0] - r[0]) == 1L * (q[1] - r[1]) * (p[0] - r[0]);
}
private void fill(char[] a, int lo, int c, char letter)
{
//System.out.println("fill " + lo + " " + c + " " + letter);
for (int i = lo; i < lo + c; i++) a[i] = letter;
}
private int cntBitOne(String s){
int c = 0, n = s.length();
for (int i = 0; i < n; i++)
if (s.charAt(i) == '1') c++;
return c;
}
class DSU {
int n;
int[] par;
int[] sz;
int nGroup;
public DSU(int n)
{
this.n = n;
par = new int[n];
sz = new int[n];
for (int i = 0; i < n; i++){
par[i] = i;
sz[i] = 1;
}
nGroup = n;
}
private boolean add(int p, int q) {
int rp = find(p);
int rq = find(q);
if (rq == rp) return false;
if (sz[rp] <= sz[rq]) {
sz[rq] += sz[rp];
par[rp] = rq;
}else {
sz[rp] += sz[rq];
par[rq] = rp;
}
nGroup--;
return true;
}
private int find(int p)
{
int r = p;
while (par[r] != r) r = par[r];
while (r != p) {
int t = par[p];
par[p] = r;
p = t;
}
return r;
}
}
// ΞΌ(n) = 1 if n is a square-free positive integer with an even number of prime factors. e.g. 6, 15
// ΞΌ(n) = β1 if n is a square-free positive integer with an odd number of prime factors. e.g. 2, 3, 5, 2*3*5
// ΞΌ(n) = 0 if n has a squared prime factor. e.g : 2*2, 3*3*5
private void build_pow2_function(int n)
{
pow2 = new int[n+1];
pow2[0] = 1;
for (int i = 1; i <= n; i++) pow2[i] = (int)(1L * pow2[i-1] * 2 % MOD);
}
private void build_fac_function(int n)
{
fac = new int[n+1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = (int)(1L * fac[i-1] * i % MOD);
}
private void build_ifac_function(int n)
{
ifac = new int[n+1];
ifac[0] = 1;
for (int i = 1; i <= n; i++)
ifac[i] = (int)(1L * ifac[i-1] * inv(i) % MOD);
}
private void build_sieve_function(int n)
{
sieve = new int[n+1];
for (int i = 2; i <= n; i++)
sieve[i] = i;
for (int i = 2; i <= n; i++)
{
if (sieve[i] == i){
for (long j = 1L * i * i; j <= n; j += i)
sieve[(int)j] = i;
}
}
}
private void build_mobius_function(int n)
{
mobius = new int[n+1];
sieve = new int[n+1];
factors = new int[n+1][];
//for (int i = 1; i <= n; i++)factors[i] = new ArrayList<>();
for (int i = 2; i <= n; i++)
sieve[i] = i;
for (int i = 2; i <= n; i++)
{
if (sieve[i] == i){
mobius[i] = -1;
for (long j = 1L * i * i; j <= n; j += i)
sieve[(int)j] = i;
}
}
for (int i = 6; i <= n; i++)
{
if (sieve[i] != i) {
int pre = i / sieve[i];
if (pre % sieve[i] != 0)
mobius[i] = -mobius[pre];
}
}
int[] sz = new int[n+1];
long tot = 0;
for (int i = 2; i <= n; i++)
{
if (mobius[i] != 0)
{
for (int j = i * 2; j <= n; j += i) {
sz[j]++;
tot++;
}
}
}
for (int i = 2; i <= n; i++) {
factors[i] = new int[sz[i]];
sz[i] = 0;
}
for (int i = 2; i <= n; i++)
{
if (mobius[i] != 0)
{
for (int j = i * 2; j <= n; j += i) {
factors[j][sz[j]++] = i;
//factors[j].add(i);
}
}
}
//System.out.println("tot = " + tot);
}
private int[] build_z_function(String s)
{
int n = s.length();
int[] zfun = new int[n];
int l = -1, r = -1;
for (int i = 1; i < n; i++)
{
// Set the start value
if (i <= r)
zfun[i] = Math.min(zfun[i-l], r - i + 1);
while (i + zfun[i] < n && s.charAt(i + zfun[i]) == s.charAt(zfun[i]))
zfun[i]++;
if (i + zfun[i] - 1> r){
l = i;
r = i + zfun[i] - 1;
}
}
if (test)
{
System.out.println("Z-function of " + s);
for (int i = 0; i < n; i++) System.out.print(zfun[i] + " ");
System.out.println();
}
return zfun;
}
class BIT {
int[] bit;
int n;
public BIT(int n){
this.n = n;
bit = new int[n+1];
}
private int query(int p)
{
int sum = 0;
for (; p > 0; p -= (p & (-p)))
sum += bit[p];
return sum;
}
private void add(int p, int val)
{
//System.out.println("add to BIT " + p);
for (; p <= n; p += (p & (-p)))
bit[p] += val;
}
}
private List<Integer> getMinFactor(int sum)
{
List<Integer> factors = new ArrayList<>();
for (int sz = 2; sz <= sum / sz; sz++){
if (sum % sz == 0) {
factors.add(sz);
factors.add(sum / sz);
}
}
if (factors.size() == 0)
factors.add(sum);
return factors;
}
/* Tree class */
class Tree {
int V = 0;
int root = 0;
List<Integer>[] nbs;
int[][] timeRange;
int[] subTreeSize;
int t;
boolean dump = false;
public Tree(int V, int root)
{
if (dump)
System.out.println("build tree with size = " + V + ", root = " + root);
this.V = V;
this.root = root;
nbs = new List[V];
subTreeSize = new int[V];
for (int i = 0; i < V; i++)
nbs[i] = new ArrayList<>();
}
public void doneInput()
{
dfsEuler();
}
public void addEdge(int p, int q)
{
nbs[p].add(q);
nbs[q].add(p);
}
private void dfsEuler()
{
timeRange = new int[V][2];
t = 1;
dfs(root);
}
private void dfs(int node)
{
if (dump)
System.out.println("dfs on node " + node + ", at time " + t);
timeRange[node][0] = t;
for (int next : nbs[node]) {
if (timeRange[next][0] == 0)
{
++t;
dfs(next);
}
}
timeRange[node][1] = t;
subTreeSize[node] = t - timeRange[node][0] + 1;
}
public List<Integer> getNeighbors(int p) {
return nbs[p];
}
public int[] getSubTreeSize(){
return subTreeSize;
}
public int[][] getTimeRange()
{
if (dump){
for (int i = 0; i < V; i++){
System.out.println(i + ": " + timeRange[i][0] + " - " + timeRange[i][1]);
}
}
return timeRange;
}
}
/* segment tree */
class SegTree {
int[] a;
int[] tree;
int[] treeMin;
int[] treeMax;
int[] lazy;
int n;
boolean dump = false;
public SegTree(int n)
{
if (dump)
System.out.println("create segTree with size " + n);
this.n = n;
treeMin = new int[n*4];
treeMax = new int[n*4];
lazy = new int[n*4];
}
public SegTree(int n, int[] a) {
this(n);
this.a = a;
buildTree(1, 0, n-1);
}
private void buildTree(int node, int lo, int hi)
{
if (lo == hi) {
tree[node] = lo;
return;
}
int m = (lo + hi) / 2;
buildTree(node * 2, lo, m);
buildTree(node * 2 + 1, m + 1, hi);
pushUp(node, lo, hi);
}
private void pushUp(int node, int lo, int hi)
{
if (lo >= hi) return;
// note that, if we need to call pushUp on a node, then lazy[node] must be zero.
//the true value is the value + lazy
treeMin[node] = Math.min(treeMin[node * 2] + lazy[node * 2], treeMin[node * 2 + 1] + lazy[node * 2 + 1]);
treeMax[node] = Math.max(treeMax[node * 2] + lazy[node * 2], treeMax[node * 2 + 1] + lazy[node * 2 + 1]);
// add combine fcn
}
private void pushDown(int node, int lo, int hi)
{
if (lazy[node] == 0) return;
int lz = lazy[node];
lazy[node] = 0;
treeMin[node] += lz;
treeMax[node] += lz;
if (lo == hi) return;
int mid = (lo + hi) / 2;
lazy[node * 2] += lz;
lazy[node * 2 + 1] += lz;
}
public int rangeQueryMax(int fr, int to)
{
return rangeQueryMax(1, 0, n-1, fr, to);
}
public int rangeQueryMax(int node, int lo, int hi, int fr, int to)
{
if (lo == fr && hi == to)
return treeMax[node] + lazy[node];
int mid = (lo + hi) / 2;
pushDown(node, lo, hi);
if (to <= mid) {
return rangeQueryMax(node * 2, lo, mid, fr, to);
}else if (fr > mid)
return rangeQueryMax(node * 2 + 1, mid + 1, hi, fr, to);
else {
return Math.max(rangeQueryMax(node * 2, lo, mid, fr, mid),
rangeQueryMax(node * 2 + 1, mid + 1, hi, mid + 1, to));
}
}
public int rangeQueryMin(int fr, int to)
{
return rangeQueryMin(1, 0, n-1, fr, to);
}
public int rangeQueryMin(int node, int lo, int hi, int fr, int to)
{
if (lo == fr && hi == to)
return treeMin[node] + lazy[node];
int mid = (lo + hi) / 2;
pushDown(node, lo, hi);
if (to <= mid) {
return rangeQueryMin(node * 2, lo, mid, fr, to);
}else if (fr > mid)
return rangeQueryMin(node * 2 + 1, mid + 1, hi, fr, to);
else {
return Math.min(rangeQueryMin(node * 2, lo, mid, fr, mid),
rangeQueryMin(node * 2 + 1, mid + 1, hi, mid + 1, to));
}
}
public void rangeUpdate(int fr, int to, int delta){
rangeUpdate(1, 0, n-1, fr, to, delta);
}
public void rangeUpdate(int node, int lo, int hi, int fr, int to, int delta){
pushDown(node, lo, hi);
if (fr == lo && to == hi)
{
lazy[node] = delta;
return;
}
int m = (lo + hi) / 2;
if (to <= m)
rangeUpdate(node * 2, lo, m, fr, to, delta);
else if (fr > m)
rangeUpdate(node * 2 + 1, m + 1, hi, fr, to, delta);
else {
rangeUpdate(node * 2, lo, m, fr, m, delta);
rangeUpdate(node * 2 + 1, m + 1, hi, m + 1, to, delta);
}
// re-set the in-variant
pushUp(node, lo, hi);
}
public int query(int node, int lo, int hi, int fr, int to)
{
if (fr == lo && to == hi)
return tree[node];
int m = (lo + hi) / 2;
if (to <= m)
return query(node * 2, lo, m, fr, to);
else if (fr > m)
return query(node * 2 + 1, m + 1, hi, fr, to);
int lid = query(node * 2, lo, m, fr, m);
int rid = query(node * 2 + 1, m + 1, hi, m + 1, to);
return a[lid] >= a[rid] ? lid : rid;
}
}
private long inv(long v)
{
return pow(v, MOD-2);
}
private long pow(long v, long p)
{
long ans = 1;
while (p > 0)
{
if (p % 2 == 1)
ans = ans * v % MOD;
v = v * v % MOD;
p = p / 2;
}
return ans;
}
private double dist(double x, double y, double xx, double yy)
{
return Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));
}
private int mod_add(int a, int b) {
int v = a + b;
if (v >= MOD) v -= MOD;
return v;
}
private long overlap(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
if (x1 > x3) return overlap(x3, y3, x4, y4, x1, y1, x2, y2);
if (x3 > x2 || y4 < y1 || y3 > y2) return 0L;
//(x3, ?, x2, ?)
int yL = Math.max(y1, y3);
int yH = Math.min(y2, y4);
int xH = Math.min(x2, x4);
return f(x3, yL, xH, yH);
}
//return #black cells in rectangle
private long f(int x1, int y1, int x2, int y2) {
long dx = 1L + x2 - x1;
long dy = 1L + y2 - y1;
if (dx % 2 == 0 || dy % 2 == 0 || (x1 + y1) % 2 == 0)
return 1L * dx * dy / 2;
return 1L * dx * dy / 2 + 1;
}
private int distM(int x, int y, int xx, int yy) {
return abs(x - xx) + abs(y - yy);
}
private boolean less(int x, int y, int xx, int yy) {
return x < xx || y > yy;
}
private int mul(int x, int y) {
return (int)(1L * x * y % MOD);
}
private int nBit1(int v) {
int v0 = v;
int c = 0;
while (v != 0) {
++c;
v = v & (v - 1);
}
return c;
}
private long abs(long v) {
return v > 0 ? v : -v;
}
private int abs(int v) {
return v > 0 ? v : -v;
}
private int common(int v) {
int c = 0;
while (v != 1) {
v = (v >>> 1);
++c;
}
return c;
}
private void reverse(char[] a, int i, int j) {
while (i < j) {
swap(a, i++, j--);
}
}
private void swap(char[] a, int i, int j) {
char t = a[i];
a[i] = a[j];
a[j] = t;
}
private int gcd(int x, int y) {
if (y == 0) return x;
return gcd(y, x % y);
}
private long gcd(long x, long y) {
if (y == 0) return x;
return gcd(y, x % y);
}
private int max(int a, int b) {
return a > b ? a : b;
}
private long max(long a, long b) {
return a > b ? a : b;
}
private int min(int a, int b) {
return a > b ? b : a;
}
private long min(long a, long b) {
return a > b ? b : a;
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader(BufferedReader in)
{
br = in;
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
String line = br.readLine();
if (line == null || line.length() == 0) return "";
st = new StringTokenizer(line);
}
catch (IOException e)
{
return "";
//e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
return null;
//e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n4\n1 4\n2 3\n3 6\n5 7\n3\n5 5\n5 5\n5 5\n6\n3 3\n1 1\n5 5\n1 5\n2 2\n4 4"] | 4 seconds | ["2\n1\n5"] | null | Java 8 | standard input | [
"dp",
"graphs",
"constructive algorithms",
"two pointers",
"sortings",
"data structures",
"trees",
"brute force"
] | 58d7066178839b400b08f39b680da140 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$)Β β the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment β a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. | 2,300 | Print $$$t$$$ integers β the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments. | standard output | |
PASSED | 3fec301b7d7ff7f275144e8e6a783cd5 | train_002.jsonl | 1578665100 | There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily Β β be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example: if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$; if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then: erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union; erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments. | 256 megabytes | import javax.swing.tree.TreeCellRenderer;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
// written by luchy0120
public class Main {
public static void main(String[] args) throws Exception {
new Main().run();
}
class Pair{
int x;int y;
Pair(int x,int y){this.x = x;this.y = y;}
@Override
public int hashCode(){
return x*127+y;
}
@Override
public boolean equals(Object obj){
Pair pr = (Pair)obj;
return pr.x == x && pr.y == y;
}
}
int h[],to[],ne[],wt[];
int ct = 0;
void add(int u,int v,int w){
to[ct] = v;
// wt[ct] = w;
ne[ct] = h[u];
h[u] = ct++;
}
long gcd(long a,long b){
return b==0?a:gcd(b,a%b);
}
static int MAXN = 100000;
static long tree[];
void update(int i,long v){
while(i<tree.length){
tree[i] += v;
i += i&(-i);
}
}
long sum(int i){
long v = 0;
while(i>0){
v = v + tree[i];
i -= i&(-i);
}
return v;
}
boolean isshun(int put[]){
int len = put.length;
if(put[len-1]==14) return false;
if(put[0]==2) return false;
if(put[1]==2) return false;
for(int i=1;i<len;++i){
if(put[i]-put[i-1]!=1) return false;
}
return true;
}
boolean doubleshun(int put[]){
int len = put.length;
if(len%2==1) return false;
for(int i=1;i<len;i+=2){
if(put[i]-put[i-1]!=0) return false;
}
for(int i=2;i<len;i+=2){
if(put[i]-put[i-1]!=1) return false;
}
return true;
}
TreeMap<Integer,Integer> mp = new TreeMap<>();
int sz = 0;
void insert(int v){
sz++;
mp.put(v,mp.getOrDefault(v,0)+1);
}
void remove(int v){
int ct = mp.getOrDefault(v,0);
if(ct==0) return;
sz--;
if(ct==1){
mp.remove(v);
}else{
mp.put(v,ct-1);
}
}
int front(){
return mp.firstKey();
}
void solve(){
int t = ni();
for(int i=0;i<t;++i){
mp.clear();
sz =0;
int n = ni();
int p[][] = new int[2*n][2];int x =0;
for(int j=0;j<n;++j){
int l = ni();
int r = ni();
p[x][0] = l;
p[x][1] = j;
x++;
p[x][0] = r+1;
p[x][1] = ~j;
x++;
}
Arrays.sort(p,(a,b)->{
if(a[0]!=b[0]){
return Integer.compare(a[0],b[0]);
}else{
return Integer.compare(a[1],b[1]);
}
});
int c = 0;
int add[] = new int[n];
for(int j=0;j<2*n;++j){
if(p[j][1]<0){
remove(~p[j][1]);
}else{
insert(p[j][1]);
}
if(sz==0){
c++;
}
if(j+1==2*n) continue;
if(sz==1&&p[j][1]<0&&p[j+1][1]>=0){
add[front()]++;
}
if(sz==1&&p[j][1]>=0&&p[j+1][1]<0){
add[front()]--;
}
}
int m = -n;
for(int j=0;j<n;++j){
m = Math.max(m,c+add[j]);
}
println(m);
}
}
public static String roundS(double result, int scale){
String fmt = String.format("%%.%df", scale);
return String.format(fmt, result);
}
// void solve() {
//
// for(int i=0;i<9;++i) {
// for (int j = 0; j < 9; ++j) {
// int v = ni();
// a[i][j] = v;
// if(v>0) {
// vis_row[i][v] = true;
// vis_col[j][v] = true;
// vis_room[get_room(i, j)][v] = true;
// }else{
// space++;
// }
// }
// }
//
//
// prepare = new int[space][2];
//
// int p = 0;
//
// for(int i=0;i<9;++i) {
// for (int j = 0; j < 9; ++j) {
// if(a[i][j]==0){
// prepare[p][0] = i;
// prepare[p][1]= j;p++;
// List<Integer> temp =new ArrayList<>();
// for(int k=1;k<=9;++k){
// if(!vis_col[j][k]&&!vis_row[i][k]&&!vis_room[get_room(i,j)][k]){
// temp.add(k);
// }
// }
// int sz = temp.size();
// val[i][j] = new int[sz];
// for(int k=0;k<sz;++k){
// val[i][j][k] = temp.get(k);
// }
// }
// }
// }
// Arrays.sort(prepare,(x,y)->{
// return Integer.compare(val[x[0]][x[1]].length,val[y[0]][y[1]].length);
// });
// dfs(0);
//
//
//
//
//
//
//
//
//
//
// }
InputStream is;
PrintWriter out;
void run() throws Exception {
is = System.in;
out = new PrintWriter(System.out);
solve();
out.flush();
}
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private char ncc() {
int b = readByte();
return (char) b;
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private String nline() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!isSpaceChar(b) || b == ' ') {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[][] nm(int n, int m) {
char[][] a = new char[n][];
for (int i = 0; i < n; i++) a[i] = ns(m);
return a;
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
private long[] nal(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nl();
return a;
}
private int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
}
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
else return minus ? -num : num;
b = readByte();
}
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
}
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
else return minus ? -num : num;
b = readByte();
}
}
void print(Object obj) {
out.print(obj);
}
void println(Object obj) {
out.println(obj);
}
void println() {
out.println();
}
void printArray(int a[],int from){
int l = a.length;
for(int i=from;i<l;++i){
print(a[i]);
if(i!=l-1){
print(" ");
}
}
println();
}
void printArray(long a[],int from){
int l = a.length;
for(int i=from;i<l;++i){
print(a[i]);
if(i!=l-1){
print(" ");
}
}
println();
}
} | Java | ["3\n4\n1 4\n2 3\n3 6\n5 7\n3\n5 5\n5 5\n5 5\n6\n3 3\n1 1\n5 5\n1 5\n2 2\n4 4"] | 4 seconds | ["2\n1\n5"] | null | Java 8 | standard input | [
"dp",
"graphs",
"constructive algorithms",
"two pointers",
"sortings",
"data structures",
"trees",
"brute force"
] | 58d7066178839b400b08f39b680da140 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$)Β β the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment β a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. | 2,300 | Print $$$t$$$ integers β the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments. | standard output | |
PASSED | 84cccad45512b307c0ad75054cdc349e | train_002.jsonl | 1578665100 | There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily Β β be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example: if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$; if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then: erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union; erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union; erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments. | 256 megabytes | import javax.swing.tree.TreeCellRenderer;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
// written by luchy0120
public class Main {
public static void main(String[] args) throws Exception {
new Main().run();
}
class Pair{
int x;int y;
Pair(int x,int y){this.x = x;this.y = y;}
@Override
public int hashCode(){
return x*127+y;
}
@Override
public boolean equals(Object obj){
Pair pr = (Pair)obj;
return pr.x == x && pr.y == y;
}
}
int h[],to[],ne[],wt[];
int ct = 0;
void add(int u,int v,int w){
to[ct] = v;
// wt[ct] = w;
ne[ct] = h[u];
h[u] = ct++;
}
long gcd(long a,long b){
return b==0?a:gcd(b,a%b);
}
static int MAXN = 100000;
static long tree[];
void update(int i,long v){
while(i<tree.length){
tree[i] += v;
i += i&(-i);
}
}
long sum(int i){
long v = 0;
while(i>0){
v = v + tree[i];
i -= i&(-i);
}
return v;
}
boolean isshun(int put[]){
int len = put.length;
if(put[len-1]==14) return false;
if(put[0]==2) return false;
if(put[1]==2) return false;
for(int i=1;i<len;++i){
if(put[i]-put[i-1]!=1) return false;
}
return true;
}
boolean doubleshun(int put[]){
int len = put.length;
if(len%2==1) return false;
for(int i=1;i<len;i+=2){
if(put[i]-put[i-1]!=0) return false;
}
for(int i=2;i<len;i+=2){
if(put[i]-put[i-1]!=1) return false;
}
return true;
}
TreeMap<Integer,Integer> mp = new TreeMap<>();
int sz = 0;
void insert(int v){
sz++;
mp.put(v,mp.getOrDefault(v,0)+1);
}
void remove(int v){
int ct = mp.getOrDefault(v,0);
if(ct==0) return;
sz--;
if(ct==1){
mp.remove(v);
}else{
mp.put(v,ct-1);
}
}
int front(){
return mp.firstKey();
}
void solve(){
int t = ni();
for(int i=0;i<t;++i){
mp.clear();
sz =0;
int n = ni();
int p[][] = new int[2*n][2];int x =0;
for(int j=1;j<=n;++j){
int l = ni();
int r = ni();
p[x][0] = l;
p[x][1] = -j;
x++;
p[x][0] = r;
p[x][1] = j;
x++;
}
Arrays.sort(p,(a,b)->{
if(a[0]!=b[0]){
return Integer.compare(a[0],b[0]);
}else{
return Integer.compare(a[1],b[1]);
}
});
int c = 0;
int add[] = new int[n];
for(int j=0;j<2*n;++j){
if(p[j][1]>0){
remove(p[j][1]);
}else{
insert(-p[j][1]);
}
if(sz==0){
c++;
}
if(j+1==2*n) continue;
if(sz==1&&p[j][1]>0&&p[j+1][1]<0&&p[j][0]<p[j+1][0]){
add[front()-1]++;
}
if(sz==1&&p[j][1]<0&&p[j+1][1]>0){
add[front()-1]--;
}
}
int m = -n;
for(int j=0;j<n;++j){
m = Math.max(m,c+add[j]);
}
println(m);
}
}
public static String roundS(double result, int scale){
String fmt = String.format("%%.%df", scale);
return String.format(fmt, result);
}
// void solve() {
//
// for(int i=0;i<9;++i) {
// for (int j = 0; j < 9; ++j) {
// int v = ni();
// a[i][j] = v;
// if(v>0) {
// vis_row[i][v] = true;
// vis_col[j][v] = true;
// vis_room[get_room(i, j)][v] = true;
// }else{
// space++;
// }
// }
// }
//
//
// prepare = new int[space][2];
//
// int p = 0;
//
// for(int i=0;i<9;++i) {
// for (int j = 0; j < 9; ++j) {
// if(a[i][j]==0){
// prepare[p][0] = i;
// prepare[p][1]= j;p++;
// List<Integer> temp =new ArrayList<>();
// for(int k=1;k<=9;++k){
// if(!vis_col[j][k]&&!vis_row[i][k]&&!vis_room[get_room(i,j)][k]){
// temp.add(k);
// }
// }
// int sz = temp.size();
// val[i][j] = new int[sz];
// for(int k=0;k<sz;++k){
// val[i][j][k] = temp.get(k);
// }
// }
// }
// }
// Arrays.sort(prepare,(x,y)->{
// return Integer.compare(val[x[0]][x[1]].length,val[y[0]][y[1]].length);
// });
// dfs(0);
//
//
//
//
//
//
//
//
//
//
// }
InputStream is;
PrintWriter out;
void run() throws Exception {
is = System.in;
out = new PrintWriter(System.out);
solve();
out.flush();
}
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private char ncc() {
int b = readByte();
return (char) b;
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private String nline() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!isSpaceChar(b) || b == ' ') {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[][] nm(int n, int m) {
char[][] a = new char[n][];
for (int i = 0; i < n; i++) a[i] = ns(m);
return a;
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
private long[] nal(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nl();
return a;
}
private int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
}
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
else return minus ? -num : num;
b = readByte();
}
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
}
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
else return minus ? -num : num;
b = readByte();
}
}
void print(Object obj) {
out.print(obj);
}
void println(Object obj) {
out.println(obj);
}
void println() {
out.println();
}
void printArray(int a[],int from){
int l = a.length;
for(int i=from;i<l;++i){
print(a[i]);
if(i!=l-1){
print(" ");
}
}
println();
}
void printArray(long a[],int from){
int l = a.length;
for(int i=from;i<l;++i){
print(a[i]);
if(i!=l-1){
print(" ");
}
}
println();
}
} | Java | ["3\n4\n1 4\n2 3\n3 6\n5 7\n3\n5 5\n5 5\n5 5\n6\n3 3\n1 1\n5 5\n1 5\n2 2\n4 4"] | 4 seconds | ["2\n1\n5"] | null | Java 8 | standard input | [
"dp",
"graphs",
"constructive algorithms",
"two pointers",
"sortings",
"data structures",
"trees",
"brute force"
] | 58d7066178839b400b08f39b680da140 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$)Β β the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment β a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. | 2,300 | Print $$$t$$$ integers β the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments. | standard output | |
PASSED | fd61d6fac47e605f19aeb42df99174ac | train_002.jsonl | 1430411400 | You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r,βc). You are staying in the cell (r1,βc1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2,βc2) since the exit to the next level is there. Can you do this? | 256 megabytes |
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.StringTokenizer;
public class C540 {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solver solver = new Solver();
solver.solve(1, in, out);
out.close();
}
static class Solver {
boolean[][] visited;
String[] field;
int n;
int m;
final int DIR_NUM = 4;
final int[] dx = {-1,0,1,0};
final int[] dy = {0,1,0,-1};
public void solve(int testNumber, InputReader in, PrintWriter out) {
n = in.nextInt();
m = in.nextInt();
field = new String[n];
for (int i = 0; i < n; i++) {
field[i] = in.next();
}
int y1 = in.nextInt()-1;
int x1 = in.nextInt()-1;
int y2 = in.nextInt()-1;
int x2 = in.nextInt()-1;
int goalcount = 0;
for (int i = 0; i < DIR_NUM; i++) {
int nx = x2 + dx[i];
int ny = y2 + dy[i];
if (nx < 0 || m <= nx || ny < 0 || n <= ny) continue;
if (field[ny].charAt(nx) == '.' ||
(ny == y1 && nx == x1)) goalcount++;
}
if (goalcount < 1 ||
(goalcount == 1 && field[y2].charAt(x2) == '.')) {
System.out.println("NO");
return;
}
visited = new boolean[n][m];
dfs(x1,y1);
if (visited[y2][x2]) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
public void dfs(int x, int y) {
visited[y][x] = true;
for (int i = 0; i < DIR_NUM; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || m <= nx || ny < 0 || n <= ny) continue;
if (visited[ny][nx]) continue;
if (field[ny].charAt(nx) == '.') {
dfs(nx, ny);
} else {
visited[ny][nx] = true;
}
}
}
}
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 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | 2 seconds | ["YES", "NO", "YES"] | NoteIn the first sample test one possible path is:After the first visit of cell (2,β2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | Java 8 | standard input | [
"dfs and similar"
] | afac59c927522fb223f59c36184229e2 | The first line contains two integers, n and m (1ββ€βn,βmββ€β500)Β β the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1ββ€βr1ββ€βn,β1ββ€βc1ββ€βm)Β β your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1,βc1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1ββ€βr2ββ€βn,β1ββ€βc2ββ€βm)Β β the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | 2,000 | If you can reach the destination, print 'YES', otherwise print 'NO'. | standard output | |
PASSED | d80f86a2af2b95d2ca2cac60dd03642d | train_002.jsonl | 1430411400 | You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r,βc). You are staying in the cell (r1,βc1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2,βc2) since the exit to the next level is there. Can you do this? | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
/**
* @author master_j
* @version 0.4.1
* @since Mar 22, 2015
*/
public class Solution {
int[] dx = new int[]{0, 0, -1, +1};
int[] dy = new int[]{+1, -1, 0, 0};
private void solve() throws IOException {
int n = io.nI(), m = io.nI();
boolean[][] solid = new boolean[n][m];
io.wc(".X");
for (int i = 0; i < n; i++) {
char[] s = io.nS().toCharArray();
for (int j = 0; j < m; j++) {
solid[i][j] = s[j] == '.';
}
}
int sx = io.nI() - 1, sy = io.nI() - 1;
int fx = io.nI() - 1, fy = io.nI() - 1;
if (sx == fx && sy == fy) {
for (int i = 0; i < 4; i++) {
int nx = sx + dx[i];
int ny = sy + dy[i];
if (0 <= nx && nx < n && 0 <= ny && ny < m && solid[nx][ny]) {
io.wln("YES");
return;
}
}
io.wln("NO");
return;
}
boolean[][] used = new boolean[n][m];
used[sx][sy] = true;
ArrayDeque<Integer> adx = new ArrayDeque<>();
adx.add(sx);
ArrayDeque<Integer> ady = new ArrayDeque<>();
ady.add(sy);
boolean hey = false;
while (!adx.isEmpty()) {
int cx = adx.pollFirst();
int cy = ady.pollFirst();
if (cx == fx && cy == fy) {
hey = true;
break;
}
for (int i = 0; i < 4; i++) {
int nx = cx + dx[i];
int ny = cy + dy[i];
if (0 <= nx && nx < n && 0 <= ny && ny < m && !used[nx][ny] && (solid[nx][ny] || nx == fx && ny == fy)) {
adx.addLast(nx);
ady.addLast(ny);
used[nx][ny] = true;
}
}
}
if (!hey) {
io.wln("NO");
return;
}
if (!solid[fx][fy]) {
io.wln("YES");
return;
}
int k = 0;
for (int i = 0; i < 4; i++) {
int nx = fx + dx[i];
int ny = fy + dy[i];
if (0 <= nx && nx < n && 0 <= ny && ny < m && solid[nx][ny] || sx == nx && sy == ny)
k++;
}
if (k <= 1)
io.wln("NO");
else
io.wln("YES");
}//2.2250738585072012e-308
public static void main(String[] args) throws IOException {
IO.launchSolution(args);
}
Solution(IO io) throws IOException {
this.io = io;
solve();
}
private final IO io;
}
class IO {
static final String _localArg = "master_j";
private static final String _problemName = "";
private static final Mode _inMode = Mode.STD_;
private static final Mode _outMode = Mode.STD_;
private static final boolean _autoFlush = false;
enum Mode {STD_, _PUT_TXT, PROBNAME_}
private final StreamTokenizer st;
private final BufferedReader br;
private final Reader reader;
private final PrintWriter pw;
private final Writer writer;
static void launchSolution(String[] args) throws IOException {
boolean local = (args.length == 1 && args[0].equals(IO._localArg));
IO io = new IO(local);
long nanoTime = 0;
if (local) {
nanoTime -= System.nanoTime();
io.wln("<output>");
}
io.flush();
new Solution(io);
io.flush();
if (local) {
io.wln("</output>");
nanoTime += System.nanoTime();
final long D9 = 1000000000, D6 = 1000000, D3 = 1000;
if (nanoTime >= D9)
io.wf("%d.%d seconds\n", nanoTime / D9, nanoTime % D9);
else if (nanoTime >= D6)
io.wf("%d.%d millis\n", nanoTime / D6, nanoTime % D6);
else if (nanoTime >= D3)
io.wf("%d.%d micros\n", nanoTime / D3, nanoTime % D3);
else
io.wf("%d nanos\n", nanoTime);
}
io.close();
}
IO(boolean local) throws IOException {
if (_inMode == Mode.PROBNAME_ || _outMode == Mode.PROBNAME_)
if (_problemName.length() == 0)
throw new IllegalStateException("You imbecile. Where's my <_problemName>?");
if (_problemName.length() > 0)
if (_inMode != Mode.PROBNAME_ && _outMode != Mode.PROBNAME_)
throw new IllegalStateException("You imbecile. What's the <_problemName> for?");
Locale.setDefault(Locale.US);
if (local) {
reader = new FileReader("input.txt");
writer = new OutputStreamWriter(System.out);
} else {
switch (_inMode) {
case STD_:
reader = new InputStreamReader(System.in);
break;
case PROBNAME_:
reader = new FileReader(_problemName + ".in");
break;
case _PUT_TXT:
reader = new FileReader("input.txt");
break;
default:
throw new NullPointerException("You imbecile. Gimme _inMode.");
}
switch (_outMode) {
case STD_:
writer = new OutputStreamWriter(System.out);
break;
case PROBNAME_:
writer = new FileWriter(_problemName + ".out");
break;
case _PUT_TXT:
writer = new FileWriter("output.txt");
break;
default:
throw new NullPointerException("You imbecile. Gimme _outMode.");
}
}
br = new BufferedReader(reader);
st = new StreamTokenizer(br);
pw = new PrintWriter(writer, _autoFlush);
if (local && _autoFlush)
wln("Note: auto-flush is on.");
}
//@formatter:off
void wln() {pw.println(); }
void wln(boolean x) {pw.println(x);}
void wln(char x) {pw.println(x);}
void wln(char x[]) {pw.println(x);}
void wln(double x) {pw.println(x);}
void wln(float x) {pw.println(x);}
void wln(int x) {pw.println(x);}
void wln(long x) {pw.println(x);}
void wln(Object x) {pw.println(x);}
void wln(String x) {pw.println(x);}
void wf(String f, Object... o) {pw.printf(f, o);}
void w(boolean x) {pw.print(x);}
void w(char x) {pw.print(x);}
void w(char x[]) {pw.print(x);}
void w(double x) {pw.print(x);}
void w(float x) {pw.print(x);}
void w(int x) {pw.print(x);}
void w(long x) {pw.print(x);}
void w(Object x) {pw.print(x);}
void w(String x) {pw.print(x);}
int nI() throws IOException {st.nextToken(); return (int)st.nval;}
double nD() throws IOException {st.nextToken(); return st.nval;}
float nF() throws IOException {st.nextToken(); return (float)st.nval;}
long nL() throws IOException {st.nextToken(); return (long)st.nval;}
String nS() throws IOException {st.nextToken(); return st.sval;}
int[] nIa(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nI();
return a;
}
double[] nDa(int n) throws IOException {
double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = nD();
return a;
}
String[] nSa(int n) throws IOException {
String[] a = new String[n];
for (int i = 0; i < n; i++)
a[i] = nS();
return a;
}
void wc(String x) {wc(x.toCharArray());}
void wc(char c1, char c2) {for (char c = c1; c<=c2; c++) wc(c);}
void wc(char x[]) {for (char c : x) wc(c); }
void wc(char x) {st.ordinaryChar(x); st.wordChars(x, x);}
public boolean eof() {return st.ttype == StreamTokenizer.TT_EOF;}
public boolean eol() {return st.ttype == StreamTokenizer.TT_EOL;}
void flush() {pw.flush();}
void close() throws IOException {reader.close(); br.close(); flush(); pw.close();}
//@formatter:on
} | Java | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | 2 seconds | ["YES", "NO", "YES"] | NoteIn the first sample test one possible path is:After the first visit of cell (2,β2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | Java 8 | standard input | [
"dfs and similar"
] | afac59c927522fb223f59c36184229e2 | The first line contains two integers, n and m (1ββ€βn,βmββ€β500)Β β the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1ββ€βr1ββ€βn,β1ββ€βc1ββ€βm)Β β your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1,βc1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1ββ€βr2ββ€βn,β1ββ€βc2ββ€βm)Β β the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | 2,000 | If you can reach the destination, print 'YES', otherwise print 'NO'. | standard output | |
PASSED | 3b34e04837b948ecf54c0543605f714b | train_002.jsonl | 1430411400 | You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r,βc). You are staying in the cell (r1,βc1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2,βc2) since the exit to the next level is there. Can you do this? | 256 megabytes | import java.util.ArrayDeque;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.awt.Point;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Agostinho Junior (junior94)
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
}
class TaskC {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.readInt();
int m = in.readInt();
char[][] cave = new char[n][];
for (int i = 0; i < n; i++) {
cave[i] = in.next().toCharArray();
}
int r1 = in.readInt() - 1;
int c1 = in.readInt() - 1;
int r2 = in.readInt() - 1;
int c2 = in.readInt() - 1;
ArrayDeque<Point> stack = new ArrayDeque<>();
stack.push(new Point(r1, c1));
int[] dx = {0, 0, -1, 1};
int[] dy = {-1, 1, 0, 0};
Point[] temp = new Point[4];
for (int i = 0; i < 4; i++) {
temp[i] = new Point(-1, -1);
}
while (!stack.isEmpty()) {
Point p = stack.pop();
cave[p.x][p.y] = 'X';
int diffX = Math.abs(p.x - r2);
int diffY = Math.abs(p.y - c2);
if (diffX + diffY == 1 &&
cave[r2][c2] == 'X') {
out.println("YES");
return;
}
boolean found = false;
for (int i = 0; i < dx.length; i++) {
int x = p.x + dx[i];
int y = p.y + dy[i];
if (0 <= Math.min(x, y) && x < n && y < m &&
cave[x][y] == '.') {
if (x == r2 && y == c2) {
found = true;
}
temp[i] = new Point(x, y);
} else {
temp[i].x = -1;
}
}
if (found) {
stack.clear();
for (Point point: temp) {
if (point.x != r2 || point.y != c2) {
point.x = -1;
}
}
}
for (Point point: temp) {
if (point.x != -1) {
stack.push(new Point(point.x, point.y));
}
}
}
out.println("NO");
}
}
class InputReader {
private BufferedReader input;
private StringTokenizer line = new StringTokenizer("");
public InputReader(InputStream in) {
input = new BufferedReader(new InputStreamReader(in));
}
public void fill() {
try {
if(!line.hasMoreTokens()) line = new StringTokenizer(input.readLine());
} catch(IOException io) { io.printStackTrace(); System.exit(0);}
}
public String next() {
fill();
return line.nextToken();
}
public int readInt() {
fill();
return Integer.parseInt(line.nextToken());
}
}
class OutputWriter {
private PrintWriter output;
public OutputWriter(OutputStream out) {
output = new PrintWriter(out);
}
public void println(Object o) {
output.println(o);
}
public void close() {
output.close();
}
}
| Java | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | 2 seconds | ["YES", "NO", "YES"] | NoteIn the first sample test one possible path is:After the first visit of cell (2,β2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | Java 8 | standard input | [
"dfs and similar"
] | afac59c927522fb223f59c36184229e2 | The first line contains two integers, n and m (1ββ€βn,βmββ€β500)Β β the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1ββ€βr1ββ€βn,β1ββ€βc1ββ€βm)Β β your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1,βc1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1ββ€βr2ββ€βn,β1ββ€βc2ββ€βm)Β β the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | 2,000 | If you can reach the destination, print 'YES', otherwise print 'NO'. | standard output | |
PASSED | a281aa8afb468355fef80d0061ab98c7 | train_002.jsonl | 1430411400 | You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r,βc). You are staying in the cell (r1,βc1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2,βc2) since the exit to the next level is there. Can you do this? | 256 megabytes | /**
* @author chang
* created on 30/04/15
*/
import java.util.*;
import java.io.*;
public class IceCave {
public static void main(String[] args) throws IOException {
new IceCaveSolver();
}
}
class IceCaveSolver {
BufferedReader br;
PrintWriter out;
StringTokenizer stoken;
boolean eof;
int[] dx = {1,-1,0,0};
int[] dy = {0,0,1,-1};
String[] grid;
boolean[][] visited;
int r1,c1,r2,c2;
int n,m;
void reset(){
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j)
visited[i][j] = false;
}
}
boolean inside(int x,int y){
if (x < 0 || y < 0 || x >= n || y >= m)
return false;
return true;
}
boolean path(int beg_x,int beg_y,int dest_x,int dest_y,int invalid_x,int invalid_y){
LinkedList<Integer> xco = new LinkedList<>();
LinkedList<Integer> yco = new LinkedList<>();
xco.push(beg_x);
yco.push(beg_y);
while(!xco.isEmpty() && !yco.isEmpty()){
int x = xco.pop();
int y = yco.pop();
if (visited[x][y]) continue;
visited[x][y] = true;
if (grid[x].charAt(y) == 'X' && (x != beg_x || y != beg_y))
continue;
for(int i = 0; i < 4; ++i){
int xx = x + dx[i];
int yy = y + dy[i];
if (!inside(xx,yy)) continue;
if (xx == invalid_x && yy == invalid_y)
continue;
xco.push(xx);
yco.push(yy);
}
}
return visited[dest_x][dest_y];
}
void solve() throws IOException {
n = nextInt();
m = nextInt();
grid = new String[n];
visited = new boolean[n][m];
for(int i = 0; i < n; ++i)
grid[i] = nextString();
r1 = nextInt()-1;
c1 = nextInt()-1;
r2 = nextInt()-1;
c2 = nextInt()-1;
if (r1 == r2 && c1 == c2){
for(int i = 0; i < 4; ++i){
int x = r2 + dx[i];
int y = c2 + dy[i];
if (!inside(x,y) || grid[x].charAt(y) == 'X') continue;
out.println("YES");
return;
}
out.println("NO");
}
else if (grid[r2].charAt(c2) == 'X'){
if (path(r1,c1,r2,c2,-1,-1))
out.println("YES");
else
out.println("NO");
} else {
for(int i = 0; i < 4; ++i){
int x = r2 + dx[i];
int y = c2 + dy[i];
if (!inside(x,y)) continue;
if (grid[x].charAt(y) == 'X')
continue;
reset();
if (path(r1,c1,r2,c2,x,y)){
out.println("YES");
return;
}
}
out.println("NO");
}
}
IceCaveSolver() throws IOException {
//br = new BufferedReader(new FileReader("../../Downloads/A-small-attempt0.in"));
//out = new PrintWriter(new FileWriter("IceCaveOutput.txt"));
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
Thread t = new Thread(null, () -> {
try {
int ts = 1;
//ts = nextInt();
for (int i = 1; i <= ts; ++i) {
solve();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}, "a", 1 << 24);
t.start();
try {
t.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.close();
}
String nextToken() {
while (stoken == null || !stoken.hasMoreTokens()) {
try {
stoken = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return stoken.nextToken();
}
String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
} | Java | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | 2 seconds | ["YES", "NO", "YES"] | NoteIn the first sample test one possible path is:After the first visit of cell (2,β2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | Java 8 | standard input | [
"dfs and similar"
] | afac59c927522fb223f59c36184229e2 | The first line contains two integers, n and m (1ββ€βn,βmββ€β500)Β β the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1ββ€βr1ββ€βn,β1ββ€βc1ββ€βm)Β β your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1,βc1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1ββ€βr2ββ€βn,β1ββ€βc2ββ€βm)Β β the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | 2,000 | If you can reach the destination, print 'YES', otherwise print 'NO'. | standard output | |
PASSED | f87998423b99b71a08f52af4ab9fd04c | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | //package proje;
import java.util.*;
public class lol
{
class obj
{
int skill;
int index;
}
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int nos = s.nextInt();
obj[] skills = new obj[nos];
lol p = new lol();
for(int y=0; y<nos; y++)
{
obj m = p.new obj();
m.skill=s.nextInt();
m.index=y+1;
skills[y]=m;
}
Arrays.sort(skills, new Comparator<obj>(){
public int compare(obj o1, obj o2)
{
return o1.skill-o2.skill;
}
});
obj[] skill2 = new obj[nos/2];
obj[] skill1 = new obj[nos - (nos/2)];
int j=0;
int k=0;
for(int i=0;i<nos; i++)
{
if(i%2==0)
{
skill1[j]=skills[i];
j++;
}
else
{
skill2[k]=skills[i];
k++;
}
}
System.out.println(skill1.length);
for(obj y: skill1)
System.out.print(y.index +" ");
System.out.println();
System.out.println(skill2.length);
for(obj y: skill2)
System.out.print(y.index +" ");
}
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | dee2e658981bc088a3852e471f845f4c | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
public class DivisionIntoTeams {
static int mod = 1000000007;
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[10005]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
static class IntIntPair implements Comparable<IntIntPair> {
public final int first;
public final int second;
public static IntIntPair makePair(int first, int second) {
return new IntIntPair(first, second);
}
public IntIntPair(int first, int second) {
this.first = first;
this.second = second;
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
IntIntPair pair = (IntIntPair) o;
return first == pair.first && second == pair.second;
}
public int hashCode() {
int result = first;
result = 31 * result + second;
return result;
}
public String toString() {
return "(" + first + "," + second + ")";
}
public int compareTo(IntIntPair o) {
int value = Integer.compare(first, o.first);
if (value != 0) {
return value;
}
return Integer.compare(second, o.second);
}
}
public static void main(String[] args) throws IOException {
Reader in = new Reader();
int i, t, n;
n = in.nextInt();
StringBuilder ans = new StringBuilder();
IntIntPair arr[] = new IntIntPair[n + 1];
for (i = 1; i <= n; i++) {
t = in.nextInt();
arr[i] = new IntIntPair(t, i);
}
Arrays.sort(arr, 1, n + 1);
if ((n & 1) == 0) {
ans.append(n / 2 + "\n");
for (i = 1; i <= n; i = i + 2)
ans.append(arr[i].second + " ");
ans.append("\n" + (n / 2) + "\n");
for (i = 2; i <= n; i = i + 2)
ans.append(arr[i].second + " ");
} else {
ans.append((n / 2 + 1) + "\n");
for (i = 1; i <= n; i = i + 2)
ans.append(arr[i].second + " ");
ans.append("\n" + (n / 2) + "\n");
for (i = 2; i <= n; i = i + 2)
ans.append(arr[i].second + " ");
}
System.out.println(ans);
}
}
| Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 4c3070b5a7c91fcf1a85453f5db1ab19 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
Pair[] arr = new Pair[n];
for (int i = 0; i < n; i++) {
arr[i] = new Pair(i, in.nextInt());
}
Arrays.sort(arr, Collections.reverseOrder());
int oneSum = 0;
int twoSum = 0;
ArrayList<Integer> oneIdx = new ArrayList<>();
ArrayList<Integer> twoIdx = new ArrayList<>();
for (int i = 0; i < n; i++) {
Pair cur = arr[i];
if (oneSum <= twoSum) {
oneSum += cur.y;
oneIdx.add(cur.x);
} else {
twoSum += cur.y;
twoIdx.add(cur.x);
}
}
while (Math.abs(oneIdx.size() - twoIdx.size()) > 1) {
if (oneIdx.size() > twoIdx.size()) {
int i = oneIdx.get(oneIdx.size() - 1);
oneIdx.remove(oneIdx.size() - 1);
twoIdx.add(i);
} else {
int i = twoIdx.get(twoIdx.size() - 1);
twoIdx.remove(twoIdx.size() - 1);
oneIdx.add(i);
}
}
out.println(oneIdx.size());
for (int i = 0; i < oneIdx.size(); i++) {
out.print((oneIdx.get(i) + 1) + " ");
}
out.println();
out.println(twoIdx.size());
for (int i = 0; i < twoIdx.size(); i++) {
out.print((twoIdx.get(i) + 1) + " ");
}
}
class Pair implements Comparable<Pair> {
int x;
int y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
public int compareTo(Pair o) {
return Integer.compare(y, o.y);
}
}
}
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 | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | c941df560b492a569016f22cd959f93b | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes |
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class DivisionIntoTeams {
private void solve() {
int n = in.nextInt();
int[][] arrwp = new int[n][2];
for (int i = 0; i < n; ++i) {
arrwp[i][0] = in.nextInt();
arrwp[i][1] = i + 1;
}
Arrays.sort(arrwp, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
return o1[0] - o2[0];
}
});
out.println(n / 2 + n % 2);
for (int i = 0; i < n; i += 2) {
out.print(arrwp[i][1] + " ");
}
out.println();
out.println(n / 2);
for (int i = 1; i < n; i += 2) {
out.print(arrwp[i][1] + " ");
}
out.println();
}
private class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in), 327680);
st = new StringTokenizer("");
}
int[] nextIntegerArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; ++i) {
arr[i] = nextInt();
}
return arr;
}
long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; ++i) {
arr[i] = nextLong();
}
return arr;
}
char[] nextCharArray(int n) {
char[] arr = new char[n];
for (int i = 0; i < n; ++i) {
arr[i] = nextChar();
}
return arr;
}
double[] nextDoubleArray(int n) {
double[] arr = new double[n];
for (int i = 0; i < n; ++i) {
arr[i] = nextDouble();
}
return arr;
}
String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
char nextChar() {
String s = next();
if (s.length() > 1)
throw new RuntimeException("character expected but string provided");
return s.charAt(0);
}
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) {
throw new RuntimeException(e);
}
return str;
}
}
private FastScanner in;
private PrintWriter out;
private void run() {
try {
in = new FastScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
solve();
} finally {
out.close();
}
}
public static void main(String[] arg) {
new DivisionIntoTeams().run();
}
}
| Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | aa54c7cf6674d05ebdc64dffa4656b45 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class C {
public static void main(String[] args){
FastScanner scan = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int n = scan.nextInt();
N[] a = new N[n];
for(int i = 0; i < n; i++) a[i] = new N(scan.nextInt(), i);
Arrays.sort(a);
ArrayList<Integer> x = new ArrayList<>(), y = new ArrayList<>();
for(int i = 0; i < n; i++) {
if(i%2==0)x.add(a[i].i+1);
else y.add(a[i].i+1);
}
out.println(x.size());
for(int i : x) out.print(i+" ");
out.println("\n"+y.size());
for(int i : y) out.print(i+" ");
out.println();
out.close();
}
static class N implements Comparable<N> {
int v, i;
public N(int a, int b){
v = a;
i = b;
}
public int compareTo(N o) {
return o.v-v;
}
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine());
} catch (Exception e){e.printStackTrace();}
}
public String next() {
if (st.hasMoreTokens()) return st.nextToken();
try {st = new StringTokenizer(br.readLine());}
catch (Exception 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());}
public String nextLine() {
String line = "";
if(st.hasMoreTokens()) line = st.nextToken();
else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
while(st.hasMoreTokens()) line += " "+st.nextToken();
return line;
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for(int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n){
long[] a = new long[n];
for(int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
public double[] nextDoubleArray(int n){
double[] a = new double[n];
for(int i = 0; i < n; i++) a[i] = nextDouble();
return a;
}
public char[][] nextGrid(int n, int m){
char[][] grid = new char[n][m];
for(int i = 0; i < n; i++) grid[i] = next().toCharArray();
return grid;
}
}
}
| Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 50668cd59c399af1e64a60085f1d6013 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
Player[] players = new Player[n];
for (int i = 0; i < n; ++i) {
players[i] = new Player(in.nextInt(), i + 1);
}
Arrays.sort(players);
ArrayList<Player>[] teams = new ArrayList[2];
teams[0] = new ArrayList<>();
teams[1] = new ArrayList<>();
for (int i = 0; i < n; ++i) {
teams[i % 2].add(players[i]);
}
for (int k = 0; k < 2; ++k) {
out.println(teams[k].size());
for (int i = 0; i < teams[k].size(); ++i) {
if (i > 0) out.print(" ");
out.print(teams[k].get(i).index);
}
out.println();
}
}
class Player implements Comparable<Player> {
int skill;
int index;
public Player(int skill, int index) {
this.skill = skill;
this.index = index;
}
public int compareTo(Player player) {
if (this.skill != player.skill) {
return skill - player.skill;
}
return index - player.index;
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 65536 / 2);
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 | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 13d3e5a3a037825945ffb4b30dd8e97b | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | /**
* DA-IICT
* Author : PARTH PATEL
*/
import java.io.*;
import java.math.*;
import java.util.*;
import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;
public class C149
{
public static long mod = 1000000007;
public static long INF = (1L << 60);
static FastScanner2 in = new FastScanner2();
static OutputWriter out = new OutputWriter(System.out);
static class Pair implements Comparable<Pair>
{
int index,val;
Pair(int index,int val)
{
this.index=index;
this.val=val;
}
@Override
public int compareTo(Pair o) {
// TODO Auto-generated method stub
return this.val-o.val;
}
}
public static void main(String[] args)
{
int n=in.nextInt();
Pair[] arr=new Pair[n];
for(int i=0;i<n;i++)
{
arr[i]=new Pair(i+1, in.nextInt());
}
sort(arr);
ArrayList<Integer> list1=new ArrayList<>();
ArrayList<Integer> list2=new ArrayList<>();
for(int i=0;i<n;i++)
{
if(i%2==0)
list1.add(arr[i].index);
else
list2.add(arr[i].index);
}
out.println(list1.size());
for(int i : list1)
out.print(i+" ");
out.println();
out.println(list2.size());
for(int i : list2)
out.print(i+" ");
out.close();
}
public static long pow(long x, long n)
{
long res = 1;
for (long p = x; n > 0; n >>= 1, p = (p * p))
{
if ((n & 1) != 0)
{
res = (res * p);
}
}
return res;
}
public static long pow(long x, long n, long mod)
{
long res = 1;
for (long p = x; n > 0; n >>= 1, p = (p * p) % mod)
{
if ((n & 1) != 0)
{
res = (res * p % mod);
}
}
return res;
}
public static long gcd(long n1, long n2)
{
long r;
while (n2 != 0)
{
r = n1 % n2;
n1 = n2;
n2 = r;
}
return n1;
}
public static long lcm(long n1, long n2)
{
long answer = (n1 * n2) / (gcd(n1, n2));
return answer;
}
static class FastScanner2
{
private byte[] buf = new byte[1024];
private int curChar;
private int snumChars;
public int read()
{
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars)
{
curChar = 0;
try
{
snumChars = System.in.read(buf);
} catch (IOException e)
{
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isEndOfLine(c));
return res.toString();
}
public String nextString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n)
{
int[] arr = new int[n];
for (int i = 0; i < n; i++)
{
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n)
{
long[] arr = new long[n];
for (int i = 0; i < n; i++)
{
arr[i] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c)
{
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c)
{
return c == '\n' || c == '\r' || c == -1;
}
}
static class InputReader
{
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream inputstream)
{
reader = new BufferedReader(new InputStreamReader(inputstream));
tokenizer = null;
}
public String nextLine()
{
String fullLine = null;
while (tokenizer == null || !tokenizer.hasMoreTokens())
{
try
{
fullLine = reader.readLine();
} catch (IOException e)
{
throw new RuntimeException(e);
}
return fullLine;
}
return fullLine;
}
public String next()
{
while (tokenizer == null || !tokenizer.hasMoreTokens())
{
try
{
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e)
{
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public long nextLong()
{
return Long.parseLong(next());
}
public int[] nextIntArray(int n)
{
int a[] = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt();
}
return a;
}
public long[] nextLongArray(int n)
{
long a[] = new long[n];
for (int i = 0; i < n; i++)
{
a[i] = nextLong();
}
return a;
}
public int nextInt()
{
return Integer.parseInt(next());
}
}
static class OutputWriter
{
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream)
{
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer)
{
this.writer = new PrintWriter(writer);
}
public void print(Object... objects)
{
for (int i = 0; i < objects.length; i++)
{
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void println(Object... objects)
{
print(objects);
writer.println();
}
public void close()
{
writer.close();
}
public void flush()
{
writer.flush();
}
}
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | df46050040f9651f6e6a6aad0144ea1c | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.*;
import java.util.*;
@SuppressWarnings("unchecked")
public class Main {
private static final long MOD = (int)1e9 + 7;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Pair[] a = new Pair[n];
for (int i = 0; i < n; ++i) a[i] = new Pair((i + 1), in.nextInt());
int sumx = 0;
int sumy = 0;
Arrays.sort(a);
ArrayList<Integer> x = new ArrayList<>();
ArrayList<Integer> y = new ArrayList<>();
int i = n - 1, j = 0;
while (j <= i) {
if (x.size() - y.size() >= 1) {
y.add(a[i].i);
sumy += a[i--].val;
continue;
} else if(y.size() - x.size() >= 1) {
x.add(a[i].i);
sumx += a[i--].val;
continue;
}
if (sumx <= sumy) {
x.add(a[j].i);
sumx += a[j++].val;
} else {
y.add(a[j].i);
sumy += a[j++].val;
}
}
System.out.println(x.size());
for (int k : x) System.out.print(k + " ");
System.out.println();
System.out.println(y.size());
for (int k : y) System.out.print(k + " ");
}
static class Pair implements Comparable<Pair> {
int i, val;
Pair(int i, int val) {
this.i = i;
this.val = val;
}
public int compareTo(Pair p) {
if (p.val != this.val) return p.val - this.val;
return this.i - p.i;
}
}
/*
*/
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | c82d9c52f94a9f5a81b5d3ca8b3c9a8f | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.*;
import java.util.*;
@SuppressWarnings("unchecked")
public class Main {
private static final long MOD = (int)1e9 + 7;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Pair[] a = new Pair[n];
for (int i = 0; i < n; ++i) a[i] = new Pair((i + 1), in.nextInt());
int sumx = 0;
int sumy = 0;
Arrays.sort(a);
ArrayList<Integer> x = new ArrayList<>();
ArrayList<Integer> y = new ArrayList<>();
// int i = n - 1, j = 0;
// while (j <= i) {
// if (x.size() - y.size() >= 1) {
// y.add(a[i].i);
// sumy += a[i--].val;
// continue;
// } else if(y.size() - x.size() >= 1) {
// x.add(a[i].i);
// sumx += a[i--].val;
// continue;
// }
// if (sumx <= sumy) {
// x.add(a[j].i);
// sumx += a[j++].val;
// } else {
// y.add(a[j].i);
// sumy += a[j++].val;
// }
// }
for (int i = 0; i < n - 1; i += 2) {
x.add(a[i].i);
sumx += a[i].val;
y.add(a[i + 1].i);
sumy += a[i + 1].val;
}
if (n % 2 == 1) {
if (sumx <= sumy) x.add(a[n - 1].i);
else y.add(a[n - 1].i);
}
System.out.println(x.size());
for (int k : x) System.out.print(k + " ");
System.out.println();
System.out.println(y.size());
for (int k : y) System.out.print(k + " ");
}
static class Pair implements Comparable<Pair> {
int i, val;
Pair(int i, int val) {
this.i = i;
this.val = val;
}
public int compareTo(Pair p) {
if (p.val != this.val) return p.val - this.val;
return this.i - p.i;
}
}
/*
*/
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 310d6a1ef69f69e00be751a28868007f | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.*;
import java.util.*;
@SuppressWarnings("unchecked")
public class Main {
private static final long MOD = (int)1e9 + 7;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Pair[] a = new Pair[n];
for (int i = 0; i < n; ++i) a[i] = new Pair((i + 1), in.nextInt());
int sumx = 0;
int sumy = 0;
Arrays.sort(a);
ArrayList<Integer> x = new ArrayList<>();
ArrayList<Integer> y = new ArrayList<>();
// int i = n - 1, j = 0;
// while (j <= i) {
// if (x.size() - y.size() >= 1) {
// y.add(a[i].i);
// sumy += a[i--].val;
// continue;
// } else if(y.size() - x.size() >= 1) {
// x.add(a[i].i);
// sumx += a[i--].val;
// continue;
// }
// if (sumx <= sumy) {
// x.add(a[j].i);
// sumx += a[j++].val;
// } else {
// y.add(a[j].i);
// sumy += a[j++].val;
// }
// }
for (int i = 0; i < n - 1; i += 2) {
x.add(a[i].i);
sumx += a[i].val;
y.add(a[i + 1].i);
sumy += a[i + 1].val;
}
if (n % 2 == 1) {
// if (sumx <= sumy) x.add(a[n - 1].i);
// else y.add(a[n - 1].i);
x.add(a[n - 1].i);
}
System.out.println(x.size());
for (int k : x) System.out.print(k + " ");
System.out.println();
System.out.println(y.size());
for (int k : y) System.out.print(k + " ");
}
static class Pair implements Comparable<Pair> {
int i, val;
Pair(int i, int val) {
this.i = i;
this.val = val;
}
public int compareTo(Pair p) {
if (p.val != this.val) return p.val - this.val;
return this.i - p.i;
}
}
/*
*/
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 3ab96ff5394d2ec6183de2fc82bf4838 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.*;
import java.util.*;
@SuppressWarnings("unchecked")
public class Main {
private static final long MOD = (int)1e9 + 7;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Pair[] a = new Pair[n];
for (int i = 0; i < n; ++i) a[i] = new Pair((i + 1), in.nextInt());
int sumx = 0;
int sumy = 0;
Arrays.sort(a);
ArrayList<Integer> x = new ArrayList<>();
ArrayList<Integer> y = new ArrayList<>();
// int i = n - 1, j = 0;
// while (j <= i) {
// if (x.size() - y.size() >= 1) {
// y.add(a[i].i);
// sumy += a[i--].val;
// continue;
// } else if(y.size() - x.size() >= 1) {
// x.add(a[i].i);
// sumx += a[i--].val;
// continue;
// }
// if (sumx <= sumy) {
// x.add(a[j].i);
// sumx += a[j++].val;
// } else {
// y.add(a[j].i);
// sumy += a[j++].val;
// }
// }
for (int i = 0; i < n - 1; i += 2) {
x.add(a[i].i);
sumx += a[i].val;
y.add(a[i + 1].i);
sumy += a[i + 1].val;
}
if (n % 2 == 1) {
// if (sumx <= sumy) x.add(a[n - 1].i);
// else y.add(a[n - 1].i);
x.add(a[n - 1].i);
}
System.out.println(x.size());
for (int k : x) System.out.print(k + " ");
System.out.println();
System.out.println(y.size());
for (int k : y) System.out.print(k + " ");
}
static class Pair implements Comparable<Pair> {
int i, val;
Pair(int i, int val) {
this.i = i;
this.val = val;
}
public int compareTo(Pair p) {
if (p.val != this.val) return this.val - p.val;
return this.i - p.i;
}
}
/*
*/
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 7fef800a3548a6342d07a37d23671c46 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.*;
import java.util.*;
@SuppressWarnings("unchecked")
public class Main {
private static final long MOD = (int)1e9 + 7;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Pair[] a = new Pair[n];
for (int i = 0; i < n; ++i) a[i] = new Pair((i + 1), in.nextInt());
int sumx = 0;
int sumy = 0;
Arrays.sort(a);
ArrayList<Integer> x = new ArrayList<>();
ArrayList<Integer> y = new ArrayList<>();
int i = n - 1, j = 0;
while (j <= i) {
if (x.size() - y.size() >= 1) {
y.add(a[i].i);
sumy += a[i--].val;
continue;
} else if(y.size() - x.size() >= 1) {
x.add(a[i].i);
sumx += a[i--].val;
continue;
}
if (sumx <= sumy) {
x.add(a[j].i);
sumx += a[j++].val;
} else {
y.add(a[j].i);
sumy += a[j++].val;
}
}
System.out.println(x.size());
for (int k : x) System.out.print(k + " ");
System.out.println();
System.out.println(y.size());
for (int k : y) System.out.print(k + " ");
}
static class Pair implements Comparable<Pair> {
int i, val;
Pair(int i, int val) {
this.i = i;
this.val = val;
}
public int compareTo(Pair p) {
if (p.val != this.val) return p.val - this.val;
return this.i - p.i;
}
}
/*
*/
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 533f2136206ac5a507b15f63892c0664 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Euler {
public static void main(String[] args){
FastReader in = new FastReader();
PrintWriter o = new PrintWriter(System.out);
int n = in.nextInt();
int[][] arr = new int[n][2];
for (int i = 0; i < n; i++) {
arr[i][0] = in.nextInt();
arr[i][1] = (i + 1);
}
Arrays.sort(arr, new Comparator<int[]>() {
public int compare(int[] a, int[] b) {
return a[0] - b[0];
}
});
int x = 0;
int vX = 0;
int y = 0;
int vY = 0;
int max = arr[n - 1][0];
List<Integer> lsX = new ArrayList<>();
List<Integer> lsY = new ArrayList<>();
int i = 0;
for (; i + 1 < n; i+=2) {
vX += arr[i][0];
vY += arr[i + 1][0];
x++;
y++;
lsX.add(arr[i][1]);
lsY.add(arr[i + 1][1]);
}
if (i + 1 == n && Math.abs(vX + arr[i][0] - vY) <= max) {
x++;
lsX.add(arr[i][1]);
} else if (i + 1 == n && Math.abs(vX - arr[i][0] - vY) <= max) {
y++;
lsY.add(arr[i][1]);
}
o.println(x);
i = 0;
for (; i < lsX.size(); i++) {
o.print(lsX.get(i) + " ");
}
o.println();
o.println(y);
i = 0;
for (;i < lsY.size(); i++) {
o.print(lsY.get(i) + " ");
}
o.println();
o.close();
o.flush();
return;
}
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());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long[] readLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | decc06686a6494a66abd9a7a545743fb | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.util.*;
import java.io.*;
public class P {
static class pair implements Comparable<pair>{
int a;
int b;
public pair(int a, int b){
this.a=a;
this.b=b;
}
public int compareTo(pair p) {
if (a == p.a)
return b-p.b;
else return a-p.a;
}
public String toString(){
return a+" "+b;
}
}
public static void main(String[] args) throws IOException,InterruptedException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
// String s = br.readLine();
// char[] arr=s.toCharArray();
// ArrayList<Integer> arrl = new ArrayList<Integer>();
// TreeSet<Integer> ts1 = new TreeSet<Integer>();
// HashSet<Integer> h = new HashSet<Integer>();
// HashMap<Integer, Integer> map= new HashMap<>();
// PriorityQueue<String> pQueue = new PriorityQueue<String>();
// LinkedList<String> object = new LinkedList<String>();
// StringBuilder str = new StringBuilder();
//*******************************************************//
// StringTokenizer st = new StringTokenizer(br.readLine());
// int t = Integer.parseInt(st.nextToken());
// while(t-->0){
// st = new StringTokenizer(br.readLine());
// int n = Integer.parseInt(st.nextToken());
// int[] arr = new int[n];
// st = new StringTokenizer(br.readLine());
// for(int i=0; i<n; i++){
// arr[i] =Integer.parseInt(st.nextToken());
// }
// int ans =0;
// out.println(ans);
// }
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
pair[] arr = new pair[n];
st = new StringTokenizer(br.readLine());
for(int i=0; i<n; i++){
arr[i] =new pair(Integer.parseInt(st.nextToken()),i+1);
}
ArrayList<Integer> min = new ArrayList<Integer>();
ArrayList<Integer> max = new ArrayList<Integer>();
int summin=0;
int summax =0;
Arrays.sort(arr);
int i =0; int j = n-2;
boolean f = false;
while(i<=j){
if(i==j){
if(summin<summax){ min.add(arr[i++].b);
summin+=arr[i-1].a;}
else {
max.add(arr[i++].b);
summax+=arr[i-1].a;
}
}else
if(f){
min.add(arr[i++].b);
max.add(arr[j--].b);
summin+=arr[i-1].a;
summax+=arr[j+1].a;
}else{
max.add(arr[i++].b);
min.add(arr[j--].b);
summax+=arr[i-1].a;
summin+=arr[j+1].a;
}
f=!f;
}
Collections.sort(min);
Collections.sort(max);
if(summin<summax){
if(min.size()<=max.size())
min.add(arr[n-1].b);
else{
int x = min.remove(min.size()-1);
min.add(arr[n-1].b);
max.add(x);
}
}
else{
if(max.size()<=min.size())
max.add(arr[n-1].b);
else{
int x = max.remove(min.size()-1);
max.add(arr[n-1].b);
min.add(x);
}}
out.println(min.size());
for( i=0; i<min.size(); i++) out.print(min.get(i)+" ");
out.println();
out.println(max.size());
for( i=0; i<max.size(); i++) out.print(max.get(i)+" ");
out.flush();
}
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 5f733710984596aae52da7774ac6c5c2 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class DivisionIntoTeams
{
public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Player[] pla = new Player[n];
for (int i = 0; i < pla.length; i++)
pla[i] = new Player(i+1, sc.nextInt());
Arrays.sort(pla);
int worst = 0;
int best = pla.length - 1;
StringBuilder team1 = new StringBuilder("");
StringBuilder team2 = new StringBuilder("");
int total1 = 0;
int total2 = 0;
int count1 = 0;
int count2 = 0;
for (int i = 0; i < n; i++)
{
if(total1 <= total2)
{
if(count2 >= count1)
{
team1.append(pla[best].num + " ");
count1 ++;
total1 += pla[best].skill;
best--;
}
else
{
team2.append(pla[worst].num + " ");
count2 ++;
total2 += pla[worst].skill;
worst++;
}
}
else
{
if(count1 >= count2)
{
team2.append(pla[best].num + " ");
count2 ++;
total2 += pla[best].skill;
best--;
}
else
{
team1.append(pla[worst].num + " ");
count1 ++;
total1 += pla[worst].skill;
worst++;
}
}
}
System.out.println(count1);
System.out.println(team1);
System.out.println(count2);
System.out.println(team2);
}
static class Player implements Comparable
{
int num;
int skill;
public Player(int num, int skill)
{
this.num = num;
this.skill = skill;
}
@Override
public int compareTo(Object arg0)
{
// TODO Auto-generated method stub
return this.skill - ((Player)arg0).skill;
}
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException
{
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if(x.charAt(0) == '-')
{
neg = true;
start++;
}
for(int i = start; i < x.length(); i++)
if(x.charAt(i) == '.')
{
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
}
else
{
sb.append(x.charAt(i));
if(dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg?-1:1);
}
public boolean ready() throws IOException {return br.ready();}
}
}
| Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 8631c329f40732182f4dac5af499b575 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main1
{
static class Reader
{
private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
public double d() throws IOException {return Double.parseDouble(s()) ;}
public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = i();}return ret;}
}
///////////////////////////////////////////////////////////////////////////////////////////
// RRRRRRRRR AAA HHH HHH IIIIIIIIIIIII LLL //
// RR RRR AAAAA HHH HHH IIIIIIIIIII LLL //
// RR RRR AAAAAAA HHH HHH III LLL //
// RR RRR AAA AAA HHHHHHHHHHH III LLL //
// RRRRRR AAA AAA HHHHHHHHHHH III LLL //
// RR RRR AAAAAAAAAAAAA HHH HHH III LLL //
// RR RRR AAA AAA HHH HHH IIIIIIIIIII LLLLLLLLLLLL //
// RR RRR AAA AAA HHH HHH IIIIIIIIIIIII LLLLLLLLLLLL //
///////////////////////////////////////////////////////////////////////////////////////////
static class B implements Comparable<B>
{
int x;int y;
public B(int a,int b)
{
x=a;
y=b;
}
public int compareTo(B num)
{
return x-num.x;
}
}
public static void main(String[] args)throws IOException
{
PrintWriter out= new PrintWriter(System.out);
Reader sc=new Reader();
int n=sc.i();
B arr[]=new B[n];
for(int i=0;i<n;i++)
arr[i]=new B(sc.i(),i+1);
Arrays.sort(arr);
ArrayList<Integer> al1=new ArrayList<>();
ArrayList<Integer> al2=new ArrayList<>();
for(int i=0;i<n;i++)
{
if(i%2==0)
al1.add(arr[i].y);
else
al2.add(arr[i].y);
}
out.println(al1.size());
for(int i:al1)
out.print(i+" ");
out.println();
out.println(al2.size());
for(int i:al2)
out.print(i+" ");
out.flush();
}
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 1051a19af0aadbccc968031d37fd36bb | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
import java.lang.management.*;
import static java.lang.Math.*;
@SuppressWarnings("unchecked")
public class P0149C {
public void run() throws Exception {
int n = nextInt(), a [][] = new int [n][], s1 = 0, s2 = 0;
for (int i = 0; i < n; a[i] = new int [] { nextInt(), i + 1 }, i++);
Arrays.sort(a, new Comparator<int []>() {
@Override public int compare(int [] a, int [] b) {
return (a[0] - b[0]);
}
});
List<Integer> c1 = new ArrayList(), c2 = new ArrayList();
for (int i = n - 1; i >= 0; i--) {
if (c1.size() == c2.size()) {
if (s1 <= s2) {
s1 += a[i][0];
c1.add(a[i][1]);
} else {
s2 += a[i][0];
c2.add(a[i][1]);
}
} else {
if (c1.size() <= c2.size()) {
s1 += a[i][0];
c1.add(a[i][1]);
} else {
s2 += a[i][0];
c2.add(a[i][1]);
}
}
}
StringBuilder ans = new StringBuilder();
ans.append(c1.size()).append('\n');
for (int c : c1) { ans.append(c).append(' '); }
ans.append('\n').append(c2.size()).append('\n');
for (int c : c2) { ans.append(c).append(' '); }
println(ans);
}
public static void main(String... args) throws Exception {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedOutputStream(System.out));
new P0149C().run();
br.close();
pw.close();
System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
long gct = 0, gcc = 0;
for (GarbageCollectorMXBean garbageCollectorMXBean : ManagementFactory.getGarbageCollectorMXBeans()) {
gct += garbageCollectorMXBean.getCollectionTime();
gcc += garbageCollectorMXBean.getCollectionCount();
}
System.err.println("[GC time : " + gct + " ms, count = " + gcc + "]");
}
static long startTime = System.currentTimeMillis();
static BufferedReader br;
static PrintWriter pw;
StringTokenizer stok;
String nextToken() throws IOException {
while (stok == null || !stok.hasMoreTokens()) {
String s = br.readLine();
if (s == null) { return null; }
stok = new StringTokenizer(s);
}
return stok.nextToken();
}
void print(byte b) { print("" + b); }
void print(int i) { print("" + i); }
void print(long l) { print("" + l); }
void print(double d) { print("" + d); }
void print(char c) { print("" + c); }
void print(Object o) {
if (o instanceof int[]) { print(Arrays.toString((int [])o));
} else if (o instanceof long[]) { print(Arrays.toString((long [])o));
} else if (o instanceof char[]) { print(Arrays.toString((char [])o));
} else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
} else if (o instanceof short[]) { print(Arrays.toString((short [])o));
} else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
} else if (o instanceof float[]) { print(Arrays.toString((float [])o));
} else if (o instanceof double[]) { print(Arrays.toString((double [])o));
} else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
} else { print("" + o); }
}
void printsp(int [] a) { for (int i = 0, n = a.length; i < n; print(a[i] + " "), i++); }
void print(String s) { pw.print(s); }
void println() { println(""); }
void println(byte b) { println("" + b); }
void println(int i) { println("" + i); }
void println(long l) { println("" + l); }
void println(double d) { println("" + d); }
void println(char c) { println("" + c); }
void println(Object o) { print(o); println(); }
void println(String s) { pw.println(s); }
int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
long nextLong() throws IOException { return Long.parseLong(nextToken()); }
double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
char nextChar() throws IOException { return (char) (br.read()); }
String next() throws IOException { return nextToken(); }
String nextLine() throws IOException { return br.readLine(); }
int [] readInt(int size) throws IOException {
int [] array = new int [size];
for (int i = 0; i < size; i++) { array[i] = nextInt(); }
return array;
}
long [] readLong(int size) throws IOException {
long [] array = new long [size];
for (int i = 0; i < size; i++) { array[i] = nextLong(); }
return array;
}
double [] readDouble(int size) throws IOException {
double [] array = new double [size];
for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
return array;
}
String [] readLines(int size) throws IOException {
String [] array = new String [size];
for (int i = 0; i < size; i++) { array[i] = nextLine(); }
return array;
}
int gcd(int a, int b) {
if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
a = Math.abs(a); b = Math.abs(b);
int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);
a >>>= az; b >>>= bz;
while (a != b) {
if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }
else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }
}
return (a << Math.min(az, bz));
}
long gcd(long a, long b) {
if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
a = Math.abs(a); b = Math.abs(b);
int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);
a >>>= az; b >>>= bz;
while (a != b) {
if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }
else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }
}
return (a << Math.min(az, bz));
}
void shuffle(int [] a) { // RANDOM shuffle
Random r = new Random();
for (int i = a.length - 1, j, t; i >= 0; j = r.nextInt(a.length), t = a[i], a[i] = a[j], a[j] = t, i--);
}
void shuffle(int [] a, int m) { // QUICK shuffle
for (int i = 0, n = a.length, j = m % n, t; i < n; t = a[i], a[i] = a[j], a[j] = t, i++, j = (i * m) % n);
}
void shuffle(long [] a) {
Random r = new Random();
for (int i = a.length - 1; i >= 0; i--) {
int j = r.nextInt(a.length);
long t = a[i]; a[i] = a[j]; a[j] = t;
}
}
void shuffle(Object [] a) {
Random r = new Random();
for (int i = a.length - 1; i >= 0; i--) {
int j = r.nextInt(a.length);
Object t = a[i]; a[i] = a[j]; a[j] = t;
}
}
int [] sort(int [] a) {
final int SHIFT = 16, MASK = (1 << SHIFT) - 1, SIZE = (1 << SHIFT) + 1;
int n = a.length, ta [] = new int [n], ai [] = new int [SIZE];
for (int i = 0; i < n; ai[(a[i] & MASK) + 1]++, i++);
for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);
for (int i = 0; i < n; ta[ai[a[i] & MASK]++] = a[i], i++);
int [] t = a; a = ta; ta = t;
ai = new int [SIZE];
for (int i = 0; i < n; ai[(a[i] >> SHIFT) + 1]++, i++);
for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);
for (int i = 0; i < n; ta[ai[a[i] >> SHIFT]++] = a[i], i++);
return ta;
}
void flush() {
pw.flush();
}
void pause() {
flush(); System.console().readLine();
}
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | a2424a35f30edd4e1044a9319aa59059 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
import java.lang.management.*;
import static java.lang.Math.*;
@SuppressWarnings("unchecked")
public class P0149C {
public void run() throws Exception {
int n = nextInt(), a [][] = new int [n][], s1 = 0, s2 = 0;
for (int i = 0; i < n; a[i] = new int [] { nextInt(), i + 1 }, i++);
shuffle(a);
Arrays.sort(a, new Comparator<int []>() {
@Override public int compare(int [] a, int [] b) {
return (a[0] - b[0]);
}
});
List<Integer> c1 = new ArrayList(), c2 = new ArrayList();
for (int i = n - 1; i >= 0; i--) {
if (c1.size() == c2.size()) {
if (s1 <= s2) {
s1 += a[i][0];
c1.add(a[i][1]);
} else {
s2 += a[i][0];
c2.add(a[i][1]);
}
} else {
if (c1.size() <= c2.size()) {
s1 += a[i][0];
c1.add(a[i][1]);
} else {
s2 += a[i][0];
c2.add(a[i][1]);
}
}
}
println(c1.size()); c1.forEach(this::println);
println(c2.size()); c2.forEach(this::println);
}
public static void main(String... args) throws Exception {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedOutputStream(System.out));
new P0149C().run();
br.close();
pw.close();
System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
long gct = 0, gcc = 0;
for (GarbageCollectorMXBean garbageCollectorMXBean : ManagementFactory.getGarbageCollectorMXBeans()) {
gct += garbageCollectorMXBean.getCollectionTime();
gcc += garbageCollectorMXBean.getCollectionCount();
}
System.err.println("[GC time : " + gct + " ms, count = " + gcc + "]");
}
static long startTime = System.currentTimeMillis();
static BufferedReader br;
static PrintWriter pw;
StringTokenizer stok;
String nextToken() throws IOException {
while (stok == null || !stok.hasMoreTokens()) {
String s = br.readLine();
if (s == null) { return null; }
stok = new StringTokenizer(s);
}
return stok.nextToken();
}
void print(byte b) { print("" + b); }
void print(int i) { print("" + i); }
void print(long l) { print("" + l); }
void print(double d) { print("" + d); }
void print(char c) { print("" + c); }
void print(Object o) {
if (o instanceof int[]) { print(Arrays.toString((int [])o));
} else if (o instanceof long[]) { print(Arrays.toString((long [])o));
} else if (o instanceof char[]) { print(Arrays.toString((char [])o));
} else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
} else if (o instanceof short[]) { print(Arrays.toString((short [])o));
} else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
} else if (o instanceof float[]) { print(Arrays.toString((float [])o));
} else if (o instanceof double[]) { print(Arrays.toString((double [])o));
} else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
} else { print("" + o); }
}
void printsp(int [] a) { for (int i = 0, n = a.length; i < n; print(a[i] + " "), i++); }
void print(String s) { pw.print(s); }
void println() { println(""); }
void println(byte b) { println("" + b); }
void println(int i) { println("" + i); }
void println(long l) { println("" + l); }
void println(double d) { println("" + d); }
void println(char c) { println("" + c); }
void println(Object o) { print(o); println(); }
void println(String s) { pw.println(s); }
int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
long nextLong() throws IOException { return Long.parseLong(nextToken()); }
double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
char nextChar() throws IOException { return (char) (br.read()); }
String next() throws IOException { return nextToken(); }
String nextLine() throws IOException { return br.readLine(); }
int [] readInt(int size) throws IOException {
int [] array = new int [size];
for (int i = 0; i < size; i++) { array[i] = nextInt(); }
return array;
}
long [] readLong(int size) throws IOException {
long [] array = new long [size];
for (int i = 0; i < size; i++) { array[i] = nextLong(); }
return array;
}
double [] readDouble(int size) throws IOException {
double [] array = new double [size];
for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
return array;
}
String [] readLines(int size) throws IOException {
String [] array = new String [size];
for (int i = 0; i < size; i++) { array[i] = nextLine(); }
return array;
}
int gcd(int a, int b) {
if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
a = Math.abs(a); b = Math.abs(b);
int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);
a >>>= az; b >>>= bz;
while (a != b) {
if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }
else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }
}
return (a << Math.min(az, bz));
}
long gcd(long a, long b) {
if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
a = Math.abs(a); b = Math.abs(b);
int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);
a >>>= az; b >>>= bz;
while (a != b) {
if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }
else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }
}
return (a << Math.min(az, bz));
}
void shuffle(int [] a) { // RANDOM shuffle
Random r = new Random();
for (int i = a.length - 1, j, t; i >= 0; j = r.nextInt(a.length), t = a[i], a[i] = a[j], a[j] = t, i--);
}
void shuffle(int [] a, int m) { // QUICK shuffle
for (int i = 0, n = a.length, j = m % n, t; i < n; t = a[i], a[i] = a[j], a[j] = t, i++, j = (i * m) % n);
}
void shuffle(long [] a) {
Random r = new Random();
for (int i = a.length - 1; i >= 0; i--) {
int j = r.nextInt(a.length);
long t = a[i]; a[i] = a[j]; a[j] = t;
}
}
void shuffle(Object [] a) {
Random r = new Random();
for (int i = a.length - 1; i >= 0; i--) {
int j = r.nextInt(a.length);
Object t = a[i]; a[i] = a[j]; a[j] = t;
}
}
int [] sort(int [] a) {
final int SHIFT = 16, MASK = (1 << SHIFT) - 1, SIZE = (1 << SHIFT) + 1;
int n = a.length, ta [] = new int [n], ai [] = new int [SIZE];
for (int i = 0; i < n; ai[(a[i] & MASK) + 1]++, i++);
for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);
for (int i = 0; i < n; ta[ai[a[i] & MASK]++] = a[i], i++);
int [] t = a; a = ta; ta = t;
ai = new int [SIZE];
for (int i = 0; i < n; ai[(a[i] >> SHIFT) + 1]++, i++);
for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);
for (int i = 0; i < n; ta[ai[a[i] >> SHIFT]++] = a[i], i++);
return ta;
}
void flush() {
pw.flush();
}
void pause() {
flush(); System.console().readLine();
}
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | a37c520070a298685c767224fa6741b6 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
import java.lang.management.*;
import static java.lang.Math.*;
@SuppressWarnings("unchecked")
public class P0149C {
public void run() throws Exception {
int n = nextInt(), a [][] = new int [n][], s1 = 0, s2 = 0;
for (int i = 0; i < n; a[i] = new int [] { nextInt(), i + 1 }, i++);
Arrays.sort(a, new Comparator<int []>() {
@Override public int compare(int [] a, int [] b) {
return (a[0] - b[0]);
}
});
List<Integer> c1 = new ArrayList(), c2 = new ArrayList();
for (int i = n - 1; i >= 0; i--) {
if (c1.size() == c2.size()) {
if (s1 <= s2) {
s1 += a[i][0];
c1.add(a[i][1]);
} else {
s2 += a[i][0];
c2.add(a[i][1]);
}
} else {
if (c1.size() <= c2.size()) {
s1 += a[i][0];
c1.add(a[i][1]);
} else {
s2 += a[i][0];
c2.add(a[i][1]);
}
}
}
println(c1.size()); c1.forEach(this::println);
println(c2.size()); c2.forEach(this::println);
}
public static void main(String... args) throws Exception {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedOutputStream(System.out));
new P0149C().run();
br.close();
pw.close();
System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
long gct = 0, gcc = 0;
for (GarbageCollectorMXBean garbageCollectorMXBean : ManagementFactory.getGarbageCollectorMXBeans()) {
gct += garbageCollectorMXBean.getCollectionTime();
gcc += garbageCollectorMXBean.getCollectionCount();
}
System.err.println("[GC time : " + gct + " ms, count = " + gcc + "]");
}
static long startTime = System.currentTimeMillis();
static BufferedReader br;
static PrintWriter pw;
StringTokenizer stok;
String nextToken() throws IOException {
while (stok == null || !stok.hasMoreTokens()) {
String s = br.readLine();
if (s == null) { return null; }
stok = new StringTokenizer(s);
}
return stok.nextToken();
}
void print(byte b) { print("" + b); }
void print(int i) { print("" + i); }
void print(long l) { print("" + l); }
void print(double d) { print("" + d); }
void print(char c) { print("" + c); }
void print(Object o) {
if (o instanceof int[]) { print(Arrays.toString((int [])o));
} else if (o instanceof long[]) { print(Arrays.toString((long [])o));
} else if (o instanceof char[]) { print(Arrays.toString((char [])o));
} else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
} else if (o instanceof short[]) { print(Arrays.toString((short [])o));
} else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
} else if (o instanceof float[]) { print(Arrays.toString((float [])o));
} else if (o instanceof double[]) { print(Arrays.toString((double [])o));
} else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
} else { print("" + o); }
}
void printsp(int [] a) { for (int i = 0, n = a.length; i < n; print(a[i] + " "), i++); }
void print(String s) { pw.print(s); }
void println() { println(""); }
void println(byte b) { println("" + b); }
void println(int i) { println("" + i); }
void println(long l) { println("" + l); }
void println(double d) { println("" + d); }
void println(char c) { println("" + c); }
void println(Object o) { print(o); println(); }
void println(String s) { pw.println(s); }
int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
long nextLong() throws IOException { return Long.parseLong(nextToken()); }
double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
char nextChar() throws IOException { return (char) (br.read()); }
String next() throws IOException { return nextToken(); }
String nextLine() throws IOException { return br.readLine(); }
int [] readInt(int size) throws IOException {
int [] array = new int [size];
for (int i = 0; i < size; i++) { array[i] = nextInt(); }
return array;
}
long [] readLong(int size) throws IOException {
long [] array = new long [size];
for (int i = 0; i < size; i++) { array[i] = nextLong(); }
return array;
}
double [] readDouble(int size) throws IOException {
double [] array = new double [size];
for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
return array;
}
String [] readLines(int size) throws IOException {
String [] array = new String [size];
for (int i = 0; i < size; i++) { array[i] = nextLine(); }
return array;
}
int gcd(int a, int b) {
if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
a = Math.abs(a); b = Math.abs(b);
int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);
a >>>= az; b >>>= bz;
while (a != b) {
if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }
else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }
}
return (a << Math.min(az, bz));
}
long gcd(long a, long b) {
if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
a = Math.abs(a); b = Math.abs(b);
int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);
a >>>= az; b >>>= bz;
while (a != b) {
if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }
else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }
}
return (a << Math.min(az, bz));
}
void shuffle(int [] a) { // RANDOM shuffle
Random r = new Random();
for (int i = a.length - 1, j, t; i >= 0; j = r.nextInt(a.length), t = a[i], a[i] = a[j], a[j] = t, i--);
}
void shuffle(int [] a, int m) { // QUICK shuffle
for (int i = 0, n = a.length, j = m % n, t; i < n; t = a[i], a[i] = a[j], a[j] = t, i++, j = (i * m) % n);
}
void shuffle(long [] a) {
Random r = new Random();
for (int i = a.length - 1; i >= 0; i--) {
int j = r.nextInt(a.length);
long t = a[i]; a[i] = a[j]; a[j] = t;
}
}
void shuffle(Object [] a) {
Random r = new Random();
for (int i = a.length - 1; i >= 0; i--) {
int j = r.nextInt(a.length);
Object t = a[i]; a[i] = a[j]; a[j] = t;
}
}
int [] sort(int [] a) {
final int SHIFT = 16, MASK = (1 << SHIFT) - 1, SIZE = (1 << SHIFT) + 1;
int n = a.length, ta [] = new int [n], ai [] = new int [SIZE];
for (int i = 0; i < n; ai[(a[i] & MASK) + 1]++, i++);
for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);
for (int i = 0; i < n; ta[ai[a[i] & MASK]++] = a[i], i++);
int [] t = a; a = ta; ta = t;
ai = new int [SIZE];
for (int i = 0; i < n; ai[(a[i] >> SHIFT) + 1]++, i++);
for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);
for (int i = 0; i < n; ta[ai[a[i] >> SHIFT]++] = a[i], i++);
return ta;
}
void flush() {
pw.flush();
}
void pause() {
flush(); System.console().readLine();
}
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 879023edfbcc249d1c676638c3edc046 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.util.*;
import java.io.*;
public class A
{
public static void main(String ar[]) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String s1[]=br.readLine().split(" ");
int a[][]=new int[n][2];
for(int i=0;i<n;i++)
{ a[i][0]=Integer.parseInt(s1[i]); a[i][1]=i+1; }
Arrays.sort(a,new Comparator<int[]>(){
public int compare(final int f1[],final int f2[])
{
if(f1[0]>f2[0])
return 1;
else if(f1[0]==f2[0])
return 0;
else
return -1;
}
});
ArrayList<Integer> a1=new ArrayList<Integer>();
ArrayList<Integer> a2=new ArrayList<Integer>();
int sum1=0,sum2=0;
for(int i=0;i<n;i++)
{
if(i%2==0)
a1.add(a[i][1]);
else
a2.add(a[i][1]);
}
System.out.println(n/2+n%2);
for(int i=0;i<a1.size();i++)
System.out.print(a1.get(i)+" ");
System.out.println();
System.out.println(n/2);
for(int i=0;i<a2.size();i++)
System.out.print(a2.get(i)+" ");
}
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | 220e6a04b4121f45689d7aab751b3035 | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.util.*;
public class Solution
{
public static void main(String []args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arr[] = new int[n];
for(int i = 0 ; i < n ; i++)
{
arr[i] = sc.nextInt();
}
Integer index[] = new Integer[n];
for(int i = 0 ; i < n ; i++)
{
index[i] = i;
}
IndexSort comparator = new IndexSort(arr);
Arrays.sort(index , comparator);
System.out.println(n - n/2);
for(int i = 0 ; i < n ; i = i + 2)
{
System.out.print(index[i] + 1);
System.out.print(" ");
}
System.out.println();
System.out.println(n/2);
for(int i = 1 ; i < n ; i = i + 2)
{
System.out.print(index[i] + 1);
System.out.print(" ");
}
}
}
class IndexSort implements Comparator<Integer>
{
int arr[];
public IndexSort(int arr[])
{
this.arr = arr;
}
public int compare(Integer index1 , Integer index2)
{
return arr[index1] - arr[index2];
}
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | bad7b0c917629566bdddb9d254bd978c | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class C {
public static void main(String cd[]){
Scanner in=new Scanner(System.in);
int n=in.nextInt();
nodE a[]=new nodE[n];
for(int i=0;i<n;i++){
a[i]=new nodE(in.nextInt(),i+1);
}
Arrays.sort(a);
System.out.println(n-n/2);
for(int i=0;i<n;i+=2){
System.out.print(a[i].pos+" ");
}
System.out.println();
System.out.println(n/2);
for(int i=1;i<n;i+=2){
System.out.print(a[i].pos+" ");
}
System.out.println();
}
}
class nodE implements Comparable<nodE>{
int val;
int pos;
nodE(int val,int pos){
this.val=val;
this.pos=pos;
}
@Override
public int compareTo(nodE o) {
// TODO Auto-generated method stub
return this.val-o.val;
}
} | Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output | |
PASSED | a13107c74b8107ecf646e662dd33ef5d | train_002.jsonl | 1328886000 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (xβ+βyβ=βn). The sizes of teams differ in no more than one (|xβ-βy|ββ€β1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | 256 megabytes | // package april2020;
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
public class C {
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader scn = new FastReader();
int n = scn.nextInt();
Pair[] a = new Pair[n];
for(int i =1;i<=n;i++) {
a[i-1] = new Pair(scn.nextInt(),i);
}
Arrays.sort(a);
boolean chance =true;
int x = 0;
ArrayList<Pair> xp = new ArrayList<Pair>();
int y = 0;
ArrayList<Pair> yp = new ArrayList<Pair>();
for(int i=n-1;i>=0;i--) {
if(chance) {
x+=a[i].v;xp.add(a[i]);
}else {
y+=a[i].v;yp.add(a[i]);
}
chance^=true;
}
if(Math.abs(x-y)>a[n-1].v) {
Pair rp = xp.remove(xp.size()-1);
// x--;
yp.add(rp);
}
System.out.println(xp.size());
for(int i=0;i<xp.size();i++) {
System.out.print(xp.get(i).i+" ");
}
System.out.println();
System.out.println(yp.size());
for(int i =0;i<yp.size();i++) {
System.out.print(yp.get(i).i+" ");
}
System.out.println();
}
static class Pair implements Comparable<Pair>{
int v;
int i;
public Pair(int v, int i) {
this.v = v;
this.i = i;
}
@Override
public int compareTo(Pair o) {
// TODO Auto-generated method stub
return this.v-o.v;
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n1 2 1", "5\n2 3 3 1 1"] | 1 second | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, the third limitation on the difference in skills ((2β+β1)β-β(1)β=β2ββ€β2) is fulfilled. | Java 8 | standard input | [
"sortings",
"greedy",
"math"
] | 0937a7e2f912fc094cc4275fd47cd457 | The first line contains the only integer n (2ββ€βnββ€β105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1ββ€βaiββ€β104), the i-th number represents the i-th boy's playing skills. | 1,500 | On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: xβ+βyβ=βn, |xβ-βy|ββ€β1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.