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
|
f3d7e7325064cd80408ed9ac71498fa4
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int balance = 0;
String s = in.next();
for (int i = 0; i < s.length(); i++)
if (s.charAt(i) == 'x')
balance++;
else
balance--;
if (balance < 0)
for (int i = 0; i < -balance; i++)
out.print('y');
else
for (int i = 0; i < balance; i++)
out.print('x');
out.println();
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
48c4b82b52a03211cd02de3fe0403da4
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;
public class CodeParsing implements Runnable {
void solve() throws IOException {
String s = readString();
int x = 0;
for (int i = 0; i < s.length(); i ++) {
char c = s.charAt(i);
if (c == 'x')
x ++;
else
x --;
}
char c = 'x';
if (x < 0)
c = 'y';
x = Math.abs(x);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < x; i ++)
sb.append(c);
out.println(sb);
}
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
public static void main(String[] args) {
new CodeParsing().run();
}
public void run() {
try {
long t1 = System.currentTimeMillis();
if (System.getProperty("ONLINE_JUDGE") != null) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
in = new BufferedReader(new FileReader("/Users/shenchen/input.txt"));
out = new PrintWriter("/Users/shenchen/output.txt");
}
Locale.setDefault(Locale.US);
solve();
in.close();
out.close();
long t2 = System.currentTimeMillis();
System.err.println("Time = " + (t2 - t1));
} catch (Throwable t) {
t.printStackTrace(System.err);
System.exit(-1);
}
}
String readString() throws IOException {
while (!tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
int readInt() throws IOException {
return Integer.parseInt(readString());
}
long readLong() throws IOException {
return Long.parseLong(readString());
}
double readDouble() throws IOException {
return Double.parseDouble(readString());
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
d419e12c7783ba581cd7e6c6644ea389
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Example {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (Exception e) {
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
public void run() throws Exception {
//in = new BufferedReader(new FileReader("input.txt"));
//out = new PrintWriter(new FileWriter("output.txt"));
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.flush();
out.close();
in.close();
}
public void solve() throws Exception {
char[] c = next().toCharArray();
int n = c.length;
int x = 0;
int y = 0;
for (int i = 0; i < n; i++) {
if (c[i] == 'x') {
x++;
} else {
y++;
}
}
if (x > y) {
for (int i = 0; i < x - y; i++) {
out.print("x");
}
} else {
for (int i = 0; i < y - x; i++) {
out.print("y");
}
}
out.println();
}
public static void main(String[] args) throws Exception {
new Example().run();
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
3cd0ecec7e5535cd6ed242650605eeb3
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
//package example;
import java.io.*;
import java.util.*;
public class Example {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (Exception e) {
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
public void run() throws Exception {
//in = new BufferedReader(new FileReader("input.txt"));
//out = new PrintWriter(new FileWriter("output.txt"));
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.flush();
out.close();
in.close();
}
public void solve() throws Exception {
char[] c = next().toCharArray();
int n = c.length;
int x = 0;
int y = 0;
for (int i = 0; i < n; i++) {
if (c[i] == 'x') {
x++;
} else {
y++;
}
}
if (x > y) {
for (int i = 0; i < x - y; i++) {
out.print("x");
}
} else {
for (int i = 0; i < y - x; i++) {
out.print("y");
}
}
out.println();
}
public static void main(String[] args) throws Exception {
new Example().run();
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
7dc3efed02bbdd4335211452be5e3abf
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.util.Scanner;
public class ParseCode {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String s=sc.nextLine();
int x;
int y=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='y'){
y++;//n
}
}
x=s.length()-y;
if(x>y){
for(int i=0;i<x-y;i++){
System.out.print("x");
}
}else if(y>x){
for(int i=0;i<y-x;i++){
System.out.print("y");
}
}else{
System.out.print("");
}
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
8d2f41eb1956dfa03f904e59993feaf7
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.Queue;
import java.util.Stack;
public class Main {
private StringTokenizer st;
private BufferedReader bf;
StringBuilder sb = new StringBuilder("");
public void readInput() throws IOException {
st = new StringTokenizer(bf.readLine());
}
public Integer nextInt(String s) {
return Integer.valueOf(s);
}
public Double nextDouble(String s) {
return Double.valueOf(s);
}
public void run() {
try {
bf = new BufferedReader(new InputStreamReader(System.in));
char c = ' ';
int x = 0, y = 0;
while ((c = (char) bf.read()) != '\n') {
if (c == 'x') {
x++;
} else if (c == 'y') {
y++;
}
}
if (x > y) {
for (int i = 1; i <= x - y; i++) {
System.out.print('x');
}
System.out.println();
} else {
for (int i = 1; i <= y - x; i++) {
System.out.print('y');
}
System.out.println();
}
} catch (Exception e) {
System.out.println("Exception");
}
}
public static void main(String[] args) {
new Main().run();
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
1d1385b2eb861ac54fb35a2dd0322362
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.io.*;
public class CF156B {
/**
* @param args
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
char[] chars = br.readLine().toCharArray();
int nx = 0;
int ny = 0;
for(int i = 0; i < chars.length; i++){
if(chars[i] == 'x')nx++;
if(chars[i] == 'y')ny++;
}
if(nx > ny){
for(int i = 0; i < (nx-ny); i++){
System.out.print("x");
}
} else{
for(int i = 0; i < (ny-nx); i++){
System.out.print("y");
}
}
System.out.println();
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
36900cabceae3e9fddb83a2187f6db1c
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.util.*;
public class cf255b {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x = 0, y = 0;
for(char z : in.next().trim().toCharArray())
if(z=='x') x++;
else y++;
int v = Math.min(x,y);
x -= v;
y -= v;
StringBuilder sb = new StringBuilder();
for(int i=0; i<x; i++)
sb.append('x');
for(int i=0; i<y; i++)
sb.append('y');
System.out.println(sb.toString());
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
639752077d5f9066535c06b44aacfd60
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.lang.StringBuilder;
public class Solution255B {
public static void main(String[] args) {
//Scanner sc = new Scanner(System.in);
MyScanner sc = new MyScanner();
String line = sc.nextLine();
int countX = 0;
int countY = 0;
for (int i = 0 ; i < line.length() ; i++) {
if (line.charAt(i) == 'x') {
countX++;
} else if (line.charAt(i) == 'y') {
countY++;
}
}
if(countX > countY) {
for (int i = 0 ; i < countX - countY ; i++) {
System.out.print('x');
}
} else {
for (int i = 0 ; i < countY - countX ; i++) {
System.out.print('y');
}
}
System.out.println();
}
}
class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
fc3d3026ce54676efa5568d786366333
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class B {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
char[] s=in.nextLine().toCharArray();
int s1=0;
int s2=0;
for(int i=0; i<s.length; i++){
if(s[i]=='x'){
s1++;
}
else{
s2++;
}
}
if(s1>s2){
for(int i=0; i<s1-s2; i++){
out.print('x');
}
}
else{
for(int i=0; i<s2-s1; i++){
out.print('y');
}
}
out.close();
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
c3af3bc50aeb22dab673b455d7357e2c
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
static BufferedReader br;
static StringTokenizer st;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
int num = 0;
for(int i = 0; i < str.length(); i++) {
if(str.charAt(i) == 'x')
num++;
else
num--;
}
char print = num > 0 ? 'x' : 'y';
num = Math.abs(num);
while(num-- > 0)
System.out.print(print);
}
public static String nextToken() throws IOException {
while(st == null || !st.hasMoreTokens()) {
if(!br.ready()) {
System.exit(0);
}
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public static int readInt() throws IOException {
return Integer.parseInt(nextToken());
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
b8372c0f309f60f55879a6a90b86caf5
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
public static long rotateRight(long n, int i) {
return Long.rotateRight(n, 32 + i);
}
public static long xor(long a, long b) {
return a ^ b;
}
public static void main(String[] args) throws Exception {
FastScanner kb = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
// ///////////////////////
String a = kb.nextString();
int x = 0;
int y = 0;
for (int i = 0; i < a.length(); i++) {
char temp = a.charAt(i);
if (temp == 'x')
x++;
else if (temp == 'y')
y++;
}
if (y > x) {
y = y - x;
for (int i = 0; i < y; i++) {
out.print("y");
}
} else if (x > y) {
x = x - y;
for (int i = 0; i < x; i++) {
out.print("x");
}
}
// ///////////////////////
out.close();
}
}
class FastScanner {
final private int BUFFER_SIZE = 1 << 19;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public FastScanner(InputStream in) {
din = new DataInputStream(in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String nextString() throws Exception {
StringBuffer sb = new StringBuffer("");
byte c = read();
while (c <= ' ')
c = read();
do {
sb.append((char) c);
c = read();
} while (c > ' ');
return sb.toString();
}
public char nextChar() throws Exception {
byte c = read();
while (c <= ' ')
c = read();
return (char) c;
}
public int nextInt() throws Exception {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = c == '-';
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws Exception {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = c == '-';
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws Exception {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws Exception {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
9ec9a779d4dac63e56b93b6b61d065a3
|
train_001.jsonl
|
1355671800
|
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class BB {
static StringTokenizer st;
static BufferedReader in;
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
String s = next();
int x = 0, y = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i)=='x')
x++;
else
y++;
}
int diff = Math.abs(x-y);
char w = 'x';
if (y > x)
w = 'y';
for (int i = 1; i <= diff; i++) {
pw.print(w);
}
pw.println();
pw.close();
}
private static int nextInt() throws IOException{
return Integer.parseInt(next());
}
private static long nextLong() throws IOException{
return Long.parseLong(next());
}
private static double nextDouble() throws IOException{
return Double.parseDouble(next());
}
private static String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
}
|
Java
|
["x", "yxyxy", "xxxxxy"]
|
2 seconds
|
["x", "y", "xxxx"]
|
NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
|
Java 6
|
standard input
|
[
"implementation"
] |
528459e7624f90372cb2c3a915529a23
|
The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
| 1,200 |
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.
|
standard output
| |
PASSED
|
f54dbda12163727e8e37e739cafa08eb
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.InputMismatchException;
public class B1268 {
static class Solver {
int N;
long A, B;
void solve(int testNumber, FastScanner s, PrintWriter out) {
N = s.nextInt();
for(int i = 0; i < N; i++) {
long x = s.nextInt();
if(i % 2 == 0) {
A += (x + 1) / 2;
B += (x / 2);
} else {
B += (x + 1) / 2;
A += (x / 2);
}
}
out.println(A < B ? A : B);
}
}
final static boolean cases = false;
public static void main(String[] args) {
FastScanner s = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
Solver solver = new Solver();
for (int t = 1, T = cases ? s.nextInt() : 1; t <= T; t++)
solver.solve(t, s, out);
out.close();
}
static int min(int a, int b) {
return a < b ? a : b;
}
static int max(int a, int b) {
return a > b ? a : b;
}
static long min(long a, long b) {
return a < b ? a : b;
}
static long max(long a, long b) {
return a > b ? a : b;
}
static int swap(int a, int b) {
return a;
}
static Object swap(Object a, Object b) {
return a;
}
static String ts(Object... o) {
return Arrays.deepToString(o);
}
static class FastScanner {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastScanner(InputStream stream) {
this.stream = stream;
}
public FastScanner(File f) throws FileNotFoundException {
this(new FileInputStream(f));
}
public FastScanner(String s) {
this.stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
}
int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
boolean isEndline(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isEndline(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndline(c));
return res.toString();
}
// Jacob Garbage
public int[] nextIntArray(int N) {
int[] ret = new int[N];
for (int i = 0; i < N; i++)
ret[i] = this.nextInt();
return ret;
}
public int[][] next2DIntArray(int N, int M) {
int[][] ret = new int[N][];
for (int i = 0; i < N; i++)
ret[i] = this.nextIntArray(M);
return ret;
}
public long[] nextLongArray(int N) {
long[] ret = new long[N];
for (int i = 0; i < N; i++)
ret[i] = this.nextLong();
return ret;
}
public long[][] next2DLongArray(int N, int M) {
long[][] ret = new long[N][];
for (int i = 0; i < N; i++)
ret[i] = nextLongArray(M);
return ret;
}
public double[] nextDoubleArray(int N) {
double[] ret = new double[N];
for (int i = 0; i < N; i++)
ret[i] = this.nextDouble();
return ret;
}
public double[][] next2DDoubleArray(int N, int M) {
double[][] ret = new double[N][];
for (int i = 0; i < N; i++)
ret[i] = this.nextDoubleArray(M);
return ret;
}
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
d413e8e7bea645ff4b7c610334d86e19
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.*;
import java.util.StringTokenizer;
public class B {
FastScanner scanner;
PrintWriter writer;
void solve() throws IOException {
scanner = new FastScanner(System.in);
writer = new PrintWriter(System.out);
int n = scanner.nextInt();
long b = 0;
long w = 0;
for (int i = 0; i < n; i++) {
int a = scanner.nextInt();
if (i % 2 == 0) {
b += (a + 1) / 2;
w += a / 2;
} else {
b += a / 2;
w += (a + 1) / 2;
}
}
writer.println(Math.min(b, w));
writer.close();
}
public static void main(String... args) throws IOException {
new B().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
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
82c06e6261b900a8be4aef35de8190a4
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Locale;
import java.util.StringTokenizer;
public class Solution implements Runnable {
private PrintStream out;
private BufferedReader in;
private StringTokenizer st;
public void solve() throws IOException {
long time0 = System.currentTimeMillis();
int n = nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
long answer = solve(n, a);
out.println(answer);
System.err.println("time: " + (System.currentTimeMillis() - time0));
}
private long solve(int n, int[] a) {
long black = 0;
long white = 0;
for (int i = 0; i < n; i++) {
black += (a[i] + (i % 2)) / 2;
white += (a[i] + ((i + 1) % 2)) / 2;
}
return Math.min(black, white);
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public String next() throws IOException {
while (!st.hasMoreTokens()) {
String line = in.readLine();
if (line == null) {
return null;
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
@Override
public void run() {
try {
solve();
out.close();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
public Solution(String name) throws IOException {
Locale.setDefault(Locale.US);
if (name == null) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintStream(new BufferedOutputStream(System.out));
} else {
in = new BufferedReader(new InputStreamReader(new FileInputStream(name + ".in")));
out = new PrintStream(new BufferedOutputStream(new FileOutputStream(name + ".out")));
}
st = new StringTokenizer("");
}
public static void main(String[] args) throws IOException {
new Thread(new Solution(null)).start();
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
94eaeeca11b65acac08e991b2f714ed2
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import static java.lang.Math.*;
public class B {
public Object solve () {
int N = sc.nextInt();
int [] A = sc.nextInts();
long B = 0, W = 0;
for (int i : rep(N))
if (i % 2 == 0) {
long b = A[i] / 2, w = A[i] - b;
B += b; W += w;
}
else {
long w = A[i] / 2, b = A[i] - w;
B += b; W += w;
}
long res = min(B, W);
return res;
}
private static final int CONTEST_TYPE = 1;
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; }
//////////////////////////////////////////////////////////////////////////////////// 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(); }
//////////////////////////////////////////////
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 B().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
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
10e621204725b902e8187ec28d274f14
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class cf1 {
static long mod = (long)1e9 + 7;
static long mod1 = 998244353;
static FastScanner f;
static PrintWriter pw = new PrintWriter(System.out);
static Scanner S = new Scanner(System.in);
static long x0; static long y0;
static int inf = (int)(1e9);
static long iinf = (long)(1e18);
static void solve()throws IOException {
int n = f.ni();
long a = 0 , b = 0;
for(int i = 0; i < n; ++i) {
long x = f.nl();
a += x / 2;
b += x / 2;
if(ise(i)) a += x % 2;
else b += x % 2;
}
pn(Math.min(a , b));
}
public static void main(String[] args)throws IOException {
init();
int t = 1;
while(t --> 0) {solve();}
pw.flush();
pw.close();
}
/******************************END OF MAIN PROGRAM*******************************************/
public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
public static class FastScanner {
BufferedReader br;StringTokenizer st;
FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}
}
public static void pn(Object o){pw.println(o);}
public static void p(Object o){pw.print(o);}
public static void pni(Object o){pw.println(o);pw.flush();}
static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
static long gcd(long a,long b){if(b==0l)return a;else{return gcd(b,a%b);}}
static long lcm(long a,long b){return (a*b/gcd(a,b));}
static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
static long mpow(long a,long b){long res=1;while(b>0l){if((b&1)==1l)res=((res%mod)*(a%mod))%mod;b>>=1l;a=((a%mod)*(a%mod))%mod;}return res;}
static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
static int log2(int x){return (int)(Math.log(x)/Math.log(2));}
static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
static int gnv(char c){return Character.getNumericValue(c);}//No. of integers less than equal to i in ub
static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
static int upperbound(int a[],int i){int lo=0,hi=a.length-1,mid=0;int count=0;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]<=i){count=mid+1;lo=mid+1;}else hi=mid-1;}return count;}
static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
static void sort(ArrayList<Integer> a){Collections.sort(a);}//!Precompute fact in ncr()!
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
0a619840aa17ec1c30e7ea531ec293bf
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class B{
static PrintWriter out;
static InputReader in;
public static void main(String args[]){
out = new PrintWriter(System.out);
in = new InputReader();
new B();
out.flush(); out.close();
}
B(){
solve();
}
void solve(){
int n = in.nextInt();
long tot = 0;
int a[] = new int[n];
for(int i = 0; i < n; i++)tot += a[i] = in.nextInt();
long c = 0; int p = -1;
for(int i = n - 1; i >= 0; i--){
boolean even = a[i] % 2 == 0, odd = !even;
if(c == 0){
if(odd){
c = 1; p = 1;
}
}else if(c == 1){
if(p == 1){
if(odd){
c = 0;
}else{
c = 1;
}
p = 2;
}else{
if(odd){
c = 2;
}else{
c = 1;
}
p = 1;
}
}else{
if(p == 1){
if(odd){
c--;
}
p = 2;
}else{
if(odd){
c++;
}
p = 1;
}
}
}
out.print((tot - c) / 2);
}
public static class InputReader{
BufferedReader br;
StringTokenizer st;
InputReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
public String next(){
while(st == null || !st.hasMoreTokens()){
try{
st = new StringTokenizer(br.readLine());
}catch(IOException e){}
}
return st.nextToken();
}
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
851e7b2d2e2cd659bc396228aa0a87d0
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) throws Exception {
Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
thread.start();
thread.join();
}
static class TaskAdapter implements Runnable {
@Override
public void run() {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastInput in = new FastInput(inputStream);
FastOutput out = new FastOutput(outputStream);
BDominoForYoung solver = new BDominoForYoung();
solver.solve(1, in, out);
out.close();
}
}
static class BDominoForYoung {
public void solve(int testNumber, FastInput in, FastOutput out) {
int n = in.readInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.readInt();
}
long ans = 0;
int first = 0;
IntegerDequeImpl deque = new IntegerDequeImpl(n);
for (int i = 0; i < n; i++) {
while (!deque.isEmpty() && first + deque.peekLast() > a[i]) {
deque.removeLast();
}
if (deque.isEmpty()) {
ans += a[i] / 2;
if (a[i] % 2 == 1) {
deque.addLast(1);
first = 0;
}
} else {
ans += deque.size();
int remain = a[i] - (first + deque.peekLast());
ans += remain / 2;
if (first == 0) {
if (remain % 2 == 0) {
deque.removeLast();
} else {
}
} else {
if (remain % 2 == 0) {
} else {
deque.addLast(deque.peekLast() + first + 1);
}
}
first = 1 - first;
}
}
out.println(ans);
}
}
static class IntegerDequeImpl implements IntegerDeque {
private int[] data;
private int bpos;
private int epos;
private static final int[] EMPTY = new int[0];
private int n;
public IntegerDequeImpl(int cap) {
if (cap == 0) {
data = EMPTY;
} else {
data = new int[cap];
}
bpos = 0;
epos = 0;
n = cap;
}
private void expandSpace(int len) {
while (n < len) {
n = Math.max(n + 10, n * 2);
}
int[] newData = new int[n];
if (bpos <= epos) {
if (bpos < epos) {
System.arraycopy(data, bpos, newData, 0, epos - bpos);
}
} else {
System.arraycopy(data, bpos, newData, 0, data.length - bpos);
System.arraycopy(data, 0, newData, data.length - bpos, epos);
}
epos = size();
bpos = 0;
data = newData;
}
public IntegerIterator iterator() {
return new IntegerIterator() {
int index = bpos;
public boolean hasNext() {
return index != epos;
}
public int next() {
int ans = data[index];
index = IntegerDequeImpl.this.next(index);
return ans;
}
};
}
public int removeLast() {
int ans = data[last(epos)];
epos = last(epos);
return ans;
}
public void addLast(int x) {
ensureMore();
data[epos] = x;
epos = next(epos);
}
public int peekLast() {
return data[last(epos)];
}
private int last(int x) {
return (x == 0 ? n : x) - 1;
}
private int next(int x) {
return x + 1 >= n ? 0 : x + 1;
}
private void ensureMore() {
if (next(epos) == bpos) {
expandSpace(n + 1);
}
}
public int size() {
int ans = epos - bpos;
if (ans < 0) {
ans += data.length;
}
return ans;
}
public boolean isEmpty() {
return bpos == epos;
}
public String toString() {
StringBuilder builder = new StringBuilder();
for (IntegerIterator iterator = iterator(); iterator.hasNext(); ) {
builder.append(iterator.next()).append(' ');
}
return builder.toString();
}
}
static interface IntegerDeque extends IntegerStack {
}
static class FastOutput implements AutoCloseable, Closeable {
private StringBuilder cache = new StringBuilder(10 << 20);
private final Writer os;
public FastOutput(Writer os) {
this.os = os;
}
public FastOutput(OutputStream os) {
this(new OutputStreamWriter(os));
}
public FastOutput println(long c) {
cache.append(c).append('\n');
return this;
}
public FastOutput flush() {
try {
os.append(cache);
os.flush();
cache.setLength(0);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return this;
}
public void close() {
flush();
try {
os.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public String toString() {
return cache.toString();
}
}
static interface IntegerIterator {
boolean hasNext();
int next();
}
static class FastInput {
private final InputStream is;
private byte[] buf = new byte[1 << 13];
private int bufLen;
private int bufOffset;
private int next;
public FastInput(InputStream is) {
this.is = is;
}
private int read() {
while (bufLen == bufOffset) {
bufOffset = 0;
try {
bufLen = is.read(buf);
} catch (IOException e) {
bufLen = -1;
}
if (bufLen == -1) {
return -1;
}
}
return buf[bufOffset++];
}
public void skipBlank() {
while (next >= 0 && next <= 32) {
next = read();
}
}
public int readInt() {
int sign = 1;
skipBlank();
if (next == '+' || next == '-') {
sign = next == '+' ? 1 : -1;
next = read();
}
int val = 0;
if (sign == 1) {
while (next >= '0' && next <= '9') {
val = val * 10 + next - '0';
next = read();
}
} else {
while (next >= '0' && next <= '9') {
val = val * 10 - next + '0';
next = read();
}
}
return val;
}
}
static interface IntegerStack {
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
22d40ca970b881eadc6e2fdcc5bf581a
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
public class Main {
private static void solve() {
int n = ni();
int[] a = na(n);
System.out.println(Math.max(f(a, true), f(a, false)));
}
private static long f(int[] a, boolean flg) {
int n = a.length;
long ret = 0;
long sum = 0;
for (int i = 0; i < n; i++) {
int x = a[i] + (flg ? 1 : 0);
ret += x / 2;
flg = !flg;
sum += a[i];
}
return Math.min(ret, sum - ret);
}
public static void main(String[] args) {
new Thread(null, new Runnable() {
@Override
public void run() {
long start = System.currentTimeMillis();
String debug = args.length > 0 ? args[0] : null;
if (debug != null) {
try {
is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
solve();
out.flush();
tr((System.currentTimeMillis() - start) + "ms");
}
}, "", 64000000).start();
}
private static java.io.InputStream is = System.in;
private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
private static java.util.StringTokenizer tokenizer = null;
private static java.io.BufferedReader reader;
public static String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new java.util.StringTokenizer(reader.readLine());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
private static double nd() {
return Double.parseDouble(next());
}
private static long nl() {
return Long.parseLong(next());
}
private static int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = ni();
return a;
}
private static char[] ns() {
return next().toCharArray();
}
private static long[] nal(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nl();
return a;
}
private static int[][] ntable(int n, int m) {
int[][] table = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
table[i][j] = ni();
}
}
return table;
}
private static int[][] nlist(int n, int m) {
int[][] table = new int[m][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
table[j][i] = ni();
}
}
return table;
}
private static int ni() {
return Integer.parseInt(next());
}
private static void tr(Object... o) {
if (is != System.in)
System.out.println(java.util.Arrays.deepToString(o));
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
39cb8c92272a3663dc555476dab500f0
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long t=2;
long[] arr=new long[n];
int f=-1,p=-1;
long ans=0;
for(int i=1;i<=n;i++)
{
long x=sc.nextInt();
if(p==-1)
arr[++p]=x;
else
{
if(arr[p]>x)
{ans+=(arr[p]-x)/t;
arr[p]-=(t*((arr[p]-x)/t));}
if(arr[p]==x)
{
ans+=x;
p--;
}
else
arr[++p]=x;
}
}
long a=0;
for(int i=0;i<=p;i++)
a+=arr[i]/t;
ans+=a;
System.out.println(ans);
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
be81ac28910f9c90bb5a28894dd1d6bc
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
// package Quarantine;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class DominoForYoung {
public static void main(String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
StringTokenizer st=new StringTokenizer(br.readLine());
long b=0,w=0;
for(int i=1;i<=n;i++){
int len=Integer.parseInt(st.nextToken());
if(i%2==0){
b+=(len)/2;
w+=(len+1)/2;
}
else {
b+=(len+1)/2;
w+=len/2;
}
}
System.out.println(Math.min(b,w));
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
e08d61ed79f1a34114e1793639a3dfac
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.*;
import java.util.StringTokenizer;
public class BTask {
private static final String QUICK_ANSWER = "NO";
private final Input in;
private final StringBuilder out;
public BTask(Input in, StringBuilder out) {
this.in = in;
this.out = out;
}
public void solve() throws QuickAnswer {
int n = nextInt();
int[] a = nextInts(n);
long cnt = 0;
int pos = -1;
int c = 0;
for (int i : a) {
while (c * 2 - 1 + pos > i) --c;
if (c == 0) pos = -1;
if (pos == -1) {
cnt += i / 2;
if (i % 2 == 1) {
pos = 0;
c = 1;
}
continue;
}
cnt += i / 2;
if (pos == 0) {
if (i % 2 == 1) {
++cnt;
if (--c == 0) pos = -1;
else pos = 1;
} else pos = 1;
continue;
}
pos = 0;
if (i % 2 == 1) {
++c;
}
}
print(cnt);
}
// Common functions
private static class Input {
private final BufferedReader in;
private StringTokenizer tokenizer = null;
public Input(BufferedReader in) {
this.in = in;
}
String nextToken() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(in.readLine());
} catch (Exception e) {
throw new RuntimeException(e);
}
return tokenizer.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
String nextLine() {
try {
return in.readLine();
} catch (IOException e) {
return "";
}
}
}
void quickAnswer(String answer) throws QuickAnswer {
throw new QuickAnswer(answer);
}
void quickAnswer() throws QuickAnswer {
quickAnswer(QUICK_ANSWER);
}
static class QuickAnswer extends Exception {
private String answer;
public QuickAnswer(String answer) {
this.answer = answer;
}
}
void print(Object... args) {
String prefix = "";
for (Object arg : args) {
out.append(prefix);
out.append(arg);
prefix = " ";
}
}
void println(Object... args) {
print(args);
out.append("\n");
}
void printsp(Object... args) {
print(args);
out.append(" ");
}
int nextInt() {
return in.nextInt();
}
long nextLong() {
return in.nextLong();
}
String nextString() {
return in.nextLine();
}
int[] nextInts(int count) {
int[] res = new int[count];
for (int i = 0; i < count; ++i) {
res[i] = nextInt();
}
return res;
}
int[][] nextInts(int count, int n) {
int[][] res = new int[n][count];
for (int i = 0; i < count; ++i) {
for (int j = 0; j < n; j++) {
res[j][i] = nextInt();
}
}
return res;
}
long[] nextLongs(int count) {
long[] res = new long[count];
for (int i = 0; i < count; ++i) {
res[i] = nextLong();
}
return res;
}
long[][] nextLongs(int count, int n) {
long[][] res = new long[n][count];
for (int i = 0; i < count; ++i) {
for (int j = 0; j < n; j++) {
res[j][i] = nextLong();
}
}
return res;
}
public static void main(String[] args) {
doMain(System.in, System.out);
}
static void doMain(InputStream inStream, PrintStream outStream) {
Input in = new Input(new BufferedReader(new InputStreamReader(inStream)));
StringBuilder totalOut = new StringBuilder();
int count = 1;
//count = in.nextInt();
while (count-- > 0) {
try {
StringBuilder out = new StringBuilder();
new BTask(in, out).solve();
totalOut.append(out.toString());
} catch (QuickAnswer e) {
totalOut.append(e.answer);
}
if (count > 0) {
totalOut.append("\n");
}
}
outStream.print(totalOut.toString());
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
ffef7fc12018a8fa1f83d56ff6213fec
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Random;
import java.util.TreeSet;
public final class CF_609_D1_B
{
static boolean verb=true;
static void log(Object X){if (verb) System.err.println(X);}
static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}
static void logWln(Object X){if (verb) System.err.print(X);}
static void info(Object o){ System.out.println(o);}
static void output(Object o){outputWln(""+o+"\n"); }
static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}
// Global vars
static BufferedWriter out;
static InputReader reader;
static void test() {
log("testing");
Random r=new Random();
int NTESTS=100000;
int NMAX=10;
for (int t=0;t<NTESTS;t++) {
}
log("done");
}
static void process() throws Exception {
//log(effortBourrin(new int[] {0,3,4,1,2},3));
//test();
//testDirect();
out = new BufferedWriter(new OutputStreamWriter(System.out));
reader = new InputReader(System.in);
int n=reader.readInt();
long[] cnt=new long[2];
int e=0;
for (int i=0;i<n;i++) {
int x=reader.readInt();
cnt[e]+=x/2;
cnt[1-e]+=x-x/2;
e=1-e;
}
output(Math.min(cnt[0],cnt[1]));
try {
out.close();
} catch (Exception Ex) {
}
}
public static void main(String[] args) throws Exception {
process();
}
static final class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
private int read() throws IOException {
if (curChar >= numChars) {
curChar = 0;
numChars = stream.read(buf);
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public final String readString() throws IOException {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.append((char) c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public final String readString(int L) throws IOException {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder(L);
do {
res.append((char) c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public final int readInt() throws IOException {
int c = read();
boolean neg = false;
while (isSpaceChar(c)) {
c = read();
}
char d = (char) c;
// log("d:"+d);
if (d == '-') {
neg = true;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
// log("res:"+res);
if (neg)
return -res;
return res;
}
public final long readLong() throws IOException {
int c = read();
boolean neg = false;
while (isSpaceChar(c)) {
c = read();
}
char d = (char) c;
// log("d:"+d);
if (d == '-') {
neg = true;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
// log("res:"+res);
if (neg)
return -res;
return res;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
}
/*
5
1 4 5 2 3
*/
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
2a875f8401a06334192113238f667f53
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) throws Exception {
Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
thread.start();
thread.join();
}
static class TaskAdapter implements Runnable {
@Override
public void run() {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastInput in = new FastInput(inputStream);
FastOutput out = new FastOutput(outputStream);
BDominoForYoung solver = new BDominoForYoung();
solver.solve(1, in, out);
out.close();
}
}
static class BDominoForYoung {
public void solve(int testNumber, FastInput in, FastOutput out) {
int[] cnts = new int[2];
int n = in.readInt();
long ans = 0;
for (int i = 0; i < n; i++) {
int a = in.readInt();
cnts[i % 2] += a % 2;
ans += a / 2;
}
out.println(ans + Math.min(cnts[0], cnts[1]));
}
}
static class FastInput {
private final InputStream is;
private byte[] buf = new byte[1 << 13];
private int bufLen;
private int bufOffset;
private int next;
public FastInput(InputStream is) {
this.is = is;
}
private int read() {
while (bufLen == bufOffset) {
bufOffset = 0;
try {
bufLen = is.read(buf);
} catch (IOException e) {
bufLen = -1;
}
if (bufLen == -1) {
return -1;
}
}
return buf[bufOffset++];
}
public void skipBlank() {
while (next >= 0 && next <= 32) {
next = read();
}
}
public int readInt() {
int sign = 1;
skipBlank();
if (next == '+' || next == '-') {
sign = next == '+' ? 1 : -1;
next = read();
}
int val = 0;
if (sign == 1) {
while (next >= '0' && next <= '9') {
val = val * 10 + next - '0';
next = read();
}
} else {
while (next >= '0' && next <= '9') {
val = val * 10 - next + '0';
next = read();
}
}
return val;
}
}
static class FastOutput implements AutoCloseable, Closeable {
private StringBuilder cache = new StringBuilder(10 << 20);
private final Writer os;
public FastOutput(Writer os) {
this.os = os;
}
public FastOutput(OutputStream os) {
this(new OutputStreamWriter(os));
}
public FastOutput println(long c) {
cache.append(c).append('\n');
return this;
}
public FastOutput flush() {
try {
os.append(cache);
os.flush();
cache.setLength(0);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return this;
}
public void close() {
flush();
try {
os.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public String toString() {
return cache.toString();
}
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
439aebc4377898923f2770536389cb4e
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.util.Scanner;
public class DominoForYoung {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = in.nextLong();
}
long[] bipartite = new long[2];
for (int i = 0; i < n; i++) {
bipartite[0] += arr[i] / 2;
bipartite[1] += arr[i] / 2;
if (arr[i] % 2 == 1) {
if (i % 2 == 1) {
bipartite[0]++;
}
else {
bipartite[1]++;
}
}
}
System.out.println(Math.min(bipartite[0], bipartite[1]));
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
2c77e996b3f5f20f8f40c1c1f6bf2867
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class C324C
{
private static StringTokenizer st;
public static void nextLine(BufferedReader br) throws IOException
{
st = new StringTokenizer(br.readLine());
}
public static int nextInt()
{
return Integer.parseInt(st.nextToken());
}
public static String next()
{
return st.nextToken();
}
public static long nextLong()
{
return Long.parseLong(st.nextToken());
}
public static double nextDouble()
{
return Double.parseDouble(st.nextToken());
}
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
nextLine(br);
int n=nextInt();
nextLine(br);
long[] col = new long[2];
for(int i = 0; i < n; i++) {
int x = nextInt();
col[i % 2] += (x + 1) / 2;
col[1 - i % 2] += x / 2;
}
System.out.println(Math.min(col[0], col[1]));
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
5fb51c360ab574b6019791b3d39e24df
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class EdB {
public static void main(String[] args) throws Exception{
int num = 998244353;
// TODO Auto-generated method stub
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
// String input1 = bf.readLine().trim();
// String input2 = bf.readLine().trim();
int n = Integer.parseInt(bf.readLine());
int [] array = new int[n+1];
StringTokenizer st = new StringTokenizer(bf.readLine());
for(int i = 0;i<n;i++){
array[i] = Integer.parseInt(st.nextToken());
}
array[n] = 0;
long[] per = new long[array[0]];
int j = array[0];
int count = 0;
int index = 0;
for(int i = 0;i<n+1;i++){
if (array[i] == j){
count++;
}
else{
per[index] = count;
count++;
index+=(j-array[i]);
j = array[i];
}
}
for(int i = 1;i<array[0];i++){
if (per[i] == 0)
per[i] = per[i-1];
}
long answer = 0;
long white = 0;
long black = 0;
boolean whitestart = true;
for(int i = 0;i<array[0];i++){
if (whitestart){
black+=per[i]/2;
white+=(per[i]-per[i]/2);
whitestart = false;
}
else{
white+=per[i]/2;
black+=(per[i]-per[i]/2);
whitestart = true;
}
}
out.println(Math.min(white, black));
out.close();
}
}
//StringJoiner sj = new StringJoiner(" ");
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
d403c243b6e859fe4337fba7cac4c842
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Solution {
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String[] inputArr = br.readLine().split(" ");
long blackCount = 0;
long whiteCount = 0;
for(int i = 0; i < n; i++) {
long curr = Long.parseLong(inputArr[i]);
blackCount += curr / 2;
whiteCount += curr / 2;
if(i % 2 == 0) {
blackCount += curr % 2;
} else {
whiteCount += curr % 2;
}
}
System.out.println(Math.min(blackCount, whiteCount));
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
898764ed18a54e9c207fbc1fa5043c07
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
*
* @author kaixi_000
*/
public class Cf1268B {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int N=Integer.parseInt(br.readLine());
long black=0; long white=0;
StringTokenizer st=new StringTokenizer(br.readLine());
boolean odd=false;
while(st.hasMoreTokens()) {
int x=Integer.parseInt(st.nextToken());
if(odd){
black+=(x+1)/2;
white+=(x)/2;
}else{
black+=(x)/2;
white+=(x+1)/2;
}
odd=!odd;
}
System.out.println(Math.min(white,black));
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
de69d9479ce93e2a2b4c2a18ce0946dd
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class b {
public static void main(String[] args){
JS scan = new JS();
int n = scan.nextInt();
int[] a = new int[n+1];
long[] x = new long[2];
for(int i = 0; i < n; i++){
a[i] = scan.nextInt();
x[i%2] += a[i]/2;
x[(i+1)%2] += a[i]/2;
x[i%2] += a[i]%2;
}
System.out.println(Math.min(x[0], x[1]));
}
static class JS{
public int BS = 1<<16;
public char NC = (char)0;
byte[] buf = new byte[BS];
int bId = 0, size = 0;
char c = NC;
double num = 1;
BufferedInputStream in;
public JS() {
in = new BufferedInputStream(System.in, BS);
}
public JS(String s) throws FileNotFoundException {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
}
public char nextChar(){
while(bId==size) {
try {
size = in.read(buf);
}catch(Exception e) {
return NC;
}
if(size==-1)return NC;
bId=0;
}
return (char)buf[bId++];
}
public int nextInt() {
return (int)nextLong();
}
public long nextLong() {
num=1;
boolean neg = false;
if(c==NC)c=nextChar();
for(;(c<'0' || c>'9'); c = nextChar()) {
if(c=='-')neg=true;
}
long res = 0;
for(; c>='0' && c <='9'; c=nextChar()) {
res = (res<<3)+(res<<1)+c-'0';
num*=10;
}
return neg?-res:res;
}
public double nextDouble() {
double cur = nextLong();
return c!='.' ? cur:cur+nextLong()/num;
}
public String next() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c>32) {
res.append(c);
c=nextChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c!='\n') {
res.append(c);
c=nextChar();
}
return res.toString();
}
public boolean hasNext() {
if(c>32)return true;
while(true) {
c=nextChar();
if(c==NC)return false;
else if(c>32)return true;
}
}
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
798ede5625ddb159a8f57bbe6f15c7bf
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
//package com.company;
import java.io.*;
import java.util.*;
public class Main {
public static class Task {
public void solve(Scanner sc, PrintWriter pw) throws IOException {
int n = sc.nextInt();
long tot = 0;
long cnt = 0;
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
cnt += (i % 2 == 0 ? a / 2: a - a / 2);
tot += a;
}
pw.println(Math.min(cnt, tot - cnt));
}
}
static long TIME_START, TIME_END;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
// Scanner sc = new Scanner(new FileInputStream("input_line"));
PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
// PrintWriter pw = new PrintWriter(new FileOutputStream("input_line"));
Runtime runtime = Runtime.getRuntime();
long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
TIME_START = System.currentTimeMillis();
Task t = new Task();
t.solve(sc, pw);
TIME_END = System.currentTimeMillis();
long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
pw.close();
System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader s) throws FileNotFoundException {
br = new BufferedReader(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 {
return Double.parseDouble(next());
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
2c3b131737da47767758e35dcb0798e4
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(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, FastScanner in, PrintWriter out) {
int n = in.nextInt();
long[] d = new long[2];
for (int i = 0; i < n; i++) {
int x = in.nextInt();
d[i % 2] += x / 2;
d[(i + 1) % 2] += (x + 1) / 2;
}
out.println(Math.min(d[0], d[1]));
}
}
static class FastScanner {
private BufferedReader in;
private StringTokenizer st;
public FastScanner(InputStream stream) {
in = new BufferedReader(new InputStreamReader(stream));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
b5ac236f6a1c36508f95a682330d3a32
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
/**
* BaZ :D
*/
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class ACMIND
{
static FastReader scan;
static PrintWriter pw;
static long MOD = 1_000_000_007 ;
static long INF = 1_000_000_000_000_000_000L;
static long inf = 2_000_000_000;
public static void main(String[] args) {
new Thread(null,null,"BaZ",1<<27)
{
public void run()
{
try
{
solve();
}
catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}.start();
}
static int n,arr[];
static long dp[][][];
static void solve() throws IOException
{
scan = new FastReader();
pw = new PrintWriter(System.out,true);
StringBuilder sb = new StringBuilder();
n = ni();
arr = new int[n];
ArrayList<Integer> odd_pos = new ArrayList<>();
ArrayList<Integer> even_pos = new ArrayList<>();
long ans = 0;
for(int i=0;i<n;++i) {
arr[i] = ni();
ans+=arr[i]/2;
if(arr[i]%2==1) {
if(i%2==0) {
even_pos.add(i);
}
else {
odd_pos.add(i);
}
}
}
ans+=min(even_pos.size(), odd_pos.size());
pl(ans);
pw.flush();
pw.close();
}
static int ni() throws IOException
{
return scan.nextInt();
}
static long nl() throws IOException
{
return scan.nextLong();
}
static double nd() throws IOException
{
return scan.nextDouble();
}
static void pl()
{
pw.println();
}
static void p(Object o)
{
pw.print(o+" ");
}
static void pl(Object o)
{
pw.println(o);
}
static void psb(StringBuilder sb)
{
pw.print(sb);
}
static void pa(String arrayName, Object arr[])
{
pl(arrayName+" : ");
for(Object o : arr)
p(o);
pl();
}
static void pa(String arrayName, int arr[])
{
pl(arrayName+" : ");
for(int o : arr)
p(o);
pl();
}
static void pa(String arrayName, long arr[])
{
pl(arrayName+" : ");
for(long o : arr)
p(o);
pl();
}
static void pa(String arrayName, double arr[])
{
pl(arrayName+" : ");
for(double o : arr)
p(o);
pl();
}
static void pa(String arrayName, char arr[])
{
pl(arrayName+" : ");
for(char o : arr)
p(o);
pl();
}
static void pa(String listName, List list)
{
pl(listName+" : ");
for(Object o : list)
p(o);
pl();
}
static void pa(String arrayName, Object[][] arr) {
pl(arrayName+" : ");
for(int i=0;i<arr.length;++i) {
for(Object o : arr[i])
p(o);
pl();
}
}
static void pa(String arrayName, int[][] arr) {
pl(arrayName+" : ");
for(int i=0;i<arr.length;++i) {
for(int o : arr[i])
p(o);
pl();
}
}
static void pa(String arrayName, long[][] arr) {
pl(arrayName+" : ");
for(int i=0;i<arr.length;++i) {
for(long o : arr[i])
p(o);
pl();
}
}
static void pa(String arrayName, char[][] arr) {
pl(arrayName+" : ");
for(int i=0;i<arr.length;++i) {
for(char o : arr[i])
p(o);
pl();
}
}
static void pa(String arrayName, double[][] arr) {
pl(arrayName+" : ");
for(int i=0;i<arr.length;++i) {
for(double o : arr[i])
p(o);
pl();
}
}
static class FastReader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public FastReader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public FastReader(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[1000000];
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();
}
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
99d5ece8dfbd46b563b8631820bf44f1
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
//SOLUTION BEGIN
//Into the Hardware Mode
void pre() throws Exception{}
void solve(int TC)throws Exception{
int n = ni();
long a = 0, b = 0;
for(int i = 0; i< n; i++){
long x = nl();
a += x/2;
b += x/2;
if(i%2==0)a+=x%2;
else b += x%2;
}
pn(Math.min(a, b));
}
//SOLUTION END
void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
void exit(boolean b){if(!b)System.exit(0);}
long IINF = (long)1e18;
final int INF = (int)1e9+2, MX = (int)2e6+5;
DecimalFormat df = new DecimalFormat("0.00000000000");
double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-7;
static boolean multipleTC = false, memory = false, fileIO = false;
FastReader in;PrintWriter out;
void run() throws Exception{
if(fileIO){
in = new FastReader("C:/users/user/desktop/inp.in");
out = new PrintWriter("C:/users/user/desktop/out.out");
}else {
in = new FastReader();
out = new PrintWriter(System.out);
}
//Solution Credits: Taranpreet Singh
int T = (multipleTC)?ni():1;
pre();
for(int t = 1; t<= T; t++)solve(t);
out.flush();
out.close();
}
public static void main(String[] args) throws Exception{
if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
else new Main().run();
}
int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
void p(Object o){out.print(o);}
void pn(Object o){out.println(o);}
void pni(Object o){out.println(o);out.flush();}
String n()throws Exception{return in.next();}
String nln()throws Exception{return in.nextLine();}
int ni()throws Exception{return Integer.parseInt(in.next());}
long nl()throws Exception{return Long.parseLong(in.next());}
double nd()throws Exception{return Double.parseDouble(in.next());}
class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception{
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception{
while (st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}catch (IOException e){
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception{
String str = "";
try{
str = br.readLine();
}catch (IOException e){
throw new Exception(e.toString());
}
return str;
}
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
83f026327d616217e86d8cc3c8516b2e
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
//package round609;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class B2 {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni();
int[] a = na(n);
Arrays.sort(a);
long ans = 0;
int h = 0;
for(int i = 0;i < n;i++){
ans += (a[i] - h) / 2;
ans += (h+1)/2;
if((a[i]-h) % 2 == 1){
h++;
}else{
h--;
}
h = Math.max(h, 0);
}
out.println(ans);
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new B2().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
ee7752d769c7d7d65daa4b82b1d66230
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.*;
import java.util.Random;
import java.math.BigInteger;
import java.util.*;
public class test {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
InputReader in = new InputReader(inputStream);
// for(int i=4;i<=4;i++) {
// InputStream uinputStream = new FileInputStream("cowmbat.in");
// String f = i+".in";
// InputStream uinputStream = new FileInputStream(f);
// InputReader in = new InputReader(uinputStream);
// PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("cowmbat.out")));
Task t = new Task();
t.solve(in, out);
out.close();
// }
}
static class Task {
public void solve(InputReader in, PrintWriter out) throws IOException {
// int n = in.nextInt();
// int arr[] = new int[n+1];
// int idx[] = new int[n+1];
// for(int i=1;i<=n;i++) {
// int v = in.nextInt();
// arr[i] = v;
// idx[v] = i;
// }
// BIT bit_num = new BIT(n+1);
// BIT bit_idx = new BIT(n+1);
// int rev = 0;
// for(int i=1;i<=n;i++) {
// if(i==1) {
// out.print(0);
// bit_num.add(i, idx[i]);
// bit_idx.add(idx[i], 1);
// }else {
// rev+=i-1-bit_idx.sum(idx[i]);
// bit_num.add(i, idx[i]);
// bit_idx.add(idx[i], 1);
// int l = 1; int r = n;
// while(l<r-1) {
// int mid = l+(r-l)/2;
// int x = bit_idx.sum(mid);
// if(x<=(i+1)/2) r = mid;
// else l = mid;
// }
// int p = l;
// if(bit_idx.sum(r)<=(i+1)/2) p = r;
// Dumper.print(i+" "+p);
// int left_sum = bit_num.sum(p);
// int rigth_sum = bit_num.sum(i)-left_sum;
// int cnt = i/2;
// int t = rev;
// t+= p*(i+1)/2-left_sum-cnt*(cnt-1)/2;
// t+= rigth_sum-cnt*(p+1)-cnt*(cnt-1)/2;
// out.print(" "+t);
// }
// }
// int n = in.nextInt();
// ArrayList<Integer> arr = new ArrayList<Integer>();
// for(int i=0;i<n-1;i++) arr.add(in.nextInt()-1);
// int cnt[] = new int[n];
// for(int i:arr) cnt[i]++;
// ArrayList<Integer> leaf = new ArrayList<Integer>();
// for(int i=0;i<n;i++) if(cnt[i]==0) leaf.add(i);
// Collections.sort(leaf, Comparator.reverseOrder());
// for(int i:leaf) arr.add(i);
//
// boolean vis[] = new boolean[n];
// StringBuilder sb = new StringBuilder();
// sb.append(arr.get(0)+1).append("\n");
// Queue<Integer> q = new LinkedList<Integer>();
// q.add(arr.get(0));
// vis[arr.get(0)] = true;
// int p = 1;
// while(!q.isEmpty()) {
// int t = q.poll();
// for(int i=0;i<cnt[t];i++,p++) {
// if(p>=arr.size()) {
// out.println(-1);
// return;
// }
// if(vis[arr.get(p)]) {
// i--;
// continue;
// }
// sb.append((t+1)+" "+(arr.get(p)+1)).append("\n");
// vis[arr.get(p)] = true;
// q.add(arr.get(p));
// }
// }
// out.println(sb.toString());
//int n = in.nextInt();
//int cnt[] = new int[n];
int n = in.nextInt();
int arr[] = in.readIntArray(n);
long ret = 0;
int even = 0;
int odd = 0;
for(int i=0;i<n;i++) {
ret+=arr[i]/2;
if(arr[i]%2==1) {
if(i%2==1) odd++;
else even++;
}
}
out.println(ret+Math.min(odd, even));
}
class pair implements Comparable<pair>{
int idx,val;
public pair(int a,int b) {
idx = a;
val = b;
}
@Override
public int compareTo(pair t) {
return this.val-t.val;
}
}
class edge{
int from,to,cost,flow;
public edge(int a, int b, int c, int d) {
from = a;
to = b;
cost = c;
flow = d;
}
}
class sgt{
sgt ls;
sgt rs;
long sum;
int max, min, l, r;
public sgt(int a, int b, int arr[]) {
if(a==b-1) {
sum = max = min = arr[a];
}
ls = new sgt(a,a+b>>2,arr);
rs = new sgt(a+b>>2,b,arr);
update();
}
public void update() {
max = Math.max(ls.max, rs.max);
min = Math.min(ls.min, rs.min);
sum = ls.sum + rs.sum;
}
public void change(int p, int val, int arr[]) {
if(r<=p||p<l) return;
if(l==r-1) {
arr[p] = val;
sum = max = min = val;
return;
}
ls.change(p, val, arr);
rs.change(p, val, arr);
update();
}
int get_max(int L, int R) {
if(L<=l&&r<=R) return this.max;
if(R<=l||r<=L) return -1;
return Math.max(ls.get_max(L, R), rs.get_max(L, R));
}
int get_min(int L, int R) {
if(L<=l&&r<=R) return this.min;
if(R<=l||r<=L) return 999999999;
return Math.min(ls.get_min(L, R), rs.get_min(L, R));
}
int get_sum(int L,int R) {
if(L<=l&&r<=R) return this.min;
if(R<=l||r<=L) return 999999999;
return ls.get_sum(L, R)+rs.get_sum(L, R);
}
}
int gcd(int a, int b) {
if(b==0) return a;
else return gcd(b,a%b);
}
long gcd(long a, long b) {
if(b==0) return a;
else return gcd(b,a%b);
}
List<List<Integer>> convert (int arr[][]){
List<List<Integer>> ret = new ArrayList<List<Integer>>();
int n = arr.length;
for(int i=0;i<n;i++) {
ArrayList<Integer> tmp = new ArrayList<Integer>();
for(int j=0;j<arr[i].length;j++) {
tmp.add(arr[i][j]);
}
ret.add(tmp);
}
return ret;
}
class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { val = x; }
}
public int GCD(int a, int b) {
if (b==0) return a;
return GCD(b,a%b);
}
}
static class ArrayUtils {
static final long seed = System.nanoTime();
static final Random rand = new Random(seed);
public static void sort(int[] a) {
shuffle(a);
Arrays.sort(a);
}
public static void shuffle(int[] a) {
for (int i = 0; i < a.length; i++) {
int j = rand.nextInt(i + 1);
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
public static void sort(long[] a) {
shuffle(a);
Arrays.sort(a);
}
public static void shuffle(long[] a) {
for (int i = 0; i < a.length; i++) {
int j = rand.nextInt(i + 1);
long t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
static class BIT{
int arr[];
int n;
public BIT(int a) {
n=a;
arr = new int[n];
}
int sum(int p) {
int s=0;
while(p>0) {
s+=arr[p];
p-=p&(-p);
}
return s;
}
void add(int p, int v) {
while(p<n) {
arr[p]+=v;
p+=p&(-p);
}
}
}
static class DSU{
int[] arr;
int[] sz;
public DSU(int n) {
arr = new int[n];
sz = new int[n];
for(int i=0;i<n;i++) arr[i] = i;
Arrays.fill(sz, 1);
}
public int find(int a) {
if(arr[a]!=a) arr[a] = find(arr[a]);
return arr[a];
}
public void union(int a, int b) {
int x = find(a);
int y = find(b);
if(x==y) return;
arr[y] = x;
sz[x] += sz[y];
}
public int size(int x) {
return sz[find(x)];
}
}
static class MinHeap<Key> implements Iterable<Key> {
private int maxN;
private int n;
private int[] pq;
private int[] qp;
private Key[] keys;
private Comparator<Key> comparator;
public MinHeap(int capacity){
if (capacity < 0) throw new IllegalArgumentException();
this.maxN = capacity;
n=0;
pq = new int[maxN+1];
qp = new int[maxN+1];
keys = (Key[]) new Object[capacity+1];
Arrays.fill(qp, -1);
}
public MinHeap(int capacity, Comparator<Key> c){
if (capacity < 0) throw new IllegalArgumentException();
this.maxN = capacity;
n=0;
pq = new int[maxN+1];
qp = new int[maxN+1];
keys = (Key[]) new Object[capacity+1];
Arrays.fill(qp, -1);
comparator = c;
}
public boolean isEmpty() { return n==0; }
public int size() { return n; }
public boolean contains(int i) {
if (i < 0 || i >= maxN) throw new IllegalArgumentException();
return qp[i] != -1;
}
public int peekIdx() {
if (n == 0) throw new NoSuchElementException("Priority queue underflow");
return pq[1];
}
public Key peek(){
if(isEmpty()) throw new NoSuchElementException("Priority queue underflow");
return keys[pq[1]];
}
public int poll(){
if(isEmpty()) throw new NoSuchElementException("Priority queue underflow");
int min = pq[1];
exch(1,n--);
down(1);
assert min==pq[n+1];
qp[min] = -1;
keys[min] = null;
pq[n+1] = -1;
return min;
}
public void update(int i, Key key) {
if (i < 0 || i >= maxN) throw new IllegalArgumentException();
if (!contains(i)) {
this.add(i, key);
}else {
keys[i] = key;
up(qp[i]);
down(qp[i]);
}
}
private void add(int i, Key x){
if (i < 0 || i >= maxN) throw new IllegalArgumentException();
if (contains(i)) throw new IllegalArgumentException("index is already in the priority queue");
n++;
qp[i] = n;
pq[n] = i;
keys[i] = x;
up(n);
}
private void up(int k){
while(k>1&&less(k,k/2)){
exch(k,k/2);
k/=2;
}
}
private void down(int k){
while(2*k<=n){
int j=2*k;
if(j<n&&less(j+1,j)) j++;
if(less(k,j)) break;
exch(k,j);
k=j;
}
}
public boolean less(int i, int j){
if (comparator == null) {
return ((Comparable<Key>) keys[pq[i]]).compareTo(keys[pq[j]]) < 0;
}
else {
return comparator.compare(keys[pq[i]], keys[pq[j]]) < 0;
}
}
public void exch(int i, int j){
int swap = pq[i];
pq[i] = pq[j];
pq[j] = swap;
qp[pq[i]] = i;
qp[pq[j]] = j;
}
@Override
public Iterator<Key> iterator() {
// TODO Auto-generated method stub
return null;
}
}
private static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int zcurChar;
private int znumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (znumChars == -1)
throw new InputMismatchException();
if (zcurChar >= znumChars)
{
zcurChar = 0;
try
{
znumChars = stream.read(buf);
} catch (IOException e)
{
throw new InputMismatchException();
}
if (znumChars <= 0)
return -1;
}
return buf[zcurChar++];
}
public int nextInt()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String nextString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.')
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return nextString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
public int[] readIntArray(int n) {
int[] ret = new int[n];
for (int i = 0; i < n; i++) {
ret[i] = nextInt();
}
return ret;
}
}
static class Dumper {
static void print_int_arr(int[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("---------------------");
}
static void print_char_arr(char[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("---------------------");
}
static void print_double_arr(double[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("---------------------");
}
static void print_2d_arr(int[][] arr, int x, int y) {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
System.out.println();
System.out.println("---------------------");
}
static void print_2d_arr(boolean[][] arr, int x, int y) {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
System.out.println();
System.out.println("---------------------");
}
static void print(Object o) {
System.out.println(o.toString());
}
static void getc() {
System.out.println("here");
}
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
1b843fa4c2eed42d2235ba845e5a045b
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class A {
public static void main (String[] args) { new A(); }
A() {
Scanner s = new Scanner(System.in);
System.err.println("");
int n = s.nextInt();
int[] a = new int[n];
for(int i = 0; i < n; i++) a[i] = s.nextInt();
long[] cnt = new long[2];
for(int i = 0; i < n; i++) {
int p1 = i&1, p2 = p1^1;
cnt[p1] += a[i]/2 + (a[i]&1);
cnt[p2] += a[i]/2;
}
System.out.println(Math.min(cnt[0], cnt[1]));
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
1d8e9268e59012ee0969a088f13306b0
|
train_001.jsonl
|
1576926300
|
You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$). Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.
|
256 megabytes
|
import java.util.*;
public class CodeForces1268B{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
long blue = 0;
long red = 0;
for(int i = 0;i<n;i++){
int a = input.nextInt();
if(i % 2 == 0){
blue+= a/2;
red+= (a+1)/2;
}
else{
blue += (a+1)/2;
red+= (a)/2;
}
}
System.out.println(Math.min(blue,red));
}
}
|
Java
|
["5\n3 2 2 2 1"]
|
3 seconds
|
["4"]
|
NoteSome of the possible solutions for the example:
|
Java 8
|
standard input
|
[
"dp",
"greedy",
"math"
] |
6ac3246ee9cf78d81f96a3ed05b35918
|
The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.
| 2,000 |
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
|
standard output
| |
PASSED
|
af79304702c0f48f5e31d2b546722eb5
|
train_001.jsonl
|
1410103800
|
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers β coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.
|
256 megabytes
|
// Imports
import java.util.*;
import java.io.*;
public class B464 {
/**
* @param args the command line arguments
* @throws IOException, FileNotFoundException
*/
public static void main(String[] args) throws IOException, FileNotFoundException {
// TODO UNCOMMENT WHEN ALGORITHM CORRECT
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
// TODO code application logic here
int[][] original = new int[8][3];
int[][] perm = new int[6][3];
int[] curr = new int[8];
for(int i = 0; i < 8; i++) {
StringTokenizer st = new StringTokenizer(f.readLine());
for(int j = 0; j < 3; j++) {
original[i][j] = Integer.parseInt(st.nextToken());
}
}
for (int u = 0; u < 3; u++) {
int j0 = u << 1, j1 = j0 | 1;
int v = (u + 1) % 3, w = (u + 2) % 3;
perm[j0][0] = u; perm[j0][1] = v; perm[j0][2] = w;
perm[j1][0] = u; perm[j1][1] = w; perm[j1][2] = v;
}
// long time = System.currentTimeMillis();
for (int i0 = 0; i0 < 6; i0++) {
curr[0] = i0;
for (int i1 = 0; i1 < 6; i1++) {
curr[1] = i1;
for (int i2 = 0; i2 < 6; i2++) {
curr[2] = i2;
for (int i3 = 0; i3 < 6; i3++) {
curr[3] = i3;
for (int i4 = 0; i4 < 6; i4++) {
curr[4] = i4;
for (int i5 = 0; i5 < 6; i5++) {
curr[5] = i5;
for (int i6 = 0; i6 < 6; i6++) {
curr[6] = i6;
long[] val = new long[28];
int place = 0;
for(int i = 0; i < original.length; i++) {
for(int j = i + 1; j < original.length; j++) {
long sq = 0;
for(int l = 0; l < 3; l++) {
int k = perm[curr[i]][l];
int m = perm[curr[j]][l];
long a = original[i][k];
long b = original[j][m];
sq += (a - b)*(a - b);
}
val[place] = sq;
place++;
}
}
// System.out.println(System.currentTimeMillis() - time);
// time = System.currentTimeMillis();
Arrays.sort(val);
if(val[0] != 0 && val[12] == val[0]*2 && val[24] == val[0]*3 &&
val[0] == val[11] && val[12] == val[23] && val[24] == val[27]) {
System.out.println("YES");
for(int i = 0; i < original.length; i++) {
for(int j = 0; j < original[0].length; j++) {
System.out.print(original[i][perm[curr[i]][j]] + " ");
}
System.out.println();
}
System.exit(0);
}
}
}
}
}
}
}
}
System.out.println("NO");
// System.out.println(System.currentTimeMillis() - time);
}
}
|
Java
|
["0 0 0\n0 0 1\n0 0 1\n0 0 1\n0 1 1\n0 1 1\n0 1 1\n1 1 1", "0 0 0\n0 0 0\n0 0 0\n0 0 0\n1 1 1\n1 1 1\n1 1 1\n1 1 1"]
|
1 second
|
["YES\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n0 1 1\n1 0 1\n1 1 0\n1 1 1", "NO"]
| null |
Java 11
|
standard input
|
[
"geometry",
"brute force"
] |
55da4611bc78d55c228d0ce78bd02fd3
|
Each of the eight lines contains three space-separated integers β the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.
| 2,000 |
If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers β the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them. If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.
|
standard output
| |
PASSED
|
1993c3db4efa964cfe0b316341c18c5c
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class PoloThePenguinAndStrings {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
if (k > n || (k == 1 && n > 1)) {
System.out.println(-1);
return;
}
if (k == 1 && n == 1) {
System.out.println('a');
return;
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < n-k+2; i++)
sb.append(i%2==0?'a':'b');
for (int i = 0; i < k-2; i++)
sb.append((char)('c'+i));
System.out.println(sb);
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
06a0c4558e2da935fa50f3e6154a6014
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] x=br.readLine().split(" ");
int n=Integer.parseInt(x[0]);
int k=Integer.parseInt(x[1]);
int j=0;
for(int i=0; i<n; i++){
if(k>n || k==1 && n!=1){
System.out.println(-1);
return;
}
if(i<n-(k-2))
if(i%2==0)
System.out.print("a");
else
System.out.print("b");
else
System.out.print((char)(99+j++));
}
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
bb2c369e8bed54f7fb74324573f2db3c
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] s = bf.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int k = Integer.parseInt(s[1]);
if(k>n||(n > 1 && k == 1)){
System.out.println(-1);
return;
}
char[] alphabets = new char[26];
if(n == 1 && k == 1){
sb.append("a");
}else{
int m = 0;
for (int i = 97; i < 123; i++ , m++) {
alphabets[m] = ((char) i);
}
int total = (n-k)+2;
boolean getout = true;
for (int i = 0; i < total; i++) {
if(getout)
sb.append("a");
else
sb.append("b");
getout = !getout;
}
for (int i = 0; i < n-total; i++) {
sb.append( alphabets[i+2] );
}
}
System.out.println(sb);
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
249dc4b6734dd8208814faca020fc85e
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class A{
static String solve(int n, int k) {
if (n < k) return "-1";
StringBuilder sb = new StringBuilder();
if (n == k)
for (int i=0; i<k; i++)
sb.append(((char)( ((int)'a') + i)));
else if (k == 1) // How can I be so stupid!
return "-1";
///for (int i=0; i<n; i++)
// sb.append('a');
else { // n >= 3, k >= 2
for (int i=0; i<n-k+2; i++)
if (i%2 == 0) sb.append('a');
else sb.append('b');
for (int j=0; j<k-2; j++)
sb.append( ((char) ((int)'c' + j)));
}
return sb.toString();
}
public static void main(String [] argv) {
Kattio io = new Kattio(System.in, System.out);
int n = io.getInt();
int k = io.getInt();
io.println(solve(n, k));
io.close();
}
}
// ####### KATTIO ########
class Kattio extends PrintWriter {
public Kattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Kattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int getInt() {
return Integer.parseInt(nextToken());
}
public double getDouble() {
return Double.parseDouble(nextToken());
}
public long getLong() {
return Long.parseLong(nextToken());
}
public String getWord() {
return nextToken();
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) { }
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
19cba851d037fa42d9019148f98c00a7
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author hadi0x7c7.blog.ir
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Reader in = new Reader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
}
class TaskC {
public void solve(int testNumber, Reader in, PrintWriter out) {
int k, n;
n = in.nextInt();
k = in.nextInt();
if (k > n) {
out.print(-1);
return;
}
if (k == 1) {
if (n > 1) {
out.print(-1);
return;
} else {
out.print((char) 'a');
return;
}
}
for (int i = 0; i < Math.abs(n - k + 2); i++)
if (i % 2 == 0)
out.print("a");
else
out.print("b");
for (int i = 2; i <= k - 1; i++)
out.print((char) ('a' + i));
}
}
class Reader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public Reader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
70334d8f1894873547efa8281fc37408
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.util.*;
public class A288 {
public static void main(String[] args){
Scanner br = new Scanner(System.in);
int n = br.nextInt();
int k = br.nextInt();
if(k > n || (k == 1 && n > 1)){
System.out.println(-1);
return;
}
if(n == 1 && k == 1){
System.out.println("a");
return;
}
StringBuilder ans = new StringBuilder("");
while(ans.length() < n-k+2){
if(ans.length()%2 == 0){
ans.append("a");
}
else{
ans.append("b");
}
}
for(int i = 2;i<k;i++){
ans.append((char)('a'+i));
}
System.out.println(ans);
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
d5df7a0f095ef17e224b52a5968fb360
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
//package contest;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
public class ProblemA {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
int[] readInts() throws IOException {
String[] strings = reader.readLine().split(" ");
int[] ints = new int[strings.length];
for(int i = 0; i < ints.length; i++) {
ints[i] = Integer.parseInt(strings[i]);
}
return ints;
}
void solve() throws IOException {
int[] tt = readInts();
int n = tt[0], k = tt[1];
if(n < k || (n > 1 && k == 1)) {
writer.write("-1");
}
else {
char[] a = new char[n];
if(k <= 2) {
for(int i = 0; i < n; i++) {
if(i % 2 == 0) a[i] = 'a';
else a[i] = 'b';
}
}
else {
for(int i = 0; i < n - k + 2; i++) {
if(i % 2 == 0) a[i] = 'a';
else a[i] = 'b';
}
for(int i = 2; i < k; i++) {
a[n - k + i] = (char)('a' + i);
}
}
writer.write(a);
}
writer.flush();
}
public static void main(String[] args) throws IOException {
new ProblemA().solve();
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
c5cb3f607eb663e0a8147ebd282ca093
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import static java.lang.Math.*;
import java.io.*;
import java.util.*;
import java.math.*;
public class Template {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
String next() {
while (st==null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (Exception e) {}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
public void run() throws Exception {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
int n = nextInt(), k = nextInt();
if(n == 1 && k == 1){
System.out.println('a');
System.exit(0);
}
if(k > n || (k == 1 && n > 1)){
System.out.println(-1);
System.exit(0);
}
else{
StringBuilder sb = new StringBuilder();
String end = "";
for(int i = 2; i < k; ++i){
end += Character.toString((char)(i + 97));
}
int m = n - k + 2;
for(int i = 0; i < m; ++i)
if(i % 2 == 0) sb.append('a');
else sb.append('b');
sb.append(end);
System.out.println(sb.toString());
}
out.close();
}
public static void main(String[] args) throws Exception {
new Template().run();
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
1334d93eb2bc2145b49a7ed998d7b526
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader Bf = new BufferedReader(new InputStreamReader(System.in));
String input = Bf.readLine();
String out = "";
StringTokenizer str = new StringTokenizer(input, " ");
int i = 2;
int n = Integer.parseInt(str.nextToken());
int k = Integer.parseInt(str.nextToken());
String e = "";
String q = "";
if (n == 1 && k == 1) {
System.out.println("a");
} else if (n >= k && !(k == 1 && n > 1)) {
while (out.length() < n - (k - 2)) {
if (e.length() == 0) {
e = "ab";
q = e;
} else if (e.length() < n) {
e += e;
} else {
int w = n-(k-2);
out = e.substring(0,w);
}}
int z = 98;
while (out.length() < n) {
out += (char) (++z);
}
System.out.println(out);
} else {
System.out.println("-1");
}
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
80333a4cdc313284c08b96bc5719006b
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.util.Scanner;
public class A288 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int N = input.nextInt();
int K = input.nextInt();
if (N < K || (K == 1 && N != 1)) {
System.out.println("-1");
} else {
if (N == 1) {
System.out.println("a");
} else {
char[] c = new char[N];
for (int n=0; n<N-K+2; n++) {
c[n] = (n%2 == 0) ? 'a' : 'b';
}
for (int n=N-K+2; n<N; n++) {
c[n] = (char)('c' + (n-N+K-2));
}
System.out.println(new String(c));
}
}
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
ca67862bb512300d913d8a8249bca8d3
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Vaibhav Mittal
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.readInt();
int k = in.readInt();
if ((n > 1 && k == 1) || (n < k)) {
out.println("-1");
}
else if (n == 1) {
out.println("a");
}
else {
char[] res = new char[n];
for (int i = 0; i < n; ++i)
res[i] = i % 2 == 0 ? 'a' : 'b';
for (int i = n - 1, j = k - 1; i >= 0 && j >= 2; --i, --j)
res[i] = (char) (j + 'a');
out.println(res);
}
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
private int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
3b74a466e266a9e8c0a8fa8013a0a574
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s =br.readLine().split(" ");
int n = Integer.parseInt(s[0]) ;
int k = Integer.parseInt(s[1]) ;
if(k>n || k == 1 && n != 1 ){
System.out.print("-1");
return ;
}
int a = Math.abs(k-2) ;
int z = n-a ;
int i = 0 ; ;
for(; i<z/2 ;i++)
System.out.print("ab") ;
if((i*2)!= z || z == 0 && i == 0)
System.out.print("a") ;
for (int j = 99 ; j < (99+(k-2)) ; j++ )
System.out.print((char) j) ;
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
bbbc8ec7aad6ca0cc731b40154b1a238
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public final class penguin_and_strings
{
static Scanner sc=new Scanner(System.in);
static PrintWriter out=new PrintWriter(System.out);
static void solve(int n,int m)
{
char[] a=new char[26];
int j=0;
for(int i=97;i<=122;i++)
{
a[j]=(char)i;
j++;
}
StringBuffer sb=new StringBuffer("");
j=0;
int morg=m;
while(m>0)
{
sb.append(a[j]);
j++;
m--;
}
int i=1;
boolean ans=true;
while(sb.length()<n && ans)
{
if(i<sb.length()-1)
{
inner:
for(j=0;j<26;j++)
{
if((a[j]<sb.charAt(i) || a[j]<sb.charAt(i+1)) && (a[j]!=sb.charAt(i) && a[j]!=sb.charAt(i+1)))
{
sb.insert(i+1,a[j]);
i++;
break inner;
}
else if(a[j]>sb.charAt(i) && a[j]>sb.charAt(i+1))
{
break inner;
}
}
}
else
{
inner:
for(j=0;j<26;j++)
{
if(j<morg && a[j]!=sb.charAt(i))
{
sb.insert(i+1,a[j]);
i++;
break inner;
}
else
{
if(j>=morg)
{
ans=false;
break inner;
}
}
}
}
}
if(sb.length()!=n)
{
out.println("-1");
}
else
{
out.println(sb.toString());
}
}
public static void main(String args[]) throws Exception
{
int n=sc.nextInt();
int m=sc.nextInt();
if(m>n)
{
out.println("-1");
}
else
{
if(n<=1)
{
out.println("a");
}
else
{
if(n==m)
{
int i=97;
while(m>0)
{
out.print((char)i);
i++;
m--;
}
out.println("");
}
else
{
if(m==1)
{
out.println("-1");
}
else
{
solve(n,m);
}
}
}
}
out.close();
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
9a1d22054d12779a9f7543aa2d8eab64
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class A {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
void solve() throws IOException {
int n = nextInt();
int k = nextInt();
if (n < k) {
out.println("-1");
return;
}
if (k == 1) {
out.println(n == 1 ? "a" : "-1");
return;
}
if (k == 2) {
for (int i = 0; i < n; i++) {
out.print(((i & 1) == 0) ? 'a' : 'b');
}
out.println();
return;
}
for (int i = 0; i < n - (k - 2); i++) {
out.print(((i & 1) == 0) ? 'a' : 'b');
}
for (int i = 2; i < k; i++)
out.print((char)('a' + i));
out.println();
}
A() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new A();
}
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.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
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
1f0f6264702abe1900e3131aef3b292f
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class cf288A {
static InputReader in = new InputReader();
static String str;
static String[] arr;
public static void main(String[] args) throws Exception {
str = in.readLine();
int n = Integer.parseInt(str.substring(0, str.indexOf(" ")));
int k = Integer.parseInt(str.substring(str.indexOf(" ") + 1));
if(n < k) {
System.out.println(-1);
return;
}
if(n == 1) {
System.out.println("a");
return;
}
if(k == 1) {
System.out.println(-1);
return;
}
StringBuilder sb = new StringBuilder("");
for(int i = 0; i < n - k + 2; i++) {
sb.append(i % 2 == 0 ? "a" : "b");
}
for(int i = 0; i < k - 2; i++) {
sb.append((char) (97 + 2 + i));
}
System.out.println(sb.toString());
}
static class InputReader {
BufferedReader br;
public InputReader() {
try {
br = new BufferedReader(new FileReader("cf288A.in"));
} catch(Exception e) {
br = new BufferedReader(new InputStreamReader(System.in));
}
}
public String readLine() throws Exception {
return br.readLine();
}
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
3a5c3878bedaf5ce0f361ea1d9e9e942
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class PoloThePenguinAndStrings {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer t = new StringTokenizer(br.readLine());
int n = Integer.parseInt(t.nextToken());
int k = Integer.parseInt(t.nextToken());
if(k>n||(n>1&&k==1)){
System.out.println(-1);
return;
}
if(n==1&&k==1){
System.out.print("a");
return;
}
n = n-k+2;
if (n%2==0){
for (int i =1;i<=n; ){
System.out.print("ab");
i+=2;
}
}
else{
for (int i =1;i<=n-1; ){
System.out.print("ab");
i+=2;
}
System.out.print("a");
}
int count =3;
while(count<=k){
char c = (char)(count+96);
System.out.print(c);
count++;
}
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
81d93fd00a0bc67dc1741a702af46099
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class PoloThePenguinAndStrings {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String [] in = br.readLine().split(" ");
int n = Integer.parseInt(in[0]);
int k = Integer.parseInt(in[1]);
if(k>n||(n>1&&k==1)){
System.out.println(-1);
return;
}
String prefix ="";
while(k>2){
char c = (char)(k+96);
prefix = c+prefix;
k--;
}
n = n-prefix.length();
StringBuilder start = new StringBuilder();
if (n%2==0){
for (int i =1;i<=n; ){
start.append("ab");
i+=2;
}
}
else{
for (int i =1;i<=n-1; ){
start.append("ab");
i+=2;
}
start.append("a");
}
start.append(prefix);
System.out.println(start);
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
8e157faea7b78be16b7c99895b65ff06
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class PoloThePenguinAndStrings {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String [] in = br.readLine().split(" ");
int n = Integer.parseInt(in[0]);
int k = Integer.parseInt(in[1]);
if(k>n||(n>1&&k==1)){
System.out.println(-1);
return;
}
StringBuilder prefix =new StringBuilder();
int count =3;
while(count<=k){
char c = (char)(count+96);
prefix.append(c);
count++;
}
n = n-prefix.length();
StringBuilder start = new StringBuilder();
if (n%2==0){
for (int i =1;i<=n; ){
start.append("ab");
i+=2;
}
}
else{
for (int i =1;i<=n-1; ){
start.append("ab");
i+=2;
}
start.append("a");
}
start.append(prefix);
System.out.println(start);
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
aa40467f4bf7301ba0d3c2aac65abd02
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class PoloThePenguinAndStrings {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer t = new StringTokenizer(br.readLine());
int n = Integer.parseInt(t.nextToken());
int k = Integer.parseInt(t.nextToken());
if(k>n||(n>1&&k==1)){
System.out.println(-1);
return;
}
StringBuilder prefix =new StringBuilder();
int count =3;
while(count<=k){
char c = (char)(count+96);
prefix.append(c);
count++;
}
n = n-prefix.length();
StringBuilder start = new StringBuilder();
if (n%2==0){
for (int i =1;i<=n; ){
start.append("ab");
i+=2;
}
}
else{
for (int i =1;i<=n-1; ){
start.append("ab");
i+=2;
}
start.append("a");
}
start.append(prefix);
System.out.println(start);
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
942ca80cde1e506ff1bb322dcf6239b5
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] s = bf.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int k = Integer.parseInt(s[1]);
if(k>n||(n > 1 && k == 1)){
System.out.println(-1);
return;
}
char[] alphabets = new char[26];
if(n == 1 && k == 1){
sb.append("a");
}else{
int m = 0;
for (int i = 97; i < 123; i++ , m++) {
alphabets[m] = ((char) i);
}
int total = (n-k)+2;
boolean getout = true;
for (int i = 0; i < total; i++) {
if(getout)
sb.append("a");
else
sb.append("b");
getout = !getout;
}
for (int i = 0; i < n-total; i++) {
sb.append( alphabets[i+2] );
}
}
System.out.println(sb);
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
6ebe843576b38e66651cf00f3e0c018e
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Random;
import java.util.Stack;
import java.util.StringTokenizer;
public class B {
private void solve() throws IOException {
int n = nextInt();
int k = nextInt();
if (k == 1) {
if (n == 1) {
println("a");
} else {
println("-1");
}
return;
}
if (k > n) {
println("-1");
return;
}
while (n > k - 1) {
print("ab");
n -= 2;
}
if (n == k - 1) {
print("a");
}
for (int i = 0; i < k - 2; i++) {
print((char)(i + 'a' + 2));
}
println("");
}
private String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
private int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(nextToken());
}
private double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(nextToken());
}
private long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
private void print(Object o) {
writer.print(o);
}
private void println(Object o) {
writer.println(o);
}
private void printf(String format, Object... o) {
writer.printf(format, o);
}
public static void main(String[] args) {
long time = System.currentTimeMillis();
Locale.setDefault(Locale.US);
new B().run();
System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time));
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
private void run() {
try {
reader = new BufferedReader(new InputStreamReader(System.in));
writer = new PrintWriter(System.out);
solve();
reader.close();
writer.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(13);
}
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
a8c43754cc46abef371e7388d772ef08
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.InputStreamReader ;
import java.io.BufferedReader ;
import java.io.IOException;
public class prob10 {
public static void main(String[]args)throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] in=br.readLine().split(" ");
int n=Integer.parseInt(in[0]);
int k=Integer.parseInt(in[1]);
StringBuilder sb= new StringBuilder("");
if(k==1&&n==1)
System.out.println("a");
else{
if(k>n||(k==1 &&n!=1))
System.out.println(-1);
else{
for(int i=0;i<n-k+2;i++)
sb=(i%2==0)?sb.append("a"):sb.append("b");
int j=1;
for(int i=n-k+2;i<n;i++){
sb.append((char)('b'+j));
j++;
}
}
}
System.out.println(sb);
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
6f35e33531e2c28045ccbad34f061f2b
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args)throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
StringTokenizer st=new StringTokenizer(s);
int n=Integer.parseInt(st.nextToken());
int k=Integer.parseInt(st.nextToken());
String S="";
if(n<k ||( k==1 && n>1))
System.out.println("-1");
else{
int L='a';
int z=n-k;
for(int i=0;i<z/2;i++){
System.out.print("ab");
}
if(z%2!=0)
System.out.print("a");
if(z==0 || z%2==0){
for(int i=0;i<k;i++){
System.out.print((char)(L+i));
}
}
else{
System.out.print("ba");
for(int i=2;i<k;i++)
System.out.print((char)(L+i));
}
}
}}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
f94158397dfbed30cebd10727b3fdbf7
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class A {
public static void main(String[] args) throws Exception {
new A().solve();
// new FileInputStream(new File("input.txt")),
// new PrintStream(new FileOutputStream(new File("output.txt"))));
}
void solve() throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
String[] sp;
int n = sc.nextInt();
int k = sc.nextInt();
if (n < k) {
System.out.println("-1");
return;
}
if (k == 1) {
if (n == 1) {
System.out.println("a");
} else {
System.out.println("-1");
}
return;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n - (k - 2); i++) {
sb.append((char) ('a' + i % 2));
}
for (int i = n - (k - 2); i < n; i++) {
sb.append((char) ('c' + (i - (n - (k - 2)))));
}
System.out.println(sb);
}
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
177b78fa4b442917b5f6de1f8a5ca2e7
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
/*
* @author Ivan Pryvalov ([email protected])
*/
public class Codeforces_Round_177_Div1_A implements Runnable{
private void solve() throws IOException {
int n = scanner.nextInt(); //10^6
int k = scanner.nextInt(); //26
if (n==1){
if (k==1){
out.println("a");
}else{
out.println("-1");
}
return;
}
//n>=2
if (k<2 || k>n){
out.println("-1");
return;
}
char[] c = new char[n];
for(int i=0; i<n; i++){
c[i] = i%2 ==0 ? 'a' : 'b';
}
for(int i=n-1; k>2; i--, k--){
c[i] = (char)('a' + k - 1);
}
out.println(new String(c));
}
/////////////////////////////////////////////////
final int BUF_SIZE = 1024 * 1024 * 8;//important to read long-string tokens properly
final int INPUT_BUFFER_SIZE = 1024 * 1024 * 8 ;
final int BUF_SIZE_INPUT = 1024;
final int BUF_SIZE_OUT = 1024;
boolean inputFromFile = false;
String filenamePrefix = "A-small-attempt0";
String inSuffix = ".in";
String outSuffix = ".out";
//InputStream bis;
//OutputStream bos;
PrintStream out;
ByteScanner scanner;
ByteWriter writer;
// @Override
public void run() {
try{
InputStream bis = null;
OutputStream bos = null;
//PrintStream out = null;
if (inputFromFile){
File baseFile = new File(getClass().getResource("/").getFile());
bis = new BufferedInputStream(
new FileInputStream(new File(
baseFile, filenamePrefix+inSuffix)),
INPUT_BUFFER_SIZE);
bos = new BufferedOutputStream(
new FileOutputStream(
new File(baseFile, filenamePrefix+outSuffix)));
out = new PrintStream(bos);
}else{
bis = new BufferedInputStream(System.in, INPUT_BUFFER_SIZE);
bos = new BufferedOutputStream(System.out);
out = new PrintStream(bos);
}
scanner = new ByteScanner(bis, BUF_SIZE_INPUT, BUF_SIZE);
writer = new ByteWriter(bos, BUF_SIZE_OUT);
solve();
out.flush();
}catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public interface Constants{
final static byte ZERO = '0';//48 or 0x30
final static byte NINE = '9';
final static byte SPACEBAR = ' '; //32 or 0x20
final static byte MINUS = '-'; //45 or 0x2d
final static char FLOAT_POINT = '.';
}
public static class EofException extends IOException{
}
public static class ByteWriter implements Constants {
int bufSize = 1024;
byte[] byteBuf = new byte[bufSize];
OutputStream os;
public ByteWriter(OutputStream os, int bufSize){
this.os = os;
this.bufSize = bufSize;
}
public void writeInt(int num) throws IOException{
int byteWriteOffset = byteBuf.length;
if (num==0){
byteBuf[--byteWriteOffset] = ZERO;
}else{
int numAbs = Math.abs(num);
while (numAbs>0){
byteBuf[--byteWriteOffset] = (byte)((numAbs % 10) + ZERO);
numAbs /= 10;
}
if (num<0)
byteBuf[--byteWriteOffset] = MINUS;
}
os.write(byteBuf, byteWriteOffset, byteBuf.length - byteWriteOffset);
}
/**
* Please ensure ar.length <= byteBuf.length!
*
* @param ar
* @throws IOException
*/
public void writeByteAr(byte[] ar) throws IOException{
for (int i = 0; i < ar.length; i++) {
byteBuf[i] = ar[i];
}
os.write(byteBuf,0,ar.length);
}
public void writeSpaceBar() throws IOException{
byteBuf[0] = SPACEBAR;
os.write(byteBuf,0,1);
}
}
public static class ByteScanner implements Constants{
InputStream is;
public ByteScanner(InputStream is, int bufSizeInput, int bufSize){
this.is = is;
this.bufSizeInput = bufSizeInput;
this.bufSize = bufSize;
byteBufInput = new byte[this.bufSizeInput];
byteBuf = new byte[this.bufSize];
}
public ByteScanner(byte[] data){
byteBufInput = data;
bufSizeInput = data.length;
bufSize = data.length;
byteBuf = new byte[bufSize];
byteRead = data.length;
bytePos = 0;
}
private int bufSizeInput;
private int bufSize;
byte[] byteBufInput;
byte by=-1;
int byteRead=-1;
int bytePos=-1;
byte[] byteBuf;
int totalBytes;
boolean eofMet = false;
private byte nextByte() throws IOException{
if (bytePos<0 || bytePos>=byteRead){
byteRead = is==null? -1: is.read(byteBufInput);
bytePos=0;
if (byteRead<0){
byteBufInput[bytePos]=-1;//!!!
if (eofMet)
throw new EofException();
eofMet = true;
}
}
return byteBufInput[bytePos++];
}
/**
* Returns next meaningful character as a byte.<br>
*
* @return
* @throws IOException
*/
public byte nextChar() throws IOException{
while ((by=nextByte())<=0x20);
return by;
}
/**
* Returns next meaningful character OR space as a byte.<br>
*
* @return
* @throws IOException
*/
public byte nextCharOrSpacebar() throws IOException{
while ((by=nextByte())<0x20);
return by;
}
/**
* Reads line.
*
* @return
* @throws IOException
*/
public String nextLine() throws IOException {
readToken((byte)0x20);
return new String(byteBuf,0,totalBytes);
}
public byte[] nextLineAsArray() throws IOException {
readToken((byte)0x20);
byte[] out = new byte[totalBytes];
System.arraycopy(byteBuf, 0, out, 0, totalBytes);
return out;
}
/**
* Reads token. Spacebar is separator char.
*
* @return
* @throws IOException
*/
public String nextToken() throws IOException {
readToken((byte)0x21);
return new String(byteBuf,0,totalBytes);
}
/**
* Spacebar is included as separator char
*
* @throws IOException
*/
private void readToken() throws IOException {
readToken((byte)0x21);
}
private void readToken(byte acceptFrom) throws IOException {
totalBytes = 0;
while ((by=nextByte())<acceptFrom);
byteBuf[totalBytes++] = by;
while ((by=nextByte())>=acceptFrom){
byteBuf[totalBytes++] = by;
}
}
public int nextInt() throws IOException{
readToken();
int num=0, i=0;
boolean sign=false;
if (byteBuf[i]==MINUS){
sign = true;
i++;
}
for (; i<totalBytes; i++){
num*=10;
num+=byteBuf[i]-ZERO;
}
return sign?-num:num;
}
public long nextLong() throws IOException{
readToken();
long num=0;
int i=0;
boolean sign=false;
if (byteBuf[i]==MINUS){
sign = true;
i++;
}
for (; i<totalBytes; i++){
num*=10;
num+=byteBuf[i]-ZERO;
}
return sign?-num:num;
}
/*
//TODO test Unix/Windows formats
public void toNextLine() throws IOException{
while ((ch=nextChar())!='\n');
}
*/
public double nextDouble() throws IOException{
readToken();
char[] token = new char[totalBytes];
for (int i = 0; i < totalBytes; i++) {
token[i] = (char)byteBuf[i];
}
return Double.parseDouble(new String(token));
}
public int[] loadIntArray(int size) throws IOException{
int[] a = new int[size];
for (int i = 0; i < a.length; i++) {
a[i] = nextInt();
}
return a;
}
public long[] loadLongArray(int size) throws IOException{
long[] a = new long[size];
for (int i = 0; i < a.length; i++) {
a[i] = nextLong();
}
return a;
}
}
public static abstract class Timing{
private static int counter = 0;
protected String name = "Timing"+(++counter);
private boolean debug;
public Timing(boolean debug) {
super();
this.debug = debug;
}
public abstract void run();
public void start(){
long time1 = System.currentTimeMillis();
run();
long time2 = System.currentTimeMillis();
if (debug)
System.out.println(name+" time = "+(time2-time1)/1000.0+" ms.");
}
}
public static class Alg{
public static interface BooleanChecker{
public boolean check(long arg);
}
public static class BinarySearch{
/**
* This check returns boolean value, result of function.
* It should be monotonic.
*
* @return
*/
public BooleanChecker bc;
/**
* Returns following element: <pre> 0 0 [1] 1 1</pre>
*/
public long search(long left, long right){
while (left<=right){
long mid = (left+right)/2;
if (bc.check(mid)){
right = mid-1;
}else{
left = mid+1;
}
}
return left;
}
/**
* Optional.<br>
* Returns following element: <pre> 1 1 [1] 0 0</pre>
*/
public long searchInverted(long left, long right){
while (left<=right){
long mid = (left+right)/2;
if (!bc.check(mid)){
right = mid-1;
}else{
left = mid+1;
}
}
return left - 1;
}
}
}
public static class Modulo{
long mod = (long)1e9+7;
public Modulo(long mod) {
super();
this.mod = mod;
}
public long inv(long a) {
long res = pow(a, mod-2);
return res;
}
public long pow(long a, long x) {
if (x==0)
return 1;
long part = 1;
if ((x&1)!=0)
part = a;
return (part * pow((a*a)%mod, x>>1)) % mod;
}
public long c(long n, long m){
long res = 1;
for(int i=1; i<=m; i++){
res = (res * (n-m+i)) % mod;
res = (res * inv(i)) % mod;
}
return res;
}
}
public static void main(String[] args) {
new Codeforces_Round_177_Div1_A().run();
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
93505b1a062d544c870695150879e457
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import static java.lang.Math.*;
import java.io.*;
import java.util.*;
import java.math.*;
public class Template {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
String next() {
while (st==null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (Exception e) {}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
public void run() throws Exception {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
Long start = System.currentTimeMillis();
int n = nextInt();
int k = nextInt();
if (n < k || (n>1 && k==1)) {
out.println(-1);
} else {
if (n==k) {
for (int i=0; i<n; i++) out.print((char)('a' + i));
} else {
for (int i=0; i<n-(k-2); i++) {
out.print((char)('a' + i % 2));
}
for (int i=2; i<k; i++) out.print((char)('a'+i));
}
}
Long end = System.currentTimeMillis();
//System.out.println((end - start) / 1000.0);
out.close();
}
public static void main(String[] args) throws Exception {
new Template().run();
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
b123b7ea1c9ddd387121ee667ba511ff
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s =br.readLine().split(" ");
int n = Integer.parseInt(s[0]) ;
int k = Integer.parseInt(s[1]) ;
if(k>n || k == 1 && n != 1 ){
System.out.print("-1");
return ;
}
int a = Math.abs(k-2) ;
int z = n-a ;
int i = 0 ; ;
for(; i<z/2 ;i++)
System.out.print("ab") ;
if((i*2)!= z || z == 0 && i == 0)
System.out.print("a") ;
for (int j = 99 ; j < (99+(k-2)) ; j++ )
System.out.print((char) j) ;
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
c83c79ba0c81e261b14f2fce0c58a498
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
//package ru.akvasov.codeforces.r244;
import java.util.Scanner;
/**
* Created by akvasov on 15.05.14.
*/
public class A {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
StringBuilder sb = new StringBuilder();
if (n == 1 && k == 1){
System.out.println("a");
return;
}
if (k < 2 || k > n) {
System.out.println(-1);
return;
}
int t = n - k + 2;
for (int i = 0; i < t; i++){
if (i % 2 == 0) {
sb.append("a");
} else {
sb.append("b");
}
}
if (t >=0){
for (int i = 0; i < k - 2; i++){
sb.append((char)('c' + i));
}
}
String ans = sb.toString();
if (ans.isEmpty()){
System.out.println(-1);
} else {
System.out.println(sb.toString());
}
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
c3202764605666096a0d9fb131ba7b53
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
/* Codeforces Template */
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;
public class Main {
static long initTime;
static final Random rnd = new Random(7777L);
static boolean writeLog = false;
public static void main(String[] args) throws IOException {
initTime = System.currentTimeMillis();
try {
writeLog = "true".equals(System.getProperty("LOCAL_RUN_7777"));
} catch (SecurityException e) {}
new Thread(null, new Runnable() {
public void run() {
try {
try {
if (new File("input.txt").exists())
System.setIn(new FileInputStream("input.txt"));
} catch (SecurityException e) {}
long prevTime = System.currentTimeMillis();
new Main().run();
log("Total time: " + (System.currentTimeMillis() - prevTime) + " ms");
log("Memory status: " + memoryStatus());
} catch (IOException e) {
e.printStackTrace();
}
}
}, "1", 1L << 24).start();
}
void run() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
in.close();
}
/***************************************************************
* Solution
**************************************************************/
void solve() throws IOException {
int n = nextInt();
int k = nextInt();
if (k > n) {
out.println(-1);
return;
}
if (k == 1) {
out.println(n == 1 ? "a" : "-1");
return;
}
char[] s = new char [n];
for (int i = 0; i < n; i++)
s[i] = (i % 2 == 0) ? 'a' : 'b';
for (int j = 0; j + 2 < k; j++) {
int pos = n - j - 1;
char c = (char) ('a' + k - j - 1);
s[pos] = c;
}
out.println(s);
}
/***************************************************************
* Input
**************************************************************/
BufferedReader in;
PrintWriter out;
StringTokenizer st = new StringTokenizer("");
String nextToken() throws IOException {
while (!st.hasMoreTokens())
st = new StringTokenizer(in.readLine());
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
int[] nextIntArray(int size) throws IOException {
int[] ret = new int [size];
for (int i = 0; i < size; i++)
ret[i] = nextInt();
return ret;
}
long[] nextLongArray(int size) throws IOException {
long[] ret = new long [size];
for (int i = 0; i < size; i++)
ret[i] = nextLong();
return ret;
}
double[] nextDoubleArray(int size) throws IOException {
double[] ret = new double [size];
for (int i = 0; i < size; i++)
ret[i] = nextDouble();
return ret;
}
String nextLine() throws IOException {
st = new StringTokenizer("");
return in.readLine();
}
boolean EOF() throws IOException {
while (!st.hasMoreTokens()) {
String s = in.readLine();
if (s == null)
return true;
st = new StringTokenizer(s);
}
return false;
}
/***************************************************************
* Output
**************************************************************/
void printRepeat(String s, int count) {
for (int i = 0; i < count; i++)
out.print(s);
}
void printArray(int[] array) {
if (array == null || array.length == 0)
return;
for (int i = 0; i < array.length; i++) {
if (i > 0) out.print(' ');
out.print(array[i]);
}
out.println();
}
void printArray(long[] array) {
if (array == null || array.length == 0)
return;
for (int i = 0; i < array.length; i++) {
if (i > 0) out.print(' ');
out.print(array[i]);
}
out.println();
}
void printArray(double[] array) {
if (array == null || array.length == 0)
return;
for (int i = 0; i < array.length; i++) {
if (i > 0) out.print(' ');
out.print(array[i]);
}
out.println();
}
void printArray(double[] array, String spec) {
if (array == null || array.length == 0)
return;
for (int i = 0; i < array.length; i++) {
if (i > 0) out.print(' ');
out.printf(Locale.US, spec, array[i]);
}
out.println();
}
void printArray(Object[] array) {
if (array == null || array.length == 0)
return;
boolean blank = false;
for (Object x : array) {
if (blank) out.print(' '); else blank = true;
out.print(x);
}
out.println();
}
@SuppressWarnings("rawtypes")
void printCollection(Collection collection) {
if (collection == null || collection.isEmpty())
return;
boolean blank = false;
for (Object x : collection) {
if (blank) out.print(' '); else blank = true;
out.print(x);
}
out.println();
}
/***************************************************************
* Utility
**************************************************************/
static String memoryStatus() {
return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB";
}
static void checkMemory() {
System.err.println(memoryStatus());
}
static long prevTimeStamp = Long.MIN_VALUE;
static void updateTimer() {
prevTimeStamp = System.currentTimeMillis();
}
static long elapsedTime() {
return (System.currentTimeMillis() - prevTimeStamp);
}
static void checkTimer() {
System.err.println(elapsedTime() + " ms");
}
static void chk(boolean f) {
if (!f) throw new RuntimeException("Assert failed");
}
static void chk(boolean f, String format, Object ... args) {
if (!f) throw new RuntimeException(String.format(format, args));
}
static void log(String format, Object ... args) {
if (writeLog) System.err.println(String.format(Locale.US, format, args));
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
0d3b6d9030a199b20f7a851656505787
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer(r.readLine());
int n=Integer.parseInt(st.nextToken());
int k=Integer.parseInt(st.nextToken());
PrintWriter pr=new PrintWriter(System.out);
if(k>n||(n>k&&k==1))
{
pr.println(-1);
}
else
if(k==1&&n==1)
{
pr.println("a");
}
else
{
int lim=n-(k-2);
int x=lim/2;
for(int j=0;j<x;j++)
{
pr.print("ab");
}
if(lim%2!=0)
{
pr.print("a");
}
for(int j=2;j<n-lim+2;j++)
{
pr.print((char)('a'+j));
}
}
pr.flush();
pr.close();
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
75b7ec812015fa24b37bc2aab479fcfa
|
train_001.jsonl
|
1364916600
|
Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class CFR177A {
public static void findString(int n,int k) {
if (k > n || (k == 1 && n > 1)) {
System.out.println("-1");
return;
}
for (int i = 0; i < n - k + 2 && i < n ; i++) {
System.out.print(i % 2 == 0?"a":"b");
}
for (int i = n - k + 2; i < n; i++) {
char s = (char) ((int)'a' + (i - n + k));
System.out.print(s);
}
}
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String input = in.readLine();
String[] inputs = input.split(" ");
int n = Integer.parseInt(inputs[0]);
int k = Integer.parseInt(inputs[1]);
findString(n, k);
}
}
|
Java
|
["7 4", "4 7"]
|
2 seconds
|
["ababacd", "-1"]
| null |
Java 7
|
standard input
|
[
"greedy"
] |
2f659be28674a81f58f5c587b6a0f465
|
A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters.
| 1,300 |
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
|
standard output
| |
PASSED
|
d560aa5bf3e2518bef8d8d7cd56a2935
|
train_001.jsonl
|
1457342700
|
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi,βyi).They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xiβ-βxj|β+β|yiβ-βyj|. Daniel, as an ordinary person, calculates the distance using the formula .The success of the operation relies on the number of pairs (i,βj) (1ββ€βiβ<βjββ€βn), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public final class Watchmen {
public static long combinatoria(long n) {
return (n * (n - 1)) / 2;
}
static public void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // para
// leer
// la
// entrada
StringBuilder out = new StringBuilder(); // para escribir la salida,
// todo junto y no imprimir
// linea por linea
String line;
// leer el input hasta EOF (line == null), esto se logra con Ctrl + D en una terminal
while ((line = in.readLine()) != null) {
String[] tokens = line.split(" "); // "partir" cada linea por espacios
int cantidad = Integer.parseInt(tokens[0]);
ArrayList<Integer[]> pares = new ArrayList<>();
for (int i = 0; i < cantidad; i++) {
line = in.readLine();
tokens = line.split(" ");
Integer[] par = {Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])};
pares.add(par);
}
long suma = 0;
Collections.sort(pares, new Comparator<Integer[]>() {
@Override
public int compare(Integer[] o1, Integer[] o2) {
int compare = o1[0].compareTo(o2[0]);
if (compare == 0)
return o1[1].compareTo(o2[1]);
return compare;
}
});
//contar iguales
int[] paresIguales = new int[200001];
Integer[] currentPar = pares.get(0);
int currentIndex = 0;
paresIguales[currentIndex]++;
for (int i = 1; i < cantidad; i++) {
if (!pares.get(i)[0].equals(currentPar[0]) || !pares.get(i)[1].equals(currentPar[1])) {
currentIndex++;
currentPar = pares.get(i);
}
paresIguales[currentIndex]++;
}
for (int i = 0; i <= cantidad; i++) {
suma -= combinatoria(paresIguales[i]);
}
int[] xIguales = new int[200001];
int currentX = pares.get(0)[0];
currentIndex = 0;
xIguales[currentIndex]++;
for (int i = 1; i < cantidad; i++) {
if (pares.get(i)[0] != currentX) {
currentIndex++;
currentX = pares.get(i)[0];
}
xIguales[currentIndex]++;
}
for (int i = 0; i <= cantidad; i++) {
suma += combinatoria(xIguales[i]);
}
// y iguales
Collections.sort(pares, new Comparator<Integer[]>() {
@Override
public int compare(Integer[] o1, Integer[] o2) {
int compare = o1[1].compareTo(o2[1]);
if (compare == 0)
return o1[0].compareTo(o2[0]);
return compare;
}
});
int[] yIguales = new int[200001];
int currentY = pares.get(0)[1];
currentIndex = 0;
yIguales[currentIndex]++;
for (int i = 1; i < cantidad; i++) {
if (pares.get(i)[1] != currentY) {
currentIndex++;
currentY = pares.get(i)[1];
}
yIguales[currentIndex]++;
}
for (int i = 0; i <= currentIndex; i++) {
suma += combinatoria(yIguales[i]);
}
System.out.println(suma);
}
}
}
|
Java
|
["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1"]
|
3 seconds
|
["2", "11"]
|
NoteIn the first sample, the distance between watchman 1 and watchman 2 is equal to |1β-β7|β+β|1β-β5|β=β10 for Doctor Manhattan and for Daniel. For pairs (1,β1), (1,β5) and (7,β5), (1,β5) Doctor Manhattan and Daniel will calculate the same distances.
|
Java 7
|
standard input
|
[
"data structures",
"geometry",
"math"
] |
bd7b85c0204f6b36dc07f8a96fc36161
|
The first line of the input contains the single integer n (1ββ€βnββ€β200β000)Β β the number of watchmen. Each of the following n lines contains two integers xi and yi (|xi|,β|yi|ββ€β109). Some positions may coincide.
| 1,400 |
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
|
standard output
| |
PASSED
|
9c0f85e03ae07d07e2c2d43556a82905
|
train_001.jsonl
|
1457342700
|
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi,βyi).They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xiβ-βxj|β+β|yiβ-βyj|. Daniel, as an ordinary person, calculates the distance using the formula .The success of the operation relies on the number of pairs (i,βj) (1ββ€βiβ<βjββ€βn), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
|
256 megabytes
|
import java.awt.Point;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Comparator;
public class A650 {
public static void main(String[] args) throws IOException {
InputReader reader = new InputReader(System.in);
int N = reader.readInt();
Point[] P = new Point[N];
for (int n=0; n<N; n++) {
P[n] = new Point(reader.readInt(), reader.readInt());
}
Arrays.sort(P, new Comparator<Point>() {
@Override
public int compare(Point o1, Point o2) {
return o1.x-o2.x;
}
});
long answer = 0;
int idx = 0;
while (idx < N) {
int start = idx++;
while (idx < N && P[idx].x == P[start].x) idx++;
long count = idx-start;
answer += count*(count-1);
}
Arrays.sort(P, new Comparator<Point>() {
@Override
public int compare(Point o1, Point o2) {
int diff = o1.y-o2.y;
if (diff == 0) {
diff = o1.x-o2.x;
}
return diff;
}
});
idx = 0;
while (idx < N) {
int start = idx++;
while (idx < N && P[idx].y == P[start].y) idx++;
long count = idx-start;
answer += count*(count-1);
}
idx = 0;
while (idx < N) {
int start = idx++;
while (idx < N && P[idx].y == P[start].y && P[idx].x == P[start].x) idx++;
long count = idx-start;
answer -= count*(count-1);
}
System.out.println(answer/2);
}
static final class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
private int read() throws IOException {
if (curChar >= numChars) {
curChar = 0;
numChars = stream.read(buf);
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public final int readInt() throws IOException {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return negative ? -res : res;
}
public final long readLong() throws IOException {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return negative ? -res : res;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
}
|
Java
|
["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1"]
|
3 seconds
|
["2", "11"]
|
NoteIn the first sample, the distance between watchman 1 and watchman 2 is equal to |1β-β7|β+β|1β-β5|β=β10 for Doctor Manhattan and for Daniel. For pairs (1,β1), (1,β5) and (7,β5), (1,β5) Doctor Manhattan and Daniel will calculate the same distances.
|
Java 7
|
standard input
|
[
"data structures",
"geometry",
"math"
] |
bd7b85c0204f6b36dc07f8a96fc36161
|
The first line of the input contains the single integer n (1ββ€βnββ€β200β000)Β β the number of watchmen. Each of the following n lines contains two integers xi and yi (|xi|,β|yi|ββ€β109). Some positions may coincide.
| 1,400 |
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
|
standard output
| |
PASSED
|
bf31836d4dfd7e38f5a82516f9022b25
|
train_001.jsonl
|
1457342700
|
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi,βyi).They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xiβ-βxj|β+β|yiβ-βyj|. Daniel, as an ordinary person, calculates the distance using the formula .The success of the operation relies on the number of pairs (i,βj) (1ββ€βiβ<βjββ€βn), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class A650 {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] inputs = bf.readLine().split(" ");
Integer n = Integer.parseInt(inputs[0]);
HashMap<Long, Long> x = new HashMap<>(); HashMap<Long, Long> y = new HashMap<>();
HashMap<Long, HashMap<Long, Long>> dup = new HashMap<>();
for (int i = 0; i < n; i++) {
inputs = bf.readLine().split(" ");
Long xi = Long.parseLong(inputs[0]);
Long yi = Long.parseLong(inputs[1]);
// count x
if (x.containsKey(xi)) {
x.put(xi, x.get(xi)+1);
}
else {
x.put(xi, 1L);
}
// count y
if (y.containsKey(yi)) {
y.put(yi, y.get(yi)+1);
}
else {
y.put(yi, 1L);
}
// count duplicate
if (dup.containsKey(xi)) {
if(dup.get(xi).containsKey(yi)){
dup.get(xi).put(yi, dup.get(xi).get(yi)+1);
}
else {
dup.get(xi).put(yi, 1L);
}
}
else {
HashMap<Long, Long> temp = new HashMap<>();
temp.put(yi, 1L);
dup.put(xi, temp);
}
}
long sum = 0;
// sum horizontal
for (Long xi : x.keySet()) {
sum += x.get(xi) * (x.get(xi)-1) / 2;
}
// sum vertical
for (Long yi : y.keySet()) {
sum += y.get(yi) * (y.get(yi)-1) / 2;
}
for (Long xi : dup.keySet()) {
for(Long yi : dup.get(xi).keySet()){
sum -= dup.get(xi).get(yi)* (dup.get(xi).get(yi)-1) / 2;
}
}
// System.out.println(x);
// System.out.println(y);
// System.out.println(dup);
System.out.println(sum);
}
}
|
Java
|
["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1"]
|
3 seconds
|
["2", "11"]
|
NoteIn the first sample, the distance between watchman 1 and watchman 2 is equal to |1β-β7|β+β|1β-β5|β=β10 for Doctor Manhattan and for Daniel. For pairs (1,β1), (1,β5) and (7,β5), (1,β5) Doctor Manhattan and Daniel will calculate the same distances.
|
Java 7
|
standard input
|
[
"data structures",
"geometry",
"math"
] |
bd7b85c0204f6b36dc07f8a96fc36161
|
The first line of the input contains the single integer n (1ββ€βnββ€β200β000)Β β the number of watchmen. Each of the following n lines contains two integers xi and yi (|xi|,β|yi|ββ€β109). Some positions may coincide.
| 1,400 |
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
|
standard output
| |
PASSED
|
8f1b56af9293ee268845c42df2498c23
|
train_001.jsonl
|
1457342700
|
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi,βyi).They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xiβ-βxj|β+β|yiβ-βyj|. Daniel, as an ordinary person, calculates the distance using the formula .The success of the operation relies on the number of pairs (i,βj) (1ββ€βiβ<βjββ€βn), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
|
256 megabytes
|
import java.util.*;
import java.util.LinkedList;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class tmp {
public static void main(String [] args) throws Exception{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
StringBuilder sb = new StringBuilder();
int n = Integer.parseInt(st.nextToken());
HashMap<Integer,Integer> x = new HashMap();
HashMap<Integer,Integer> y = new HashMap();
HashMap<String, Integer> xy = new HashMap();
int a,b;
String s;
for(int i=0; i<n; i++){
s = in.readLine();
st = new StringTokenizer(s);
if(!xy.containsKey(s))
xy.put(s,1);
else
xy.put(s, xy.get(s)+1);
a =Integer.parseInt(st.nextToken());
if(!x.containsKey(a))
x.put(a,1);
else
x.put(a, x.get(a)+1);
b = Integer.parseInt(st.nextToken());
if(!y.containsKey(b))
y.put(b,1);
else
y.put(b, y.get(b)+1);
// System.out.println(st.toString() + " - " + a + " - " + b);
}
long out = 0;
for(Integer xx : x.keySet()){
a = x.get(xx);
out += (1l*a*(a-1))/2 ;
}
for(Integer yy : y.keySet()){
b = y.get(yy);
out += (1l*b*(b-1))/2 ;
}
for(String ss : xy.keySet()){
b = xy.get(ss);
out -= (1l*b*(b-1))/2 ;
}
System.out.println(out);
}
}
class Pair implements Comparable<Pair>{
int x,y;
public Pair(int fi, int ti){
x = fi;
y = ti;
}
public int compareTo(Pair p){
return x < p.x ? -1 : (x == p.x ? (y < p.y ? -1 : 1) : 1);
}
}
|
Java
|
["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1"]
|
3 seconds
|
["2", "11"]
|
NoteIn the first sample, the distance between watchman 1 and watchman 2 is equal to |1β-β7|β+β|1β-β5|β=β10 for Doctor Manhattan and for Daniel. For pairs (1,β1), (1,β5) and (7,β5), (1,β5) Doctor Manhattan and Daniel will calculate the same distances.
|
Java 7
|
standard input
|
[
"data structures",
"geometry",
"math"
] |
bd7b85c0204f6b36dc07f8a96fc36161
|
The first line of the input contains the single integer n (1ββ€βnββ€β200β000)Β β the number of watchmen. Each of the following n lines contains two integers xi and yi (|xi|,β|yi|ββ€β109). Some positions may coincide.
| 1,400 |
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
|
standard output
| |
PASSED
|
d4f45acd7f40ee90a01ec57c9da9b8be
|
train_001.jsonl
|
1457342700
|
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi,βyi).They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xiβ-βxj|β+β|yiβ-βyj|. Daniel, as an ordinary person, calculates the distance using the formula .The success of the operation relies on the number of pairs (i,βj) (1ββ€βiβ<βjββ€βn), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Problems {
public static void main(String[] args) throws IOException {
new Problems().runMain();
}
void runMain() {
Scanner sc = new Scanner(System.in);
long counter = 0;
int n = sc.nextInt();
Map<Integer, Integer> xs = new HashMap<Integer, Integer>();
Map<Integer, Integer> ys = new HashMap<Integer, Integer>();
Map<String, Integer> pairs = new HashMap<String, Integer>();
int x,y;
Integer countX, countY, countXY;
for (int i = 0; i < n; i++) {
x = sc.nextInt();
y = sc.nextInt();
String currXY = String.valueOf(x) + ";" + String.valueOf(y);
int a = xs.get(x) == null ? 0 : xs.get(x);
int b = ys.get(y) == null ? 0 : ys.get(y);
int c = pairs.get(currXY) == null ? 0 : pairs.get(currXY);
counter += (a + b - c);
countX = xs.get(x);
if (countX == null) {
xs.put(x, 1);
}
else {
xs.put(x, countX + 1);
}
countY = ys.get(y);
if (countY == null) {
ys.put(y, 1);
}
else {
ys.put(y, countY + 1);
}
countXY = pairs.get(currXY);
if (countXY == null) {
pairs.put(currXY, 1);
}
else {
pairs.put(currXY, countXY + 1);
}
}
sc.close();
System.out.print(counter);
}
}
|
Java
|
["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1"]
|
3 seconds
|
["2", "11"]
|
NoteIn the first sample, the distance between watchman 1 and watchman 2 is equal to |1β-β7|β+β|1β-β5|β=β10 for Doctor Manhattan and for Daniel. For pairs (1,β1), (1,β5) and (7,β5), (1,β5) Doctor Manhattan and Daniel will calculate the same distances.
|
Java 7
|
standard input
|
[
"data structures",
"geometry",
"math"
] |
bd7b85c0204f6b36dc07f8a96fc36161
|
The first line of the input contains the single integer n (1ββ€βnββ€β200β000)Β β the number of watchmen. Each of the following n lines contains two integers xi and yi (|xi|,β|yi|ββ€β109). Some positions may coincide.
| 1,400 |
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
|
standard output
| |
PASSED
|
6908a39b444fa32fce58ed651277a7bd
|
train_001.jsonl
|
1457342700
|
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi,βyi).They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xiβ-βxj|β+β|yiβ-βyj|. Daniel, as an ordinary person, calculates the distance using the formula .The success of the operation relies on the number of pairs (i,βj) (1ββ€βiβ<βjββ€βn), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
|
256 megabytes
|
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class A {
static <T> void add(Map<T, Integer> S, T v) {
Integer num = S.get(v);
if(num == null) {
num = 0;
}
S.put(v, num + 1);
}
static <T>long calc(Map<T, Integer> S) {
long ans = 0;
for(int num: S.values()) {
long tmp = num;
ans += (tmp*(tmp-1))/2;
}
return ans;
}
static class Pair {
int x, y;
public Pair(int x, int y) {
super();
this.x = x;
this.y = y;
}
@Override
public int hashCode() {
return x*31 + y;
}
@Override
public boolean equals(Object obj) {
Pair p = (Pair)obj;
return x == p.x && y == p.y;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
Map<Integer, Integer> X, Y;
X = new HashMap<>();
Y = new HashMap<>();
Map<Pair, Integer> map = new HashMap<>();
for(int i = 0; i < N; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
Pair p = new Pair(x, y);
add(X, x);
add(Y, y);
add(map, p);
}
System.out.println(calc(X) + calc(Y) - calc(map));
}
}
|
Java
|
["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1"]
|
3 seconds
|
["2", "11"]
|
NoteIn the first sample, the distance between watchman 1 and watchman 2 is equal to |1β-β7|β+β|1β-β5|β=β10 for Doctor Manhattan and for Daniel. For pairs (1,β1), (1,β5) and (7,β5), (1,β5) Doctor Manhattan and Daniel will calculate the same distances.
|
Java 7
|
standard input
|
[
"data structures",
"geometry",
"math"
] |
bd7b85c0204f6b36dc07f8a96fc36161
|
The first line of the input contains the single integer n (1ββ€βnββ€β200β000)Β β the number of watchmen. Each of the following n lines contains two integers xi and yi (|xi|,β|yi|ββ€β109). Some positions may coincide.
| 1,400 |
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
|
standard output
| |
PASSED
|
f5ccffbff4a86e2e789f8e4301b2f7c3
|
train_001.jsonl
|
1457342700
|
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi,βyi).They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xiβ-βxj|β+β|yiβ-βyj|. Daniel, as an ordinary person, calculates the distance using the formula .The success of the operation relies on the number of pairs (i,βj) (1ββ€βiβ<βjββ€βn), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.math.*;
public class A implements Runnable {
private static BufferedReader in;
private static PrintWriter out;
private static StringTokenizer st;
private static Random rnd;
private long getPair(long x, long y) {
return x * Integer.MAX_VALUE + y;
}
private void solve() throws IOException {
int n = nextInt();
Map<Integer, Integer> byX = new TreeMap<>();
Map<Integer, Integer> byY = new TreeMap<>();
Map<Long, Integer> cnt = new TreeMap<>();
long result = 0;
for (int i = 0; i < n; i++) {
int x = nextInt(), y = nextInt();
result += increment(byX, x);
result += increment(byY, y);
result -= increment(cnt, getPair(x, y));
}
out.println(result);
}
private int increment(Map<Long, Integer> m, long i) {
Integer b = m.get(i);
if (b == null)
b = 0;
m.put(i, b + 1);
return b;
}
private int increment(Map<Integer, Integer> m, int i) {
Integer b = m.get(i);
if (b == null)
b = 0;
m.put(i, b + 1);
return b;
}
public static void main(String[] args) {
new A().run();
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
rnd = new Random();
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(42);
}
}
private String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String line = in.readLine();
if (line == null)
return null;
st = new StringTokenizer(line);
}
return st.nextToken();
}
private int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
private long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
private double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
|
Java
|
["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1"]
|
3 seconds
|
["2", "11"]
|
NoteIn the first sample, the distance between watchman 1 and watchman 2 is equal to |1β-β7|β+β|1β-β5|β=β10 for Doctor Manhattan and for Daniel. For pairs (1,β1), (1,β5) and (7,β5), (1,β5) Doctor Manhattan and Daniel will calculate the same distances.
|
Java 7
|
standard input
|
[
"data structures",
"geometry",
"math"
] |
bd7b85c0204f6b36dc07f8a96fc36161
|
The first line of the input contains the single integer n (1ββ€βnββ€β200β000)Β β the number of watchmen. Each of the following n lines contains two integers xi and yi (|xi|,β|yi|ββ€β109). Some positions may coincide.
| 1,400 |
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
|
standard output
| |
PASSED
|
5d4e3ff7447770feebd5c1957f7448ce
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
/* https://codeforces.com/contest/378/problem/B
idea:
not care about whick k should be choosen in each semifinal.
first k element in each semifinals will be choose.
in each semifinals, in each element in k-th -> n will be choose
if it less than (n - k - 1) -th in the other simifinal.
*/
import java.util.Scanner;
public class Semifinals {
static void updateResult(int[] ip1, int[] ip2, char[] result1, char[] result2) {
int n = result1.length;
for (int i = n / 2; i < n; i++){
if (ip1[i] < ip2[n - i - 1]) {
result1[i] = '1';
}
if (ip2[i] < ip1[n - i - 1]) {
result2[i] = '1';
}
}
}
public static void main( String args[]) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
// input
int[] ip1 = new int[n];
int[] ip2 = new int[n];
for (int i = 0; i < n; i++) {
ip1[i] = scanner.nextInt();
ip2[i] = scanner.nextInt();
}
scanner.close();
// result
char[] result1 = new char[n];
char[] result2 = new char[n];
int mid = n / 2;
for( int i = 0; i < n; i++) {
result1[i] = i < mid ? '1' : '0';
result2[i] = i < mid ? '1' : '0';
}
// update result
updateResult(ip1, ip2, result1, result2);
// show result
System.out.println(new String(result1));
System.out.println(new String(result2));
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
e0b1307a5e16af1ed6928a4200809528
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.*;
public class Semifinals {
static void updateResult(ArrayList<Integer> ip1, ArrayList<Integer> ip2
, char[] result1, char[] result2)
{
int n = result1.length;
for (int i = n / 2; i < n; i++){
if (ip1.get(i) < ip2.get(n - i - 1)) {
result1[i] = '1';
}
if (ip2.get(i) < ip1.get(n - i - 1)) {
result2[i] = '1';
}
}
}
public static void main( String args[]) {
Scanner scanner = new Scanner(System.in);
// input
ArrayList<Integer> ip1 = new ArrayList<Integer>();
ArrayList<Integer> ip2 = new ArrayList<Integer>();
// Scanner lineScanner;
// String line;
// boolean firstRowFlg = true;
// int length = 0;
// for (int count = 0; (count < length || firstRowFlg) && scanner.hasNextLine(); ) {
// line = scanner.nextLine();
// lineScanner = new Scanner(line);
// if (firstRowFlg) {
// firstRowFlg = false;
// length = lineScanner.nextInt();
// } else {
// count++;
// ip1.add(lineScanner.nextInt());
// ip2.add(lineScanner.nextInt());
// }
// lineScanner.close();
// }
int length = scanner.nextInt();
for (int i = 0; i < length; i++) {
ip1.add(scanner.nextInt());
ip2.add(scanner.nextInt());
}
scanner.close();
// result
char[] result1 = new char[length];
char[] result2 = new char[length];
int mid = length / 2;
for( int i = 0; i < length; i++) {
result1[i] = i < mid ? '1' : '0';
result2[i] = i < mid ? '1' : '0';
}
// result2 = new StringBuilder(result1);
updateResult(ip1, ip2, result1, result2);
// show result
System.out.println(new String(result1));
System.out.println(new String(result2));
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
92568da2299719b7e8e1ccf53346755b
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a1 = new int[n];
int[] a2 = new int[n];
for(int i=0; i<n; i++){
a1[i] = sc.nextInt();
a2[i] = sc.nextInt();
}
int[] b1 = new int[n];
int[] b2 = new int[n];
// k=n/2
int max = 0;
for(int i=0; i<n/2; i++){
b1[i] = 1;
b2[i] = 1;
max = a1[i] > a2[i]? a1[i]: a2[i];
}
// k = 0
for (int i=n-1; i>=n/2; i--){
if (a1[i] < a2[n-i-1]){
b1[i] = 1;
}
if (a2[i] < a1[n-1-i]){
b2[i] = 1;
}
}
for(int i=0; i<n; i++){
System.out.print(b1[i]);
}
System.out.println();
for(int i=0; i<n; i++){
System.out.print(b2[i]);
}
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
a01866965bc73d62025a492a0df7ebb1
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
public class Semifinals {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
// List<String> arr = new ArrayList<String>();
List<Integer> listWinner = new ArrayList<Integer>();
// List<Integer> listordered = new ArrayList<Integer>();
List<Integer> left = new ArrayList<Integer>();
List<Integer> right = new ArrayList<Integer>();
ArrayList<String> resultA = new ArrayList<>();
ArrayList<String> resultB = new ArrayList<>();
for (int i = 0; i < n; i++) {
left.add(scan.nextInt());
resultA.add("0");
right.add(scan.nextInt());
resultB.add("0");
}
// lay moi thΓ¨n 1 nα»a vΓ¬ lΓ data ΔΓΊng
for (int i = 0; i < n / 2; i++) {
resultA.set(i, "1");
resultB.set(i, "1");
}
int i = 0, j = 0, count = 0;
while (count <= n-1) {
if (left.get(i) <= right.get(j)) {
resultA.set(i, "1");
i++;
count++;
} else {
resultB.set(j, "1");
j++;
count++;
}
}
String strA = resultA.stream().map(e->e.toString()).collect(Collectors.joining());
String strB = resultB.stream().map(e->e.toString()).collect(Collectors.joining());
System.out.println(strA);
System.out.println(strB);
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
80ff726c4de9ac65d205a4ad6f710f08
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.PriorityQueue;
import java.util.Scanner;
public class SEMIFINALS {
public static void main(String[] args) {
Scanner nik = new Scanner(System.in);
PriorityQueue<pair> pq = new PriorityQueue<>();
int n = nik.nextInt();
StringBuilder st1 = new StringBuilder();
StringBuilder st2 = new StringBuilder();
for (int i = 0; i < n; i++) {
pq.add(new pair(nik.nextInt(), 1));
pq.add(new pair(nik.nextInt(), 2));
}
for (int i = 0; i < n; i++) {
pair p = pq.remove();
if (p.t == 1) {
st1.append(1);
} else {
st2.append(1);
}
}
while (st1.length() < n / 2) {
st1.append(1);
}
while (st2.length() < n / 2) {
st2.append(1);
}
while (st1.length() != n) {
st1.append(0);
}
while (st2.length() != n) {
st2.append(0);
}
System.out.println(st1 + "\n" + st2);
}
private static class pair implements Comparable<pair> {
int x;
int t;
pair(int x, int t) {
this.x = x;
this.t = t;
}
public int compareTo(pair o) {
return this.x - o.x;
}
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
a4a2461bfd9f72f9f3671f83f7f44217
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public final class Main {
static class Triplet {
int time;
int type;
int idx;
Triplet(int time, int type, int idx) {
this.time = time;
this.type = type;
this.idx = idx;
}
}
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
List<Triplet> arr = new ArrayList<>();
int n = sc.nextInt();
for(int i = 0; i<n; i++) {
Triplet a = new Triplet(sc.nextInt(), 0, i);
Triplet b = new Triplet(sc.nextInt(), 1, i);
arr.add(a);
arr.add(b);
}
Collections.sort(arr, (a, b)->Integer.compare(a.time, b.time));
HashSet<Integer> a1 = new HashSet<>();
HashSet<Integer> a2 = new HashSet<>();
for(int i = 0; i<n; i++) {
if(arr.get(i).type==0)
a1.add(arr.get(i).idx);
else a2.add(arr.get(i).idx);
}
for(int i = 0; i<n/2; i++) {
a1.add(i);
a2.add(i);
}
char[] ans1 = new char[n];
Arrays.fill(ans1, '0');
for(int i: a1)
ans1[i] = '1';
System.out.println(new String(ans1));
Arrays.fill(ans1, '0');
for(int i: a2)
ans1[i] = '1';
System.out.println(new String(ans1));
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
5c9ae5313ff391e84f0853e1df5d818f
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.Scanner;
public class Semifinals {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Integer numOfPlayer = input.nextInt();
Integer maxK = numOfPlayer/2;
StringBuilder chanceA = new StringBuilder();
StringBuilder chanceB = new StringBuilder();
int[] groupA = new int[numOfPlayer];
int[] groupB = new int[numOfPlayer];
for(int i = 0; i < numOfPlayer; i++) {
groupA[i] = input.nextInt();
groupB[i] = input.nextInt();
if(i < maxK) {
chanceA.append(1);
chanceB.append(1);
} else {
if(groupA[i] < groupB[numOfPlayer - (i + 1)]) {
chanceA.append(1);
} else {
chanceA.append(0);
}
if(groupB[i] < groupA[numOfPlayer - (i + 1)]) {
chanceB.append(1);
} else {
chanceB.append(0);
}
}
}
System.out.println(chanceA);
System.out.println(chanceB);
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
6094a5b7941b2ae9946560fcb4775d88
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class C {
private static class P {
int i;
int s;
int sf;
public int getS() {
return s;
}
public P(int sf,int i, int s) {
this.sf=sf;
this.i = i;
this.s = s;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
P p = (P) o;
return i == p.i &&
s == p.s &&
sf == p.sf;
}
@Override
public int hashCode() {
return Objects.hash(i, s, sf);
}
}
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int n=fs.nextInt();
List<P> first = new ArrayList<>();
List<P> second = new ArrayList<>();
for (int i=0; i<n;++i) {
first.add(new P(0,i,fs.nextInt()));
second.add(new P(1,i,fs.nextInt()));
}
first.sort(Comparator.comparing(P::getS));
second.sort(Comparator.comparing(P::getS));
Set<Integer> win1 = new HashSet<>();
Set<Integer> win2 = new HashSet<>();
win1.addAll(first.subList(0, n/2).stream().map(p->p.i).collect(Collectors.toList()));
win2.addAll(second.subList(0,n/2).stream().map(p->p.i).collect(Collectors.toList()));
List<P> all = new ArrayList<>(first);
all.addAll(second);
all.sort(Comparator.comparing(P::getS));
for (int i=0; i<n; ++i) {
if (all.get(i).sf==0){
win1.add(all.get(i).i);
} else {
win2.add(all.get(i).i);
}
}
StringBuilder s1=new StringBuilder();
StringBuilder s2=new StringBuilder();
for (int i=0;i<n;++i) {
if (win1.contains(i)) {
s1.append("1");
} else {
s1.append("0");
}
if (win2.contains(i)) {
s2.append("1");
} else {
s2.append("0");
}
}
System.out.println(s1.toString());
System.out.println(s2.toString());
}
static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
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
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
39a6af958c53bcc4c8c9c63d21f6e3e3
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* @author Don Li
*/
public class Semifinals {
void solve() {
int n = in.nextInt();
int[] a = new int[n], b = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
b[i] = in.nextInt();
}
int max = -1;
for (int i = 0, j = 0, k = 0; i < n || j < n; ) {
if (i == n || j < n && a[i] > b[j]) {
max = b[j++];
} else {
max = a[i++];
}
if (++k == n) break;
}
for (int i = 0; i < n; i++) {
if (i < n / 2 || a[i] <= max) out.print('1');
else out.print('0');
}
out.println();
for (int i = 0; i < n; i++) {
if (i < n / 2 || b[i] <= max) out.print('1');
else out.print('0');
}
out.println();
}
public static void main(String[] args) {
in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
out = new PrintWriter(System.out);
new Semifinals().solve();
out.close();
}
static FastScanner in;
static PrintWriter out;
static class FastScanner {
BufferedReader in;
StringTokenizer st;
public FastScanner(BufferedReader in) {
this.in = in;
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
ee5f351bcedca2e17e9c74d140a9f09c
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.ArrayList;
import java.io.InputStream;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//input data
Scanner s = new Scanner(System.in);
int n = s.nextInt(); //number of participant each semifinal
ArrayList<Integer> A = new ArrayList(); //record result of participants from 1st and 2nd semifinals
ArrayList<Integer> B = new ArrayList();
for (int i=0; i< n; i++){
A.add(s.nextInt());
B.add(s.nextInt());
}
//processing data
int i =0, j =0;
while (i + j + 2 <= n +1){
if (A.get(i) < B.get(j)){
A.set(i,1);
i++;
} else {
B.set(j,1);
j++;
}
}
int k = n/2;
for (i=0; i <k; i++){
A.set(i,1);
B.set(i,1);
}
for (i=k; i<n; i++){
if (A.get(i) != 1) A.set(i,0);
if (B.get(i) != 1) B.set(i,0);
}
for (int count =0; count<n; count++){
System.out.print(A.get(count));
}
System.out.println();
for (int count =0; count<n; count++){
System.out.print(B.get(count));
}
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
2eb3dba1200a9eb091f6fbde1a350018
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.ArrayList;
import java.io.InputStream;
import java.io.IOException;
import java.util.Scanner;
import java.lang.StringBuilder;
public class Main {
//idea: create a class that contains the participant's record and chance to enter
//We have 0 <= 2k <= n, with the largest k possible, all the members up to k in each tournament have a chance
//With k=0, we can only select based on record. n members with the highest record have the chance
public static void main(String[] args) {
//input data
Scanner s = new Scanner(System.in);
int n = s.nextInt(); //number of participant each semifinal
ArrayList<Participant> A = new ArrayList(); //record result of participants from 1st and 2nd semifinals
ArrayList<Participant> B = new ArrayList();
for (int i=0; i< n; i++){
int a = s.nextInt();
A.add(new Participant(a));
int b = s.nextInt();
B.add(new Participant(b));
}
//processing data
int k = n/2;
for (int i=0; i <k; i++){
A.get(i).HaveChance();
B.get(i).HaveChance();
}
int i =0, j =0;
while (i + j + 2 <= n +1){
if (A.get(i).record < B.get(j).record){
A.get(i).HaveChance();
i++;
} else {
B.get(j).HaveChance();
j++;
}
}
StringBuilder sb = new StringBuilder();
for (int count =0; count<n; count++){
sb.append(A.get(count).chance);
}
sb.append("\n");
for (int count =0; count<n; count++){
sb.append(B.get(count).chance);
}
System.out.println(sb);
}
}
class Participant{
String chance = "0"; // record chance to get in final, 0 means no chance, 1 means have chance
int record; //personal record
Participant(int rec){
record = rec;
}
void HaveChance(){
chance = "1";
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
21453fedda8257a54338efb8fa1e0a13
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class CF378B {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] aa = new int[n];
int[] bb = new int[n];
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
aa[i] = Integer.parseInt(st.nextToken());
bb[i] = Integer.parseInt(st.nextToken());
}
int a = 0, b = 0;
while (a + b < n)
if (aa[a] < bb[b])
a++;
else
b++;
a = Math.max(a, n / 2);
b = Math.max(b, n / 2);
StringBuilder sa = new StringBuilder();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < a; i++)
sa.append('1');
for (int i = a; i < n; i++)
sa.append('0');
for (int i = 0; i < b; i++)
sb.append('1');
for (int i = b; i < n; i++)
sb.append('0');
System.out.println(sa);
System.out.println(sb);
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
5d08a31ae3e9d2022947297c2dca6ddf
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
ArrayList<Integer> s1 = new ArrayList<>();
ArrayList<Integer> s2 = new ArrayList<>();
HashSet<Integer> set = new HashSet<>();
ArrayList<Integer> bb = new ArrayList<>();
int j =0;
for(int i =0;i<n;i++){
int a = s.nextInt();
int b = s.nextInt();
s1.add(a);
s2.add(b);
bb.add(a);
bb.add(b);
j+=2;
}
Collections.sort(bb);
for(int i=0;i<n;i++){
set.add(bb.get(i));
}
for(int i=0;i<n/2;i++){
set.add(s1.get(i));
set.add(s2.get(i));
}
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
for(int i=0;i<n;i++){
if(set.contains(s1.get(i))){
sb1.append(1);
}
else{
sb1.append(0);
}
}
for(int i=0;i<n;i++){
if(set.contains(s2.get(i))){
sb2.append(1);
}
else{
sb2.append(0);
}
}
System.out.println(sb1);
System.out.println(sb2);
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
829de8b1d7f0e47ccc8bbdc1c15dd620
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
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;
/**
*
* @author thachlp
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
List<Integer> boardA = new ArrayList<>();
List<Integer> boardB = new ArrayList<>();
List<Integer> mergeBoard = new ArrayList<>();
Set<Integer> results = new HashSet<>();
for (int i = 0; i < n; i++) {
String[] segment = sc.nextLine().split(" ");
int l = Integer.parseInt(segment[0]);
int r = Integer.parseInt(segment[1]);
boardA.add(l);
boardB.add(r);
mergeBoard.add(l);
mergeBoard.add(r);
}
Collections.sort(mergeBoard);
List<Integer> tmp = new ArrayList<>();
tmp = mergeBoard.subList(0, n);
results.addAll(tmp);
for (int k = 1; n - 2 * k >= 0; k++) {
results.add(boardA.get(k - 1));
results.add(boardB.get(k - 1));
}
StringBuilder s1 = new StringBuilder();
StringBuilder s2 = new StringBuilder();
for (int i = 0; i < n; i++) {
if (results.contains(boardA.get(i))) {
s1.append(1);
} else {
s1.append(0);
}
if (results.contains(boardB.get(i))) {
s2.append(1);
} else {
s2.append(0);
}
}
System.out.println(s1.toString());
System.out.println(s2.toString());
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
f2c578088fd69cd3b4d0004dbb5f101e
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String []arg) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int [] a = new int [n];
int [] b = new int [n];
for(int i = 0 ; i < n; ++ i) {
a[i] = sc.nextInt();
b[i] = sc.nextInt();
}
StringBuilder s1 = new StringBuilder();
StringBuilder s2 = new StringBuilder();
int k =n/2;
for(int i = 0 ; i <k; ++i) {
s1.append("1");
s2.append("1");
}
int aP = 0;
int bP =0 ;
for(int i = 1; i<=n; ++i){
if(a[aP]<b[bP]){
++aP;
}else {
++bP;
}
}
for(int i = s1.length();i <aP; ++ i) {
s1.append("1");
}
for(int i = s1.length();i <n; ++ i) {
s1.append("0");
}
for(int i = s2.length();i <bP; ++ i) {
s2.append("1");
}
for(int i = s2.length();i <n; ++ i) {
s2.append("0");
}
System.out.println(s1);
System.out.println(s2);
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
5a9220a9ff25994f5a6d4c4b0f729435
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.*;
public class JavaApplication {
static int[] stuFirst = new int[100009];
static int[] stuSecond = new int[100009];
static int n;
public static void advancingStudent(ArrayList<Integer> first, ArrayList<Integer> second, int k) {
for (int i = 0; i < k; i++) {
stuFirst[i] = 1;
stuSecond[i] = 1;
}
int count = 0;
int iFirst = k;
int iSecond = k;
int resStu = n - 2*k;
while (count < resStu) {
if (first.get(iFirst) < second.get(iSecond)) {
stuFirst[iFirst] = 1;
iFirst++;
} else {
stuSecond[iSecond] = 1;
iSecond++;
}
count++;
}
}
public static void main(String[] args){
// File file = new File("input.txt");
Scanner scan = new Scanner(System.in);
ArrayList<Integer> first = new ArrayList<>();
ArrayList<Integer> second = new ArrayList<>();
n = scan.nextInt();
for (int i = 0; i < n; i++) {
first.add(scan.nextInt());
second.add(scan.nextInt());
}
advancingStudent(first, second, 0);
advancingStudent(first, second, n / 2);
for (int i = 0; i < n; i++) {
System.out.print(stuFirst[i]);
}
System.out.println();
for (int i = 0; i < n; i++) {
System.out.print(stuSecond[i]);
}
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
387d65b63325c217dc05ecaccb20becd
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int team1[] = new int [n + 7];
int team2[] = new int [n + 7];
for (int i = 1; i <= n; i++) {
team1[i] = in.nextInt();
team2[i] = in.nextInt();
}
for (int i = 1; i <= n; i++) {
if (i <= (n / 2) || team1[i] < team2[n - i + 1]) {
System.out.print("1");
}
else System.out.print("0");
}
System.out.println("");
for (int i = 1; i <= n; i++) {
if (i <= (n / 2) || team2[i] < team1[n - i + 1]) {
System.out.print("1");
}
else System.out.print("0");
}
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
b25160fab9d4b74227d439e75c8aba85
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main extends PrintWriter {
BufferedReader in;
StringTokenizer stok;
final Random rand = new Random(31);
final int inf = (int) 1e9;
final long linf = (long) 1e18;
final static String IO = "_std";
class Item {
int x, id;
public Item(int x, int id) {
this.x = x;
this.id = id;
}
}
void solve() throws IOException {
int n = nextInt();
boolean[][] ans = new boolean[n][2];
Item[] a = new Item[2 * n];
for (int i = 0; i < n; i++) {
a[2 * i] = new Item(nextInt(), i);
a[2 * i + 1] = new Item(nextInt(), -i - 1);
}
Arrays.sort(a, (x, y) -> Integer.compare(x.x, y.x));
for (int i = 0; i < n; i++) {
Item it = a[i];
if (a[i].id >= 0) {
ans[a[i].id][0] = true;
} else {
ans[-a[i].id - 1][1] = true;
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
print((2 * (j + 1) <= n || ans[j][i]) ? "1" : "0");
}
println();
}
}
Main() {
super(System.out);
in = new BufferedReader(new InputStreamReader(System.in));
}
Main(String fileIn, String fileOut) throws IOException {
super(fileOut);
in = new BufferedReader(new FileReader(fileIn));
}
public static void main(String[] args) throws IOException {
Main main;
if ("_std".equals(IO)) {
main = new Main();
} else if ("_iotxt".equals(IO)) {
main = new Main("input.txt", "output.txt");
} else {
main = new Main(IO + ".in", IO + ".out");
}
main.solve();
main.close();
}
String next() throws IOException {
while (stok == null || !stok.hasMoreTokens()) {
String s = in.readLine();
if (s == null) {
return null;
}
stok = new StringTokenizer(s);
}
return stok.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
int[] nextIntArray(int len) throws IOException {
int[] a = new int[len];
for (int i = 0; i < len; i++) {
a[i] = nextInt();
}
return a;
}
int[] nextIntArraySorted(int len) throws IOException {
int[] a = nextIntArray(len);
shuffle(a);
Arrays.sort(a);
return a;
}
void shuffle(int[] a) {
for (int i = 1; i < a.length; i++) {
int x = rand.nextInt(i + 1);
int _ = a[i];
a[i] = a[x];
a[x] = _;
}
}
void shuffleAndSort(int[] a) {
shuffle(a);
Arrays.sort(a);
}
boolean nextPermutation(int[] p) {
for (int a = p.length - 2; a >= 0; --a) {
if (p[a] < p[a + 1])
for (int b = p.length - 1; ; --b)
if (p[b] > p[a]) {
int t = p[a];
p[a] = p[b];
p[b] = t;
for (++a, b = p.length - 1; a < b; ++a, --b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
return true;
}
}
return false;
}
<T> List<T>[] createAdjacencyList(int n) {
List<T>[] res = new List[n];
for (int i = 0; i < n; i++) {
res[i] = new ArrayList<>();
}
return res;
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
cdfbeb8c3d2ee57f2145c09db71d98d5
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.Scanner;
import java.util.ArrayList;
public class B4 {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int n = sc.nextInt();
ArrayList <Integer> a= new ArrayList<Integer>(),b = new ArrayList<Integer>();
for (int i=0;i<n;i++){
int x ,y ;
x = sc.nextInt();
y = sc.nextInt();
a.add(x);
b.add(y);
}
for (int i=0;i<n;i++) {
if ((i+1)<=n/2)
System.out.print(1);
else
if (a.get(i) < b.get(n-i-1))
System.out.print(1);
else
System.out.print(0);
}
System.out.println();
for (int i=0;i<n;i++) {
if ((i+1)<=n/2)
System.out.print(1);
else
if (b.get(i) < a.get(n-i-1))
System.out.print(1);
else
System.out.print(0);
}
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
9522dd580a3849b1232fcf8c1abbaa02
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.util.Scanner;
public class Problem4 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int []a = new int [n];
int []b = new int [n];
int []resA = new int [n];
int []resB = new int [n];
for(int i = 0; i < n; ++i)
resA[i] = resB[i] = 0;
for(int i = 0; i < n; ++i)
{
a[i] = sc.nextInt();
b[i] = sc.nextInt();
}
int i = 0, j = 0;
for(int k = 0; k < n; ++k)
{
if (a[i] < b[j])
resA[i++] = 1;
else
resB[j++] = 1;
}
for(i = 0; i < n/2; ++i)
resA[i] = resB[i] = 1;
for(i = 0; i < n; ++i)
System.out.print(resA[i]);
System.out.print("\n");
for(i = 0; i < n; ++i)
System.out.print(resB[i]);
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
| |
PASSED
|
e31202207872cd41875edecbce792b1b
|
train_001.jsonl
|
1388331000
|
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0ββ€β2kββ€βn) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the nβ-β2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author el-Bishoy
*/
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);
Div2B378_Semifinals solver = new Div2B378_Semifinals();
solver.solve(1, in, out);
out.close();
}
static class Div2B378_Semifinals {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
// ArrayList<Pair> both = new ArrayList<>();
int[] fist = new int[n];
int[] second = new int[n];
int[] results1 = new int[n];
int[] results2 = new int[n];
int N = n / 2;
for (int i = 0; i < n; i++) {
int a = in.nextInt(), b = in.nextInt();
fist[i] = a;
second[i] = b;
// both.add(new Pair(i, a, true));
// both.add(new Pair(i, b, false));
}
int ptr1 = 0, ptr2 = 0;
int idx = 0;
int[] both = new int[n];
while (ptr1 < n && ptr2 < n && idx < n) {
if (fist[ptr1] < second[ptr2]) {
// both[idx++] = fist[ptr1++];
results1[ptr1] = 1;
ptr1++;
} else {
// both[idx++] = second[ptr2++];
results2[ptr2] = 1;
ptr2++;
}
idx++;
}
// for (int i = 0; i < n; i++) {
// Pair p = both.get(i);
// if (p.first) {
// results1[p.idx] = 1;
// } else {
// results2[p.idx] = 1;
// }
//
// }
for (int i = 0; i < N; i++) {
results1[i] = 1;
results2[i] = 1;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(results1[i]);
}
sb.append("\n");
for (int i = 0; i < n; i++) {
sb.append(results2[i]);
}
out.println(sb);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
|
Java
|
["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110"]
|
1 second
|
["1110\n1100", "1100\n1100"]
|
NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090. If kβ=β0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals. If kβ=β1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds). If kβ=β2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.
|
Java 8
|
standard input
|
[
"implementation",
"sortings"
] |
bea30e4ba653b9d0af87fc79b9ec8b4f
|
The first line contains a single integer n (1ββ€βnββ€β105) β the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β109)Β β the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.
| 1,300 |
Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".
|
standard output
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.