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 | f61a2b9213b50dae9202b17434459432 | train_002.jsonl | 1363879800 | Permutation p is an ordered set of integers p1,ββp2,ββ...,ββpn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1,ββp2,ββ...,ββpn.You have a sequence of integers a1,βa2,β...,βan. In one move, you are allowed to decrease or increase any number by one. Count the minimum number of moves, needed to build a permutation from this sequence. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main
{
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] a = new int[n];
long min = 0;
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i = 0; i < n; i++)
a[i] = Integer.parseInt(st.nextToken());
mergeSort(a,0,a.length - 1);
for(int i = 1; i <= n; i++)
if(a[i-1] > i)
min += a[i-1] - i;
else
min += i - a[i-1];
System.out.println(min);
}
static final int INF = Integer.MAX_VALUE;
static void mergeSort(int[] a, int p, int r)
{
if( p < r )
{
int q = (p + r) / 2;
mergeSort(a, p, q);
mergeSort(a, q + 1, r);
merge(a, p, q, r);
}
}
static void merge(int[] a, int p, int q, int r)
{
int n1 = q - p + 1;
int n2 = r - q;
int[] L = new int[n1+1], R = new int[n2+1];
for(int i = 0; i < n1; i++) L[i] = a[p + i];
for(int i = 0; i < n2; i++) R[i] = a[q + 1 + i];
L[n1] = R[n2] = INF;
for(int k = p, i = 0, j = 0; k <= r; k++)
if(L[i] <= R[j])
a[k] = L[i++];
else
a[k] = R[j++];
}
}
| Java | ["2\n3 0", "3\n-1 -1 2"] | 1 second | ["2", "6"] | NoteIn the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2,β1).In the second sample you need 6 moves to build permutation (1,β3,β2). | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 86d5da999415fa75b3ee754a2a28605c | The first line contains integer n (1ββ€βnββ€β3Β·105) β the size of the sought permutation. The second line contains n integers a1,βa2,β...,βan (β-β109ββ€βaiββ€β109). | 1,200 | Print a single number β the minimum number of moves. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | e26579594b80d2c5b20c7787e362136f | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
public class Football {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t;
t = scanner.nextInt();
scanner.nextLine();
int x = 0, y = 0;
String first = null, second = null, temp;
temp = scanner.nextLine();
if (temp != null) {
first=temp;
x = x + 1;
}
for (int i = 0; i < t - 1; i++) {
temp = scanner.nextLine();
if (temp.equals(first)) {
x = x + 1;
} else {
second = temp;
y = y + 1;
}
}
if (x > y) {
System.out.println(first);
} else {
System.out.println(second);
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 3dc69beb54fb0acb61e36f6f87e5a35f | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes |
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Zaid
*/
public class Football {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
int n =s.nextInt();
String team[]=new String [n] ;
int c=0;
int r=0;
String g="";
String gg="";
if(n>=1&&n<=100)
for(int i =0;i<n;i++){
team[i]=s.next();
g=team[0];
if(!g.equals(team[i]))
gg=team[i];
}
if(n==1)
System.out.println(team[0]);
if(n>1){
for(int i =0;i<n;i++){
if(g.equals(team[i]))
{
c++;
}
else if(gg.equals(team[i])
)
r++;
}
if(c>r)
System.out.println(g);;
if(r>c)
System.out.println(gg);
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | fa584cd8245424a0ddca00eda4cac20d | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
public class sa {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
String s=sc.nextLine(),g="";
int a=1,b=0;
for(int i=1;i<n;i++)
{
String sa=sc.nextLine();
if(s.equals(sa))
{
a++;
}
else
{
g=sa;
b++;
}
}
if(a>b)
{
System.out.println(s);
}
else
System.out.println(g);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 5db462871451a3c5f8a948de02c23d56 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.*;
public class whictm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int cnt1 = 0;
int cnt2 = 0;
String first = "";
String sec = "";
int n = Integer.valueOf(sc.nextLine());
while (n > 0) {
String s = sc.nextLine();
if (first.equals("") || s.equals(first)) {
first = s;
cnt1++;
} else {
sec = s;
cnt2++;
}
n--;
}
if (cnt1 > cnt2)
System.out.println(first);
else
System.out.println(sec);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 6643b1693d96c64941a3d31b3faf8192 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Map<String,Integer> map= new HashMap<String,Integer>();
Scanner input= new Scanner(System.in);
int n= input.nextInt();String temp;
for(int i=0;i<n;i++){
temp=input.next();
if(!map.containsKey(temp))
map.put(temp,0);
map.put(temp,map.get(temp)+1);
}
int max=-1;String name,answer="";int score;
for(Map.Entry<String,Integer>e: map.entrySet()){
name=e.getKey();
score=e.getValue();
if(score>max){
max=score;
answer=name;
}
}
System.out.println(answer);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | e6831b438ee5b455648df9b80450a6f4 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
public class Football {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
String a;
String b = "";
int n = cin.nextInt();
int m = 0;
a = cin.next();
m++;
for (int i = 1; i < n; i++) {
String g = cin.next();
if (g.equals(a))
m++;
else
b = g;
}
if (m > (n - m))
System.out.println(a);
else
System.out.println(b);
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | dd1abb08c25e632172e07454a1ff8b14 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.*;
public class F {
public static void main(String[] args) {
Scanner o = new Scanner(System.in);
String[] s = new String[o.nextInt()];
String x = "";
int count = 0;
for (int i = 0; i < s.length; i++)
s[i] = o.next();
Arrays.sort(s);
if (s[0].equals(s[s.length / 2]))
System.out.print(s[0]);
else
System.out.print(s[s.length - 1]);
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 7a451c9fe6fd8e7222101b9742ed459b | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.HashMap;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
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);
OutputWriter out = new OutputWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, InputReader in, OutputWriter out) {
HashMap<String, Integer> hm = new HashMap<>();
int n = in.readInt();
for (int i = 0; i < n; i++) {
String cur = in.next();
if (hm.containsKey(cur)) {
hm.put(cur, hm.get(cur) + 1);
}
else {
hm.put(cur, 1);
}
}
int max = 0;
for (String val : hm.keySet()) {
int cur = hm.get(val);
if (cur > max) max = cur;
}
for (String val : hm.keySet()) {
int cur = hm.get(val);
if (cur == max) {
out.print(val);
return;
}
}
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c))
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
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 String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void close() {
writer.close();
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 88ff4beb69e8bd6aa7018a4747bb549b | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import javax.swing.text.GapContent;
public class Task {
public static void main(String[] args) {
solve();
}
static void solve() {
int n = nextInt();
String firstName = null;
String secondName = null;
int fScore = 0;
int sScore = 0;
for (int i = 0; i < n; ++i) {
String name = nextString();
if (firstName != null && name.equals(firstName)) {
fScore++;
} else if (secondName != null && name.equals(secondName)) {
sScore++;
} else {
if (firstName == null) {
firstName = name;
fScore++;
} else if (secondName == null) {
secondName = name;
sScore++;
}
}
}
System.out.println(fScore > sScore ? firstName : secondName);
}
/************************************************************************************/
static InputStream is = System.in;
static private byte[] buffer = new byte[1024];
static private int lenbuf = 0, ptrbuf = 0;
static private int readByte() {
if (lenbuf == -1)
throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return buffer[ptrbuf++];
}
static private boolean isSpace(int c) {
return !(c >= 33 && c <= 126);
}
static private int read() {
int b;
while ((b = readByte()) != -1 && isSpace(b))
;
return b;
}
static private double nextDouble() {
return Double.parseDouble(nextString());
}
static private char nextChar() {
return (char) read();
}
static private String nextString() {
int b = read();
StringBuilder sb = new StringBuilder();
while (!(isSpace(b))) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
static private char[] nextString(int n) {
char[] buf = new char[n];
int b = read(), p = 0;
while (p < n && !(isSpace(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
static private int nextInt() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
static private long nextLong() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
static private int[] nextAi(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
static private Integer[] nextAi1(int n) {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | f85d09df4c1162b480a6f2bf2bcfdcae | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main
{
public static void main(String ar[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
Hashtable<String,Integer> goal=new Hashtable<String,Integer>();
String teamw="";
int maxg=-1;
for(int i=0;i<n;i++)
{
String t=br.readLine();
if(goal.containsKey(t))
{
int pg=goal.get(t);
goal.put(t,pg+1);
if(pg+1>maxg)
{
teamw=t;
maxg=pg+1;
}
}
else
{
goal.put(t,1);
if(1>maxg)
{
teamw=t;
maxg=1;
}
}
}
System.out.println(teamw);
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | b05f407778a11404d40c2f6cc30b0d7c | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
import java.util.ArrayList;
public class Football{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int l[] = new int[n];
ArrayList<String> s = new ArrayList<String>();
for(int i = 0 ; i < n ; i++){
String temp = in.next();
if(s.indexOf(temp)!=-1)
l[s.indexOf(temp)]++;
else{
s.add(temp);
l[s.indexOf(temp)]++;
}
}
int max = 0 , ind_max = -1 ;
for(int i = 0 ; i < n; i++)
if(l[i]>max){
max = l[i];
ind_max = i;
}
System.out.println(s.get(ind_max));
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 45ce7a4d927cf9d3bd5d5576a37eebfd | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
public class Football{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int l[] = new int[2];
String temp = in.next();
l[0]++;
String temp1 = "";
for(int i = 0 ; i < n - 1 ; i++){
String temp2 = in.next();
if(temp2.equals(temp)==false){
l[1]++;
temp1 = temp2;
}else{
l[0]++;
}
}
if(l[0]>l[1])
System.out.println(temp);
else
System.out.println(temp1);
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 9a6fe7d31d5c13d3a91e95612801259c | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | //package Codeforces.Div2A_42.Code1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
/*
* some cheeky quote
*/
public class Main
{
FastScanner in;
PrintWriter out;
private TreeMap<String, Integer> result = new TreeMap<String, Integer>();
public void solve() throws IOException
{
int n = in.nextInt();
while (n-- > 0)
{
String team = in.next();
if (result.containsKey(team))
{
result.put(team, result.get(team) + 1);
} else
{
result.put(team, 1);
}
}
int max = Integer.MIN_VALUE;
String team = "";
for (Map.Entry<String, Integer> entry : result.entrySet())
{
int temp = entry.getValue();
if (max <= temp)
{
max = temp;
team = entry.getKey();
}
}
System.out.println(team);
}
public void run()
{
try
{
in = new FastScanner();
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
class FastScanner
{
BufferedReader br;
StringTokenizer st;
FastScanner()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreTokens())
{
try
{
st = new StringTokenizer(br.readLine());
} catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
}
public static void main(String[] arg)
{
new Main().run();
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 0d7a721f6f7becb0aa6cbcf6229cd093 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.*;
import java.util.*;
public class Football2 {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(f.readLine());
HashMap<String,Integer> hm = new HashMap<String,Integer>();
for (int i = 0; i < n; i++)
{
String str = f.readLine();
if (hm.containsKey(str))
hm.put(str, hm.get(str)+1);
else
hm.put(str, 1);
}
String name = "";
int max = 0;
Iterator it = hm.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
if ((Integer)(pairs.getValue()) > max)
{
name = (String)(pairs.getKey());
max = (Integer)(pairs.getValue());
}
it.remove();
}
System.out.println(name);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 0c194ef9652afb2e341e800270f1c576 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Iterator;
public class Football {
public static void main(String [] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
HashMap<String, Integer>goals = new HashMap<String, Integer>();
for(int i = 0; i<n; i++){
String s = br.readLine();
if(goals.containsKey(s))
goals.put(s, goals.get(s)+1);
else
goals.put(s, 1);
}
int count = 0;
String ans = "";
Iterator<String>it = goals.keySet().iterator();
while(it.hasNext())
{
String key = it.next();
if(goals.get(key) > count){
ans = key;
count = goals.get(key);
}
}
bw.write(ans);
bw.flush();
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 406e482f48b50a9074336078eb2649ff | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes |
import java.util.Scanner;
/**
*
* @author Haddad
*/
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int x = s.nextInt();
int count = 0;
String a=s.next();
count+=1;
String c = "";
for(int i=0;i<x-1;i++){
String b = s.next();
if(a.equals(b)){
count+=1;
}else{
c=b;
}
}
if(count>x/2){
System.out.println(a);
}else{
System.out.println(c);
}
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | c7067c593e2a672daed4e1de6082fa3a | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.*;
public class Football
{
public static void main(String[] args) throws IOException
{
BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(ob.readLine());
int i;int c1=0,c2=0;String s1=ob.readLine();c1++;String s2="";
for(i=0;i<n-1;i++)
{
String ss=ob.readLine();
if(ss.equals(s1))
{
c1++;
}
else
{
c2++;
s2=ss;
}
}
if(c1>c2)
{
System.out.println(s1);
}
else
{
System.out.println(s2);
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 15eff527768470bd8ee2077033633cb4 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
public class memo{
public static void main (String[]args){
Scanner sc = new Scanner(System.in);
String s=sc.nextLine();
int num=Integer.parseInt(s);
int g1=1;
int g2=0;
String team1;
String team2=null;
team1=sc.nextLine();
if(num==1)System.out.println(team1);
else{
while (num>1) {
String team=sc.nextLine();
if (team.equals(team1)) {
++g1;
--num;
} else {
team2=team;
++g2;
--num;
}
}
if (g1>g2) {
System.out.println(team1);
} else {
System.out.println(team2);
}
}
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 43bccfb04c9ea9af662e625968b5a48c | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String args[] ) throws Exception {
Scanner in = new Scanner(System.in);
int n = in.nextInt(),indexes[]=new int[n],index=0,max=0;
String teams [] = new String [n];
for (int i = 0; i < teams.length; i++)
teams[i]=in.next();
for (int i = 0; i < teams.length; i++) {
if(teams[i]==null)continue;
for (int j = 0; j < teams.length; j++) {
if(i==j)continue;
if(teams[j]!=null)
if(teams[i].equals(teams[j])){
indexes[i]++;
teams[j]=null; } } }
for (int i = 0; i < indexes.length; i++) {
if(indexes[i]>max){
max=indexes[i];
index=i; }}
System.out.println(teams[index]); }}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 7a49eb20a1f1585a521fad487ed0626d | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
/**
*
* @author kai
*/
public class JavaApplication10 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
int n = in.nextInt(), c1 = 0, c2 = 0;
String[] a = new String[n];
for (int i = 0; i < n; i++) {
a[i] = in.next();
}
String s = (a[0] + ""),s2="";
for (int i = 0; i < n; i++) {
if ((a[i]+"").equals(s)) {
c1++;
} else {
s2=a[i]+"";
c2++;
}
}
//System.out.println(c1+""+c2);
if(c1>c2){
System.out.println(s);
}else{
System.out.println(s2);
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 32e839bed9358866e682208f5729c558 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;
/**
*
* @author N203tx
*/
public class main {
/************************ SOLUTION STARTS HERE ************************/
//DONT FORGET TO COMMIT AND PUSH TO GITHUB
private static void solve(FastScanner s1, PrintWriter out){
int n=s1.nextInt();
String a = null,b=null;
int ctr1=0,ctr2=0;
int i=1;
while(i<=n)
{
String s=s1.next();
if(i==1)
{
a=s;
ctr1++;
}
else
{
if(a.equalsIgnoreCase(s))
{
ctr1++;
}
else
{
b=s;
ctr2++;
}
}
i++;
}
if(ctr1>ctr2)
out.println(a);
else
out.println(b);
}
/************************ SOLUTION ENDS HERE ************************/
/************************ TEMPLATE STARTS HERE ************************/
public static void main(String []args) throws IOException {
FastScanner in = new FastScanner(System.in);
PrintWriter out =
new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
solve(in, out);
in.close();
out.close();
}
static class FastScanner{
public BufferedReader reader;
public StringTokenizer st;
public FastScanner(InputStream stream){
reader = new BufferedReader(new InputStreamReader(stream));
st = null;
}
public String next(){
while(st == null || !st.hasMoreTokens()){
try{
String line = reader.readLine();
if(line == null) return null;
st = new StringTokenizer(line);
}catch (Exception e){
throw (new RuntimeException());
}
}
return st.nextToken();
}
public String nextLine(){
String str = null;
try {
str = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
public void close(){
try{ reader.close(); } catch(IOException e){e.printStackTrace();}
}
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
char[][] nextcharArray(int n) {
char[][] arr = new char[n][n];
for (int i = 0; i < n; i++) {
String s=next();
for(int j=0;j<n;j++)
{
arr[i][j]=s.charAt(j);
}
}
return arr;
}
}
/************************ TEMPLATE ENDS HERE ************************/
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | b8e51fd6a89331868e6f3ce6412f11a2 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.*;
public class read {
public static int count=0;
public static int max=0;
public static String win="";
//public static String re="";
public static void main(String[] args) throws Exception {
Scanner input=new Scanner(System.in);
// Scanner input = new Scanner(System.in));
// List<String>list=new ArrayList<String>();
// int num=input.nextInt();
// System.out.println();
// int x=input.nextInt();
int a=input.nextInt();
ArrayList<String>list=new ArrayList<String>();
for(int ii=0;ii<a;ii++)
list.add(input.next());
for(int i=0;i<list.size();i++){
count=0;
String A=String.valueOf(list.get(i));
for(int k=i+1;k<list.size();k++){
if(A.equals(list.get(k))){
count++;
}
}
if(count>max){
max=count;
win=A;
}
}// main
if(a==1)
System.out.println(list.get(0));
else
System.out.println(win);
}} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 0f15503d605e737d1f9e593afdeef809 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
public class A_43_Football {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String sentence[] = new String[n];
sentence[0] = sc.next();
String first = sentence[0];
String second = "";
if (n == 1) {
System.out.println(first);
return;
}
int team1 = 1;
int team2 = 0;
for (int i = 1; i < n; i++) {
sentence[i] = sc.next();
if (first.equals(sentence[i]))
team1++;
else {
second = sentence[i];
team2++;
}
}
if (team1 > team2)
System.out.println(first);
else
System.out.println(second);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | f17f061b8b8c310f5785067335b5d063 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes |
import java.util.Scanner;
public class Football {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n,counter=0,m=0;
n=sc.nextInt();
String[]a=new String[n];
for(int i=0;i<n;i++)
{
a[i]=sc.next();
}
for(int i=0;i<n;i++)
{
if(a[0].compareTo(a[i])==0)
{
counter++;
}
else
{
m=i;
}
}
if(counter>(a.length-counter))
{
System.out.println(a[0]);
}
else
System.out.println(a[m]);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 1614e051eb36e165c473269d1ed40278 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)throws IOException
{
Scanner sc=new Scanner(new java.io.BufferedInputStream(System.in));
int goals=sc.nextInt();
int score=1;
String team1=sc.next();
String team2="";
for(int i=0;i<goals-1;i++)
{
String team=sc.next();
if(team1.equals(team))
{
score +=1;
}
else
team2=team;
}
if((2*score)>goals)
{
System.out.println(team1);
}
else
System.out.println(team2);
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 94ce55e9bf366b29a9e614870d20c3ab | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)throws IOException
{
Scanner sc=new Scanner(new java.io.BufferedInputStream(System.in));
int goals=sc.nextInt();
int score=1;
String team1=sc.next();
String team2="";
for(int i=0;i<goals-1;i++)
{
String team=sc.next();
if(team1.equals(team))
{
score +=1;
}
else
team2=team;
}
if((2*score)>goals)
{
System.out.println(team1);
}
else
System.out.println(team2);
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | e054f2521b86a5d05d51dfc627c3b296 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)throws IOException
{
Scanner sc=new Scanner(new java.io.BufferedInputStream(System.in));
int goals=sc.nextInt();
int score=1;
String team1=sc.next();
String team2="";
for(int i=0;i<goals-1;i++)
{
String team=sc.next();
if(team1.equals(team))
{
score +=1;
}
else
team2=team;
}
if((2*score)>goals)
{
System.out.println(team1);
}
else
System.out.println(team2);
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | b7a5a4f2701b4fb62cfb39dfb890d5f2 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | //package codeforces;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
public class A {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
A() throws IOException {
// reader = new BufferedReader(new FileReader("input.txt"));
// writer = new PrintWriter(new FileWriter("output.txt"));
}
StringTokenizer stringTokenizer;
String next() throws IOException {
while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
stringTokenizer = new StringTokenizer(reader.readLine());
}
return stringTokenizer.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
void solve() throws IOException {
int n = nextInt();
Map<String, Integer> map = new HashMap<>();
for(int i = 0; i < n; i++) {
String s = next();
Integer x = map.get(s);
x = x == null ? 1 : x + 1;
map.put(s, x);
}
String winner = null;
int foo = 0;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if(entry.getValue() > foo) {
foo = entry.getValue();
winner = entry.getKey();
}
}
writer.println(winner);
writer.close();
}
public static void main(String[] args) throws IOException {
new A().solve();
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | e6a7a90e352d053dda45db8d04f113dc | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
public class palin {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt(), res = 1;
String str = scan.next(), str2 = "", temp;
for (int i = 0; i < n - 1; i++) {
temp = scan.next();
if (str.equals(temp)) {
res++;
} else {
str2 = temp;
res--;
}
}
if (res > 0)
System.out.println(str);
else
System.out.println(str2);
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 316158e9688a93fb43ec6146f9cfd068 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class a {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
ArrayList<String> l=new ArrayList<String>();
for(int i=0;i<n;i++)
l.add(sc.next());
Collections.sort(l);
System.out.println(Collections.frequency(l,l.get(0))>Collections.frequency(l,l.get(l.size()-1))?l.get(0):l.get(l.size()-1));
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 7a765954a703271be55cc9b826403ef0 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
public class Football {
public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
int n = sin.nextInt(), count1 = 1;
String a = sin.next(), b = "";
for(int i = 1 ; i < n; i++)
{
String temp = sin.next();
if(temp.equals(a))
count1++;
else
b = temp;
}
if(count1 > n/2)
System.out.println(a);
else
System.out.println(b);
}}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 095b2b4865a44aa88790bd3b1008c7b3 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class A43 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int N = input.nextInt();
Map<String,Integer> map = new HashMap<String,Integer>();
for (int n=0; n<N; n++) {
String team = input.next();
Integer score = map.get(team);
if (score == null) {
score = 1;
} else {
score++;
}
map.put(team, score);
}
int max = 0;
String winner = null;
for (Map.Entry<String,Integer> entry : map.entrySet()) {
int score = entry.getValue();
if (score > max) {
max = score;
winner = entry.getKey();
}
}
System.out.println(winner);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 48a09a4fb33cba7804648161bace30e9 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class a {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
ArrayList<String> l=new ArrayList<String>();
for(int i=0;i<n;i++)
l.add(sc.next());
Collections.sort(l);
System.out.println(Collections.frequency(l,l.get(0))>Collections.frequency(l,l.get(l.size()-1))?l.get(0):l.get(l.size()-1));
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 36b354c5b25dbd6093502b443cea10d7 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes |
import java.util.*;
public class tmp {
public static void main(String [] args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String team1 = scan.next(), team2="";
int s1=1, s2=0;
String s;
for(int i=1; i<n; i++){
s = scan.next();
if(s.equals(team1))
s1++;
else{
if(s2 == 0)
team2 = s;
s2++;
}
}
System.out.println(s1 > s2 ? team1 : team2);
}
}
class Pair implements Comparable<Pair>{
int f,t;
public Pair(int fi, int ti){
f = fi;
t = ti;
}
public int compareTo(Pair p){
return f < p.f ? -1 : f==p.f ? 0 : 1;
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 11b7fa4a1cfec6d69f3cd736b58e35fd | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Reader.init(System.in);
int n=Reader.nextInt();
String s="";
for (int i = 0; i < n; i++)
s+=Reader.reader.readLine()+" ";
{String a[]=s.split(" ");
int f=0,c=0,v=0;
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length; j++) {
if(a[i].equals(a[j]))
{
f++;
}
}
if(f>c)
{
c=f;
v=i;
}
f=0;
}
System.out.println(a[v]);
}
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/**
* call this method to initialize reader for InputStream
*/
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/**
* get next word
*/
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static public void nextIntArrays(int[]... arrays) throws IOException {
for (int i = 1; i < arrays.length; ++i) {
if (arrays[i].length != arrays[0].length) {
throw new InputMismatchException("Lengths are different");
}
}
for (int i = 0; i < arrays[0].length; ++i) {
for (int[] array : arrays) {
array[i] = nextInt();
}
}
}
static public void nextLineArrays(String[]... arrays) throws IOException {
for (int i = 1; i < arrays.length; ++i) {
if (arrays[i].length != arrays[0].length) {
throw new InputMismatchException("Lengths are different");
}
}
for (int i = 0; i < arrays[0].length; ++i) {
for (String[] array : arrays) {
array[i] = reader.readLine();
}
}
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | ea9d30f7c1606b91ea0a250314a3417a | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Set;
public class HelpfulMath {
public static void main(String[] agrs) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
int x = Integer.valueOf(reader.readLine());
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (int i = 0; i < x; i++) {
String string = reader.readLine();
if (map.containsKey(string)) {
map.put(string, map.get(string) + 1);
} else {
map.put(string, 1);
}
}
Set<String> set = map.keySet();
int max = 0;
String string = "";
for (String s : set) {
if (map.get(s) > max) {
max = map.get(s);
string = s;
}
}
System.out.println(string);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 457b86b9d3b0a8d37c1fcd98dbc22e3c | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static String getMax(HashMap<String, Integer> map, String[] a) {
if (a[1] == null) {
return a[0];
} else {
return map.get(a[0]) > map.get(a[1]) ? a[0] : a[1];
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int x = s.nextInt();
HashMap<String, Integer> map = new HashMap<String, Integer>();
int i = 0;
String[] a = new String[2];
while (x-- > 0) {
String string = s.next();
if (map.containsKey(string)) {
int c = map.get(string);
c++;
map.put(string, c);
} else {
map.put(string, 1);
a[i] = string;
i++;
}
}
System.out.println(getMax(map, a));
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 4fe9c47145dcefc0199d6278f16b6ae2 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {
static int current = 0;
public static void updateArray(String[][] arr, String s) {
boolean b = true;
for (int i = 0; i < arr.length; i++) {
if (s.equals(arr[i][0])) {
arr[i][1] = Integer.parseInt(arr[i][1]) + 1 + "";
b = false;
}
}
if (b) {
arr[current][0] = s;
arr[current][1] = 1 + "";
current++;
}
}
public static String getMax(String[][] arr) {
int max = Integer.parseInt(arr[0][1]);
int index = 0;
int x;
for (int i = 0; i < current; i++) {
if ((x = Integer.parseInt(arr[i][1])) > max) {
max = x;
index = i;
}
}
return arr[index][0];
}
public static void main(String[] args) throws NumberFormatException,
IOException {
BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
int x = Integer.parseInt(s.readLine());
String[][] arr = new String[x][2];
while (x-- > 0) {
String str = s.readLine();
updateArray(arr, str);
}
System.out.println(getMax(arr));
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | f792c1d80fbaa8323a93cf70c3676fee | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes |
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Twins
*/
public class Football
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String one ="",two="";int oneint=0,twoint=0;
int t=sc.nextInt();
for (int i = 0; i < t; i++)
{
if (i==0)
{
one=sc.next();
oneint++;
continue;
}
String temp=sc.next();
if (i>0&&one.equals(temp))
{
oneint++;
}
else if (i>0)
{
two=temp;
twoint++;
}
}
if (oneint>twoint)
{
System.out.println(one);
}
else
System.out.println(two);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 79c087d49379778947c158d55b7dac36 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.*;
public class read {
public static int count=0;
public static int max=0;
public static String win="";
//public static String re="";
public static void main(String[] args) throws Exception {
Scanner input=new Scanner(System.in);
// Scanner input = new Scanner(System.in));
// List<String>list=new ArrayList<String>();
// int num=input.nextInt();
// System.out.println();
// int x=input.nextInt();
int a=input.nextInt();
ArrayList<String>list=new ArrayList<String>();
for(int ii=0;ii<a;ii++)
list.add(input.next());
for(int i=0;i<list.size();i++){
count=0;
String A=String.valueOf(list.get(i));
for(int k=i+1;k<list.size();k++){
if(A.equals(list.get(k))){
count++;
}
}
if(count>max){
max=count;
win=A;
}
}// main
if(a==1)
System.out.println(list.get(0));
else
System.out.println(win);
}} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | ad527ccd830799f7f73378e3f086b9f5 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
public class problem43A {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashMap<String, Integer> hash = new HashMap<>();
for(int i=0;i<n;i++){
String str = sc.next();
if(hash.containsKey(str)){
hash.put(str,hash.get(str)+1);
}
else{
hash.put(str, 1);
}
}
Iterator<String> it = hash.keySet().iterator();
int max = -1;
String winner = "";
while(it.hasNext()){
String key = it.next();
if(hash.get(key)>max){
winner = key;
max = hash.get(key);
}
}
System.out.println(winner);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | c9ae878b2b1bd8f721f41f33d232c565 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
public class Main {
public static Scanner leer = new Scanner(System.in);
public static void main(String[] args) {
int n = leer.nextInt();
int p = 0;
String v[] = new String[n];
int ve[] = new int[n];
for (int i = 0; i < n; i++) {
String cadena = leer.next();
if(p >= 1){
for (int j = 0; j < p; j++) {
if(v[j].equals(cadena)){
ve[j]++;
break;
}
else{
if(j == p-1){
v[p] = cadena;
ve[p]++;
p++;
break;
}
}
}
}
else{
v[0] = cadena;
ve[0]++;
p++;
}
}
int k = 0;
for (int i = 1; i < p; i++) {
if(ve[i] > ve[k]){
k = i;
}
}
System.out.println(v[k]);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 66b0ff3254bf5b9acf8c2d75273881c5 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine().trim());
int team1 = 1 ;
int team2 = 0 ;
String t1= br.readLine().trim(),t3, t2 = "";
for (int i =1 ; i < n ; i++ ){
t3=br.readLine().trim();
if (!t3.equals(t1)){
t2= t3;
team2++;
}
else
team1++;
}
// System.out.println (team1);
// System.out.println (team2);
if (team1 > team2)
System.out.println (t1);
else
System.out.println (t2);
} catch (Exception e) {
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | de0e71d26787d5672648e7bb900a0683 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class football {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String[] arr = new String [2];
int num = Integer.parseInt (br.readLine ().trim ());
int count1 = 0 ;
int count2 = 0;
arr[0]= br.readLine ();
count1++;
for (int i = 1 ; i < num ; i++){
String k = br.readLine ();
if (!k.equals(arr[0])){
arr[1]= k ;
count2++;}
else
count1++;
}
if (count1 > count2)
System.out.println (arr[0]);
else
System.out.println (arr[1]);
}
catch (Exception e){
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 3242d320f0eaca7a1f4822a640f02673 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | /* package whatever; // don't place package name! */
import java.io.*;
import java.util.StringTokenizer;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader r = new BufferedReader (new InputStreamReader (System.in));
int n = Integer.parseInt(r.readLine());
String s1="",s2="",s="";
int sc1=0,sc2=0;
s1 = r.readLine();
sc1++;
for(int i=1;i<n;i++){
if(s1.equals(s=r.readLine())){
sc1++;
}
else {
sc2++;
s2=s;
}
}
if(sc1>sc2)
System.out.print(s1);
else
System.out.print(s2);
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 4b7cf94708280bdf8a506dd6683f31b6 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author mohammad
*/
public class football2 {
public static void main(String[] args) {
Scanner m=new Scanner(System.in);
int x=m.nextInt();
String []team=new String[x];
for(int i=0;i<x;i++){
team[i]=m.next();
}
java.util.Arrays.sort(team);
if(team[0].equals(team[team.length/2])){
System.out.println(team[0]);
}
else {
System.out.println(team[team.length/2]);
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 26752d163d4f4739b58d5648bee34f74 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.*;
public class Football{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Hashtable t = new Hashtable();
for(int i = 0; i < n; i++){
String team = scan.next();
if(t.containsKey(team)){
t.put(team, (int) t.get(team) + 1);
}else{
t.put(team, 1);
}
}
int max = 0;
String max_team = "";
Enumeration<String> keys = t.keys();
while(keys.hasMoreElements()){
String key = keys.nextElement();
int score = (int) t.get(key);
if(score > max){
max = score;
max_team = key;
}
}
System.out.println(max_team);
}
} | Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 1c2ea8ea515265442b73bfb2d6c8016c | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.*;
import java.util.*;
public class anotherFootball {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String aux;
int n = Integer.parseInt(br.readLine());
String word = br.readLine();
String word2 = "";
int cnt1 = 1, cnt2 = 0;
for (int i = 0; i < n-1; i++) {
aux = br.readLine();
if(aux.equals(word)) cnt1++;
else {
word2 = aux;
cnt2++;
}
}
if(cnt1 > cnt2) System.out.println(word);
else System.out.println(word2);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 3eb6e2fb5d7327f8625559d64e79b41b | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 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 invisible
*/
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);
FootBall solver = new FootBall();
solver.solve(1, in, out);
out.close();
}
static class FootBall {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.readInt();
String s[] = new String[n];
for (int i = 0; i < n; i++) {
s[i] = in.readLine();
}
String ans = "";
int max = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
int temp = 0;
for (int j = 0; j < n; j++) {
if (s[i].equals(s[j]))
temp++;
}
if (temp > max) {
max = temp;
ans = s[i];
}
}
out.printLine(ans);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
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 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;
}
private String readLine0() {
StringBuilder buf = new StringBuilder();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r')
buf.appendCodePoint(c);
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0)
s = readLine0();
return s;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 226a6962356e74975e097150586d71b4 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author invisible
*/
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);
FootBall solver = new FootBall();
solver.solve(1, in, out);
out.close();
}
static class FootBall {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.readInt();
String s[] = new String[n];
for (int i = 0; i < n; i++) {
s[i] = in.readLine();
}
String ans = "";
int count = 1;
int max = Integer.MIN_VALUE;
Arrays.sort(s);
for (int i = 0; i < s.length - 1; i++) {
if (s[i].equals(s[i + 1]))
count++;
else {
if (count > max) {
max = count;
ans = s[i];
// System.out.println(count);
count = 1;
}
}
}
if (s.length >= 2 && s[n - 1].equals(s[n - 2]))
if (count > max) {
max = count;
ans = s[n - 1];
// System.out.println(count);
count = 1;
}
out.printLine(s.length == 1 ? s[0] : ans);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
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 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;
}
private String readLine0() {
StringBuilder buf = new StringBuilder();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r')
buf.appendCodePoint(c);
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0)
s = readLine0();
return s;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 85385dd82bd8fccfe60830853c765313 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.Set;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author invisible
*/
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);
FootBall solver = new FootBall();
solver.solve(1, in, out);
out.close();
}
static class FootBall {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.readInt();
String s[] = new String[n];
Map<String, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
String val = in.readLine();
if (!map.containsKey(val)) {
map.put(val, 1);
} else {
map.put(val, map.get(val
) + 1);
}
}
String ans = "";
int max = Integer.MIN_VALUE;
Iterator<String> key = map.keySet().iterator();
while (key.hasNext()) {
String temp = key.next();
if (map.get(temp) > max) {
ans = temp;
max = map.get(temp);
}
}
out.printLine(ans);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
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 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;
}
private String readLine0() {
StringBuilder buf = new StringBuilder();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r')
buf.appendCodePoint(c);
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0)
s = readLine0();
return s;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | cefdb277b6171a81d34100e3729a4dfb | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes |
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String tab[]= new String[n];
for(int i=0;i<n;i++)
tab[i]=sc.next();
int a1=1,a2=0;
String equ2="";
for(int i=1;i<n;i++)
if(tab[i].equals(tab[0]))
a1++;
else {
a2++;
equ2=tab[i];
}
if(a1>a2)
System.out.println(tab[0]);
else if (a1<a2)
System.out.println(equ2);
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | 276025f7cc0e291f156b1eceee1feed7 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int goals = Integer.parseInt(br.readLine());
int a = 0;
String teamA = "";
int b = 0;
String teamB = "";
for(int i = 0;i < goals;i++){
String scorer = br.readLine();
if(teamA == ""){
teamA = scorer;
} else if(teamB == "" && !teamA.equals(scorer)){
teamB = scorer;
}
if(teamA.equals(scorer))
a++;
}
if(a >= 0.5*goals){
System.out.println(teamA);
}else{
System.out.println(teamB);
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | eca46975e025b55ea4a88383386e2827 | train_002.jsonl | 1291046400 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | 256 megabytes | import java.util.Scanner;
public class Football2
{
public static void main(String[] args)
{
Scanner cs = new Scanner(System.in) ;
short line = cs.nextShort() ;
String [] arr = new String[line] ;
short farst = 0 ;
short scend = 0 ;
for (int i = 0; i < line; i++)
{
arr[i] = cs.next() ;
}
String s1 = "";
String s = arr[0] ;
for (int i = 0; i < line; i++)
{
if(arr[i].equals(s))
{
farst ++ ;
}
else
{
s1 = arr[i] ;
scend ++ ;
}
}
if(farst > scend)
{
System.out.println(s);
}
else
{
System.out.println(s1);
}
}
}
| Java | ["1\nABC", "5\nA\nABA\nABA\nA\nA"] | 2 seconds | ["ABC", "A"] | null | Java 7 | standard input | [
"strings"
] | e3dcb1cf2186bf7e67fd8da20c1242a9 | The first line contains an integer n (1ββ€βnββ€β100) β the number of lines in the description. Then follow n lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | 1,000 | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | standard output | |
PASSED | bb4ed861579e400f4991207a9c4e4311 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.io.*;
import java.util.*;
public class Manikya {
BufferedReader br;
PrintWriter out;
void solve() {
int t = ni();
while(t-- > 0) {
int n = ni();
PriorityQueue<Integer> pq = new PriorityQueue<Integer>(Collections.reverseOrder());
for(int i = 0; i < n; i++) {
pq.add(ni());
}
int curr = 1;
int prev = 0;
// out.println(pq);
while(!pq.isEmpty()) {
//removing zeroes
while(pq.peek() == 0 && !pq.isEmpty()) pq.poll();
if(pq.isEmpty()) break;
int c = pq.poll();
if(prev != 0 ) pq.offer(prev);
prev = c-1;
curr = (curr+1)%2;
// //Check for values
// out.println("queue: " + pq + " curr: " + curr + "prev: " + prev);
}
if(curr == 0) out.println("T");
else out.println("HL");
}
}
// -------- I/O Template -------------
char nc() {
return ns().charAt(0);
}
String nLine() {
try {
return br.readLine();
} catch(IOException e) {
return "-1";
}
}
double nd() {
return Double.parseDouble(ns());
}
long nl() {
return Long.parseLong(ns());
}
int ni() {
return Integer.parseInt(ns());
}
StringTokenizer ip;
String ns() {
if(ip == null || !ip.hasMoreTokens()) {
try {
ip = new StringTokenizer(br.readLine());
} catch(IOException e) {
throw new InputMismatchException();
}
}
return ip.nextToken();
}
void run() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.flush();
}
public static void main(String[] args) {
new Manikya().run();
}
} | Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 2b0df97b67084f4da0c7c31b7a6b2096 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.io.*;
public class StonedGames {
public static void main(String []args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
for(int i=0;i<n;i++){
int arr_length = Integer.parseInt(br.readLine());
String []arr = br.readLine().split(" ");
int []input_arr = new int[arr_length];
int largest_element = 0;
int sum_arr = 0;
for(int j=0;j<arr_length;j++){
input_arr[j] = Integer.parseInt(arr[j]);
largest_element = Math.max(largest_element, input_arr[j]);
sum_arr += input_arr[j];
}
if(largest_element > sum_arr - largest_element){
System.out.println("T");
} else if(sum_arr%2==0){
System.out.println("HL");
} else {
System.out.println("T");
}
}
}
}
| Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 05ac3c99921db61c1b7517b5ef1990f2 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) {
Problems problems = new Problems();
problems.solve();
}
}
class Problems {
Parser parser = new Parser();
void solve() {
int t = parser.parseInt();
for (int i = 0; i < t; i++) {
Problem problem = new Problem();
problem.solve(i);
}
}
class Problem {
void solve(int testcase) {
int n = parser.parseInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = parser.parseInt();
}
if (n == 1) {
System.out.println("T");
return;
}
Arrays.sort(a);
int sum = 0;
for (int i = 0; i < n - 1; i++) {
sum += a[i];
}
if (sum < a[n - 1]) {
System.out.println("T");
return;
}
if((sum + a[n - 1]) % 2 == 1) {
System.out.println("T");
return;
}
System.out.println("HL");
}
}
}
class Parser {
private final Iterator<String> stringIterator;
private final Deque<String> inputs;
Parser() {
this(System.in);
}
Parser(InputStream in) {
BufferedReader br = new BufferedReader(new InputStreamReader(in));
stringIterator = br.lines().iterator();
inputs = new ArrayDeque<>();
}
void fill() {
while (inputs.isEmpty()) {
if (!stringIterator.hasNext()) throw new NoSuchElementException();
inputs.addAll(Arrays.asList(stringIterator.next().split(" ")));
while (!inputs.isEmpty() && inputs.getFirst().isEmpty()) {
inputs.removeFirst();
}
}
}
Integer parseInt() {
fill();
if (!inputs.isEmpty()) {
return Integer.parseInt(inputs.pollFirst());
}
throw new NoSuchElementException();
}
Long parseLong() {
fill();
if (!inputs.isEmpty()) {
return Long.parseLong(inputs.pollFirst());
}
throw new NoSuchElementException();
}
Double parseDouble() {
fill();
if (!inputs.isEmpty()) {
return Double.parseDouble(inputs.pollFirst());
}
throw new NoSuchElementException();
}
String parseString() {
fill();
return inputs.removeFirst();
}
} | Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 7673d5e937d92794b96bcebd7e9955a6 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | /*
Author: Anthony Ngene
Created: 31/08/2020 - 06:38
*/
import java.io.*;
import java.util.*;
public class D {
// Do not take life too seriously. You will never get out of it alive. - Elbert Hubbard
public static void main(String[] args) throws IOException {
in = new FastScanner();
int cases = in.intNext();
for (int t = 1; t <= cases; t++) {
int n = in.intNext();
int[] arr = in.nextIntArray(n);
boolean firstWins = false;
int total = sum(arr);
int half = total / 2;
for (int i = 0; i < n; i++)
if (arr[i] > half) {
firstWins = true;
break;
}
if (!firstWins)
firstWins = (total % 2 == 1);
out.println(firstWins ? "T" : "HL");
}
out.close();
}
// checks: 1. edge cases 2. overflow 3. possible errors (e.g 1/0, arr[out]) 4. time/space complexity
// Generated Code Below:
private static final FastWriter out = new FastWriter();
private static FastScanner in;
static ArrayList<Integer>[] adj;
private static long e97 = (long)1e9 + 7;
static class FastWriter {
private static final int IO_BUFFERS = 128 * 1024;
private final StringBuilder out;
public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
public FastWriter p(Object object) { out.append(object); return this; }
public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public FastWriter pp(int[] args) { for (int ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public FastWriter pp(long[] args) { for (long ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public FastWriter pp(char[] args) { for (char ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public void println(long[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
public void println(int[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
public void println(char[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
public void println(double[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
public void println(boolean[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
public <T>void println(T[] arr) { out.append(Arrays.toString(arr)).append("\n"); }
public void println(long[][] arr) { for (long[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public void println(int[][] arr) { for (int[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public void println(char[][] arr) { for (char[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public void println(double[][] arr) { for (double[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public <T>void println(T[][] arr) { for (T[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
public void toFile(String fileName) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
writer.write(out.toString());
writer.close();
}
public void close() throws IOException { System.out.print(out); }
}
static class FastScanner {
private InputStream sin = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
public FastScanner(){}
public FastScanner(String filename) throws FileNotFoundException {
File file = new File(filename);
sin = new FileInputStream(file);
}
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}else{
ptr = 0;
try {
buflen = sin.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long longNext() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b) || b == ':'){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
public int intNext() {
long nl = longNext();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public double doubleNext() { return Double.parseDouble(next());}
public long[] nextLongArray(final int n){
final long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = longNext();
return a;
}
public int[] nextIntArray(final int n){
final int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = intNext();
return a;
}
public double[] nextDoubleArray(final int n){
final double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = doubleNext();
return a;
}
public ArrayList<Integer>[] getAdj(int n) {
ArrayList<Integer>[] adj = new ArrayList[n + 1];
for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
return adj;
}
public ArrayList<Integer>[] adjacencyList(int nodes, int edges) throws IOException {
return adjacencyList(nodes, edges, false);
}
public ArrayList<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException {
adj = getAdj(nodes);
for (int i = 0; i < edges; i++) {
int a = intNext(), b = intNext();
adj[a].add(b);
if (!isDirected) adj[b].add(a);
}
return adj;
}
}
private static int sum(int... ins){ int total = 0; for (int v : ins) { total += v; } return total; }
}
| Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 66a29424d383116aec6888b223d0f471 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.util.*;
import java.io.*;
public class A {
static FastReader f = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
int t = f.nextInt();
while(t-- > 0) {
solve();
}
out.close();
}
static void solve() {
int n = f.nextInt();
PriorityQueue<Integer> pri = new PriorityQueue<>();
int p1 = 0, p2 = 0;
for(int i=0;i<n;i++) {
pri.add(-f.nextInt());
}
while(true) {
if(p1 == 0) {
if(pri.isEmpty()) {
out.println("HL");
return;
}
p1 = -pri.poll();
}
if(!pri.isEmpty() && p1 < -pri.peek()) {
int loc = p1;
p1 = -pri.poll();
pri.add(-loc);
}
p1--;
if(p2 == 0) {
if(pri.isEmpty()) {
out.println("T");
return;
}
p2 = -pri.poll();
}
if(!pri.isEmpty() && p2 < -pri.peek()) {
int loc = p2;
p2 = -pri.poll();
pri.add(-loc);
}
p2--;
}
}
static class FastReader {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String next() {
while(st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch(IOException ioe) {
ioe.printStackTrace();
}
return s;
}
int nextInt() {
return Integer.parseInt(next());
}
}
} | Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 41dd02bcf76df4ce43186220cddce4e6 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | /******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int[] arr = new int[n];
int sum=0;
int max=0;
for(int i=0;i<n;i++){
arr[i] =sc.nextInt();
sum+=arr[i];
max = (int)Math.max(max,arr[i]);
}
Arrays.sort(arr);
if(n==1){
System.out.println('T');
}
else if(n==2){
if(arr[0]!=arr[1]){
System.out.println('T');
}
else{
System.out.println("HL");
}
}
else{
if(sum%2!=0 || max>sum-max){
System.out.println('T');
}
else{
System.out.println("HL");
}
}
}
}
}
| Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | ed13d07579794b57d4b8fc480464f049 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Main {
static ArrayList<Integer> adj[];
static PrintWriter out = new PrintWriter(System.out);
public static long mod;
static int [][]notmemo;
static int k;
static int[] a;
static int b[];
static int m;
static class Pair {
int u ;int v;
public Pair(int a1,int a2) {
u=a1;
v=a2;
}
}
static Pair s1[];
static int s;
static ArrayList<Pair> adjlist[];
static char c[][];
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int a[]=new int[n];
PriorityQueue<Integer> pq=new PriorityQueue<>(Collections.reverseOrder());
int sum=0;
for (int i = 0; i < a.length; i++) {
a[i]=sc.nextInt();
sum+=a[i];
pq.add(a[i]);
}
boolean f=true;
int old1=0;
int old2=0;
while(!pq.isEmpty()) {
if(f) {
int x=pq.poll();
old1=x-1;
if(old2>0)
pq.add(old2);
if(pq.size()==0&&f) {
System.out.println("T");
break;
}
}
else {
int x=pq.poll();
old2=x-1;
if(old1>0)
pq.add(old1);
}
if(pq.size()==0&&!f) {
System.out.println("HL");
break;
}
f=!f;
}
}
}
static long[][] memo;
static long dp(int idx,int sum) {
if(idx==n) {
return sum==s? 1:0;
}
if(sum==s) {
return (2*dp(idx+1,sum)%modmod);
}
if(sum>s) {
return 0;
}
if(memo[idx][sum]!=-1)
return memo[idx][sum];
long leave=0;
leave+=(2*dp(idx+1,sum)%modmod);
leave%=modmod;
long take=0;
take+=dp(idx+1,sum+a[idx]);
take%=modmod;
return memo[idx][sum]=((take+leave)%modmod);
}
static long modmod=998244353;
static int dx[]= {1,-1,0,0};
static int dy[]= {0,0,1,-1};
static boolean flood(int x,int y) {
if(x<0||x>=n||y<0||y>=m||c[x][y]=='#') {
return false;
}
return true;
}
static class BBOOK implements Comparable<BBOOK>{
int t;
int alice;
int bob;
public BBOOK(int x,int y,int z) {
t=x;
alice=y;
bob=z;
}
@Override
public int compareTo(BBOOK o) {
return this.t-o.t;
}
}
static boolean longvis[][];
static int reali,realj;
static char curchar;
private static int lcm(int a2, int b2) {
return (a2*b2)/gcd(a2,b2);
}
static boolean visit[][];
static Boolean zero[][];
static int small[];
static int idx=0;
static long dpdp[][][][];
static int modd=(int) 1e8;
static class Edge implements Comparable<Edge>
{
int node;long cost;
Edge(int a, long b) { node = a; cost = b; }
public int compareTo(Edge e){ return Long.compare(cost,e.cost); }
}
static void sieve(int N) // O(N log log N)
{
isComposite = new int[N+1];
isComposite[0] = isComposite[1] = 1; // 0 indicates a prime number
primes = new ArrayList<Integer>();
for (int i = 2; i <= N; ++i) //can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
if (isComposite[i] == 0) //can loop in 2 and odd integers for slightly better performance
{
primes.add(i);
if(1l * i * i <= N)
for (int j = i * i; j <= N; j += i) // j = i * 2 will not affect performance too much, may alter in modified sieve
isComposite[j] = 1;
}
}
static TreeSet<Integer> factors;
static ArrayList<Integer> primeFactors(int N) // O(sqrt(N) / ln sqrt(N))
{
ArrayList<Integer> factors = new ArrayList<Integer>(); //take abs(N) in case of -ve integers
int idx = 0, p = primes.get(idx);
while(1l*p * p <= N)
{
while(N % p == 0) { factors.add(p); N /= p; }
p = primes.get(++idx);
}
if(N != 1) // last prime factor may be > sqrt(N)
factors.add(N); // for integers whose largest prime factor has a power of 1
return factors;
}
static String y;
static int nomnom[];
static long fac[];
static boolean f = true;
static class SegmentTree { // 1-based DS, OOP
int N; // the number of elements in the array as a power of 2 (i.e. after padding)
int[] array, sTree, lazy;
SegmentTree(int[] in) {
array = in;
N = in.length - 1;
sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
lazy = new int[N << 1];
//build(1, 1, N);
}
void build(int node, int b, int e) // O(n)
{
if (b == e)
sTree[node] = array[b];
else {
int mid = b + e >> 1;
build(node << 1, b, mid);
build(node << 1 | 1, mid + 1, e);
sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
}
}
void update_point(int index, int val) // O(log n)
{
index += N - 1;
sTree[index] = val;
while(index>1)
{
index >>= 1;
sTree[index] = Math.max(sTree[index<<1] ,sTree[index<<1|1]);
}
}
void update_range(int i, int j, int val) // O(log n)
{
update_range(1, 1, N, i, j, val);
}
void update_range(int node, int b, int e, int i, int j, int val) {
if (i > e || j < b)
return;
if (b >= i && e <= j) {
sTree[node] += (e - b + 1) * val;
lazy[node] += val;
} else {
int mid = b + e >> 1;
propagate(node, b, mid, e);
update_range(node << 1, b, mid, i, j, val);
update_range(node << 1 | 1, mid + 1, e, i, j, val);
sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
}
}
void propagate(int node, int b, int mid, int e) {
lazy[node << 1] += lazy[node];
lazy[node << 1 | 1] += lazy[node];
sTree[node << 1] += (mid - b + 1) * lazy[node];
sTree[node << 1 | 1] += (e - mid) * lazy[node];
lazy[node] = 0;
}
int query(int i, int j) {
return query(1, 1, N, i, j);
}
int query(int node, int b, int e, int i, int j) // O(log n)
{
if (i > e || j < b)
return 0;
if (b >= i && e <= j)
return sTree[node];
int mid = b + e >> 1;
// propagate(node, b, mid, e);
int q1 = query(node << 1, b, mid, i, j);
int q2 = query(node << 1 | 1, mid + 1, e, i, j);
return Math.max(q1,q2);
}
}
static class UnionFind {
int[] p, rank, setSize;
int numSets;
int max[];
public UnionFind(int N) {
p = new int[numSets = N];
rank = new int[N];
setSize = new int[N];
for (int i = 0; i < N; i++) {
p[i] = i;
setSize[i] = 1;
}
}
public int findSet(int i) {
return p[i] == i ? i : (p[i] = findSet(p[i]));
}
public boolean isSameSet(int i, int j) {
return findSet(i) == findSet(j);
}
public int chunion(int i,int j, int x2) {
if (isSameSet(i, j))
return 0;
numSets--;
int x = findSet(i), y = findSet(j);
int z=findSet(x2);
p[x]=z;;
p[y]=z;
return x;
}
public void unionSet(int i, int j) {
if (isSameSet(i, j))
return;
numSets--;
int x = findSet(i), y = findSet(j);
if (rank[x] > rank[y]) {
p[y] = x;
setSize[x] += setSize[y];
} else {
p[x] = y;
setSize[y] += setSize[x];
if (rank[x] == rank[y])
rank[y]++;
}
}
public int numDisjointSets() {
return numSets;
}
public int sizeOfSet(int i) {
return setSize[findSet(i)];
}
}
/**
* private static void trace(int i, int time) { if(i==n) return;
*
*
* long ans=dp(i,time);
* if(time+a[i].t<a[i].burn&&(ans==dp(i+1,time+a[i].t)+a[i].cost)) {
*
* trace(i+1, time+a[i].t);
*
* l1.add(a[i].idx); return; } trace(i+1,time);
*
* }
**/
static class incpair implements Comparable<incpair> {
int a;
long b;
int idx;
incpair(int a, long dirg, int i) {
this.a = a;
b = dirg;
idx = i;
}
public int compareTo(incpair e) {
return (int) (b - e.b);
}
}
static class decpair implements Comparable<decpair> {
int a;
long b;
int idx;
decpair(int a, long dirg, int i) {
this.a = a;
b = dirg;
idx = i;
}
public int compareTo(decpair e) {
return (int) (e.b - b);
}
}
static long allpowers[];
static class Quad implements Comparable<Quad> {
int u;
int v;
char state;
int turns;
public Quad(int i, int j, char c, int k) {
u = i;
v = j;
state = c;
turns = k;
}
public int compareTo(Quad e) {
return (int) (turns - e.turns);
}
}
static long dirg[][];
static Edge[] driver;
static int n;
static long manhatandistance(long x, long x2, long y, long y2) {
return Math.abs(x - x2) + Math.abs(y - y2);
}
static long fib[];
static long fib(int n) {
if (n == 1 || n == 0) {
return 1;
}
if (fib[n] != -1) {
return fib[n];
} else
return fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);
}
static class Point implements Comparable<Point>{
long x, y;
Point(long counth, long counts) {
x = counth;
y = counts;
}
@Override
public int compareTo(Point p )
{
return Long.compare(p.y*1l*x, p.x*1l*y);
}
}
static long[][] comb;
static class Triple implements Comparable<Triple> {
int l;
int r;
long cost;
int idx;
public Triple(int a, int b, long l1, int l2) {
l = a;
r = b;
cost = l1;
idx = l2;
}
public int compareTo(Triple x) {
if (l != x.l || idx == x.idx)
return l - x.l;
return -idx;
}
}
static TreeSet<Long> primeFactors(long N) // O(sqrt(N) / ln sqrt(N))
{
TreeSet<Long> factors = new TreeSet<Long>(); // take abs(N) in case of -ve integers
int idx = 0, p = primes.get(idx);
while (p * p <= N) {
while (N % p == 0) {
factors.add((long) p);
N /= p;
}
if (primes.size() > idx + 1)
p = primes.get(++idx);
else
break;
}
if (N != 1) // last prime factor may be > sqrt(N)
factors.add(N); // for integers whose largest prime factor has a power of 1
return factors;
}
static boolean visited[];
/**
* static int bfs(int s) { Queue<Integer> q = new LinkedList<Integer>();
* q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;
* while(!q.isEmpty()) {
*
* int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {
* maxcost=Math.max(maxcost, v.cost);
*
*
*
* if(!visited[v.v]) {
*
* visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,
* v.cost); } }
*
* } return maxcost; }
**/
public static boolean FindAllElements(int n, int k) {
int sum = k;
int[] A = new int[k];
Arrays.fill(A, 0, k, 1);
for (int i = k - 1; i >= 0; --i) {
while (sum + A[i] <= n) {
sum += A[i];
A[i] *= 2;
}
}
if (sum == n) {
return true;
} else
return false;
}
static boolean[] vis2;
static boolean f2 = false;
static long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x
// r)
{
long[][] C = new long[p][r];
for (int i = 0; i < p; ++i) {
for (int j = 0; j < r; ++j) {
for (int k = 0; k < q; ++k) {
C[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;
C[i][j] %= mod;
}
}
}
return C;
}
public static int[] schuffle(int[] a2) {
for (int i = 0; i < a2.length; i++) {
int x = (int) (Math.random() * a2.length);
int temp = a2[x];
a2[x] = a2[i];
a2[i] = temp;
}
return a2;
}
static int memo1[];
static boolean vis[];
static TreeSet<Integer> set = new TreeSet<Integer>();
static long modPow(long ways, long count, long mod) // O(log e)
{
ways %= mod;
long res = 1;
while (count > 0) {
if ((count & 1) == 1)
res = (res * ways) % mod;
ways = (ways * ways) % mod;
count >>= 1;
}
return res % mod;
}
static int gcd(int ans, int b) {
if (b == 0) {
return ans;
}
return gcd(b, ans % b);
}
static int[] isComposite;
static int[] valid;
static ArrayList<Integer> primes;
static ArrayList<Integer> l1;
static TreeSet<Integer> primus = new TreeSet<Integer>();
static void sieveLinear(int N)
{
int[] lp = new int[N + 1]; //lp[i] = least prime divisor of i
for(int i = 2; i <= N; ++i)
{
if(lp[i] == 0)
{
primus.add(i);
lp[i] = i;
}
int curLP = lp[i];
for(int p: primus)
if(p > curLP || p * i > N)
break;
else
lp[p * i] = i;
}
}
public static long[] schuffle(long[] a2) {
for (int i = 0; i < a2.length; i++) {
int x = (int) (Math.random() * a2.length);
long temp = a2[x];
a2[x] = a2[i];
a2[i] = temp;
}
return a2;
}
static int V;
static long INF = (long) 1E16;
static class Edge2 {
int node;
long cost;
long next;
Edge2(int a, int c, Long long1) {
node = a;
cost = long1;
next = c;
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public Scanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
public int[] nxtArr(int n) throws IOException {
int[] ans = new int[n];
for (int i = 0; i < n; i++)
ans[i] = nextInt();
return ans;
}
}
public static int[] sortarray(int a[]) {
schuffle(a);
Arrays.sort(a);
return a;
}
public static long[] sortarray(long a[]) {
schuffle(a);
Arrays.sort(a);
return a;
}
}
| Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 93750fdd603238baa186bb7750ac1d84 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.io.*;
import java.util.*;
public class d2666 implements Runnable
{
private boolean console=false;
public void solve()
{
int i;
int n=in.ni();
int a[]=new int[n];
int v=0;
for(i=0;i<n;i++)
{
a[i]=in.ni();
v+=a[i];
}
if(n==1)
{
out.println("T");
return;
}
else if(n==2)
{
if(a[0]==a[1])
out.println("HL");
else
out.println("T");
}
else
{
int l=0;
for(i=0;i<n;i++)
if(a[i]>l)
l=a[i];
int p=v-l;
if(v%2!=0||l>p)
out.println("T");
else
out.println("HL");
}
}
@Override
public void run() {
try { init(); }
catch (FileNotFoundException e) { e.printStackTrace(); }
int t= in.ni();
while (t-->0) {
solve();
out.flush(); }
}
private FastInput in; private PrintWriter out;
public static void main(String[] args) throws Exception { new d2666().run(); }
private void init() throws FileNotFoundException {
InputStream inputStream = System.in; OutputStream outputStream = System.out;
try { if (!console && System.getProperty("user.name").equals("sachan")) {
outputStream = new FileOutputStream("/home/sachan/Desktop/output.txt");
inputStream = new FileInputStream("/home/sachan/Desktop/input.txt"); }
} catch (Exception ignored) { }
out = new PrintWriter(outputStream); in = new FastInput(inputStream);
}
static class FastInput { InputStream obj;
public FastInput(InputStream obj) { this.obj = obj; }
byte inbuffer[] = new byte[1024]; int lenbuffer = 0, ptrbuffer = 0;
int readByte() { if (lenbuffer == -1) throw new InputMismatchException();
if (ptrbuffer >= lenbuffer) { ptrbuffer = 0;
try { lenbuffer = obj.read(inbuffer); }
catch (IOException e) { throw new InputMismatchException(); } }
if (lenbuffer <= 0) return -1;return inbuffer[ptrbuffer++]; }
String ns() { int b = skip();StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { sb.appendCodePoint(b);b = readByte(); }return sb.toString();}
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(); }}
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 * 10L + (b - '0'); } else {
return minus ? -num : num; }b = readByte(); } }
boolean isSpaceChar(int c) { return (!(c >= 33 && c <= 126)); }
int skip() { int b;while ((b = readByte()) != -1 && isSpaceChar(b)) ;return b; }
float nf() {return Float.parseFloat(ns());}
double nd() {return Double.parseDouble(ns());}
char nc() {return (char) skip();}
}
}
| Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 83e1a9608831f17adea1dc03f5a15ef7 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Main {
private static final boolean N_CASE = true;
private void solve() {
int n = sc.nextInt();
int[] a = sc.nextIntArray(n);
if (n == 1) {
out.println("T");
return;
}
int sum = 0;
int max = 0;
for (int v : a) {
sum += v;
max = Math.max(v, max);
}
out.println(max > sum - max || sum % 2 == 1 ? "T" : "HL");
}
private void run() {
int T = N_CASE ? sc.nextInt() : 1;
for (int t = 0; t < T; ++t) {
solve();
}
}
private static MyWriter out;
private static MyScanner sc;
private static class MyScanner {
BufferedReader br;
StringTokenizer st;
private 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());
}
int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
int[][] nextIntArray(int n, int m) {
int[][] a = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = sc.nextInt();
}
}
return a;
}
long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
long[][] nextLongArray(int n, int m) {
long[][] a = new long[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = nextLong();
}
}
return a;
}
List<Integer> nextList(int n) {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
list.add(nextInt());
}
return list;
}
List<Long> nextLongList(int n) {
List<Long> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
list.add(nextLong());
}
return list;
}
char[] nextCharArray(int n) {
return sc.next().toCharArray();
}
char[][] nextCharArray(int n, int m) {
char[][] c = new char[n][m];
for (int i = 0; i < n; i++) {
String s = sc.next();
for (int j = 0; j < m; j++) {
c[i][j] = s.charAt(j);
}
}
return c;
}
}
private static class MyWriter extends PrintWriter {
private MyWriter(OutputStream outputStream) {
super(outputStream);
}
void printArray(int[] a) {
for (int i = 0; i < a.length; ++i) {
print(a[i]);
print(i == a.length - 1 ? '\n' : ' ');
}
}
void printArray(long[] a) {
for (int i = 0; i < a.length; ++i) {
print(a[i]);
print(i == a.length - 1 ? '\n' : ' ');
}
}
void println(int[] a) {
for (int v : a) {
println(v);
}
}
void print(List<Integer> list) {
for (int i = 0; i < list.size(); ++i) {
print(list.get(i));
print(i == list.size() - 1 ? '\n' : ' ');
}
}
void println(List<Integer> list) {
list.forEach(this::println);
}
}
private <T> List<List<T>> createGraph(int n) {
List<List<T>> g = new ArrayList<>();
for (int i = 0; i < n; ++i) {
g.add(new ArrayList<>());
}
return g;
}
private void fill(int[][] a, int value) {
for (int[] row : a) {
fill(row, value);
}
}
private void fill(int[] a, int value) {
Arrays.fill(a, value);
}
public static void main(String[] args) {
out = new MyWriter(new BufferedOutputStream(System.out));
sc = new MyScanner();
new Main().run();
out.close();
}
} | Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | dabcb0ff0c3c687c937db4c5c29403e5 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 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
*
* @author Jaynil
*/
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);
DStonedGame solver = new DStonedGame();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
static class DStonedGame {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int sum = 0;
int max = 0;
for (int i = 0; i < n; i++) {
int l = in.nextInt();
sum += l;
max = Math.max(max, l);
}
if (max > sum / 2) {
out.println("T");
return;
}
if (sum % 2 == 0) {
out.println("HL");
} else {
out.println("T");
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 445fd7e44302d044a2b3e5042f2587b4 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.util.*;
public class C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int testCases = sc.nextInt();
for (int t = 0; t < testCases; t++) {
int n = sc.nextInt();
int arr[] = new int[n];
int max = Integer.MIN_VALUE;
int count = 0;
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
count += arr[i];
max = Math.max(max, arr[i]);
}
if (n == 1) {
sb.append("T").append("\n");
continue;
}
if (max > count - max) {
sb.append("T").append("\n");
continue;
}
if (count % 2 != 0) {
sb.append("T").append("\n");
} else {
sb.append("HL").append("\n");
}
}
System.out.print(sb);
}
} | Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 6829348202094e5fc7e75d8e79481a34 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class d1 extends PrintWriter {
static BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
// static Scanner s=new Scanner(System.in);
d1 () { super(System.out); }
public static void main(String[] args) throws IOException{
d1 d1=new d1 ();d1.main();d1.flush();
}
void main() throws IOException {
BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
StringBuffer sb1 = new StringBuffer();
PrintWriter out = new PrintWriter(System.out);
// Scanner s=new Scanner(System.in);
String[] s1=s();
int t=i(s1[0]);
// System.out.println(vv*(long)x);
while(t-->0) {
String[] s2 = s();
int n = i(s2[0]);
String[] s3 = s();
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = i(s3[i]);
PriorityQueue<Integer> pq=new PriorityQueue<>(n, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o2-o1;
}
});
for(int i:a) pq.add(i);
int T=0;int HL=0;int flag=0;
while(!pq.isEmpty()){
T=pq.poll();
T-=1;
if(HL!=0) pq.add(HL);
if(pq.isEmpty()){
flag=1;break;
}
HL=pq.poll();
HL-=1;
if(T!=0)
pq.add(T);
}
if(flag==0){
System.out.println("HL");
}else System.out.println("T");
}
//System.out.println(sb.toString());
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static String[] s() throws IOException {
return s.readLine().trim().split("\\s+");
}
static int i(String ss) {
return Integer.parseInt(ss);
}
static long l(String ss) {
return Long.parseLong(ss);
}
}
class Student {
int l;long r;
public Student(int l, long r) {
this.l = l;
this.r = r;
}
public String toString()
{
return this.l+" ";
}
}
class Sortbyroll implements Comparator<Student> {
public int compare(Student a, Student b){
if(a.r<b.r) return -1;
else if(a.r==b.r){
if(a.r==b.r){
return 0;
}
if(a.r<b.r) return -1;
return 1;}
return 1; }
}
| Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | da387856e098aa19dadaf0fe2403d08c | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
public class Main {
public static void main(String[] args){
new Thread(null, null, "Anshum Gupta", 99999999) {
public void run() {
try {
solve();
} catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}.start();
}
static final long mxx = (long)(1e18+5);
static final int mxN = (int)(1e6);
static final int mxV = (int)(1e6), log = 18;
static long mod = 998244353;//Μ(long)(1e9+7); //
static final int INF = (int)1e9;
static boolean[]vis, recst;
static ArrayList<ArrayList<Integer>> adj;
static int n, m, k, q, x, b, c, d;
static char[]str;
static Long[]a;
public static void solve() throws Exception {
// solve the problem here
s = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out), true);
// out = new PrintWriter("output.txt");
int tc = s.nextInt();
for(int i=1; i<=tc; i++) {
// out.print("Case #" + i + ": ");
testcase();
}
out.flush();
out.close();
}
static void testcase() {
n = s.nextInt();
int[]a = s.nextIntArray(n);
int sum = Arrays.stream(a).sum();
Arrays.parallelSort(a);
if(2 * a[n-1] > sum) {
out.println("T");
return;
}
out.println(sum % 2 == 0 ? "HL" : "T");
}
public static PrintWriter out;
public static MyScanner s;
static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public MyScanner(String fileName) {
try {
br = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() { return Double.parseDouble(next()); }
int[] nextIntArray(int n){
int[]a = new int[n];
for(int i=0; i<n; i++) {
a[i] = this.nextInt();
}
return a;
}
long[] nextlongArray(int n) {
long[]a = new long[n];
for(int i=0; i<n; i++) {
a[i] = this.nextLong();
}
return a;
}
Integer[] nextIntegerArray(int n){
Integer[]a = new Integer[n];
for(int i=0; i<n; i++) {
a[i] = this.nextInt();
}
return a;
}
Long[] nextLongArray(int n) {
Long[]a = new Long[n];
for(int i=0; i<n; i++) {
a[i] = this.nextLong();
}
return a;
}
char[][] next2DCharArray(int n, int m){
char[][]arr = new char[n][m];
for(int i=0; i<n; i++) {
arr[i] = this.next().toCharArray();
}
return arr;
}
ArrayList<ArrayList<Integer>> readUndirectedUnweightedGraph(int n, int m) {
ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
for(int i=0; i<m; i++) {
int u = s.nextInt();
int v = s.nextInt();
adj.get(u).add(v);
adj.get(v).add(u);
}
return adj;
}
ArrayList<ArrayList<Integer>> readDirectedUnweightedGraph(int n, int m) {
ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
for(int i=0; i<m; i++) {
int u = s.nextInt();
int v = s.nextInt();
adj.get(u).add(v);
}
return adj;
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 8b170f1f1637f62c4334c2b9de013b80 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
System.out.println(helper(arr, n));
}
}
public static String helper(int[] arr, int n) {
PriorityQueue<Integer> heap = new PriorityQueue<>(new Comparator<Integer>() {
public int compare(Integer i1, Integer i2) {
return i2.compareTo(i1);
}
});
for (int i : arr)
heap.add(i);
int pvs = heap.poll() - 1;
int turn = 0;
while (!heap.isEmpty()) {
int t = heap.poll();
if (pvs > 0)
heap.add(pvs);
pvs = t - 1;
turn = 1 - turn;
}
if (turn == 0)
return "T";
else
return "HL";
}
} | Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 283f476f354334fa3bf449dd4a2ff147 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | // Author : AMIT KUMAR BARMAN (gearman_0712)
import java.io.*;
import java.util.*;
public class Stoned{
static final long modp =1000000007;
static long x_ec=1,y_ec=0,d_ec =1;
static long maxi=0;
static boolean v1 =false ,v2 = false;
static InputReader in = new InputReader(System.in);
static OutputStream outputStream = System.out;
static OutputWriter out = new OutputWriter(outputStream);
public static void main (String args[]) throws IOException {
int t= in.readInt();
int c=1;
while(t-->0)
{
int n= in.readInt();
PriorityQueue<Integer> que = new PriorityQueue<>((o1,o2)->{
return o2-o1;
});
int sum = 0;
for(int i= 0;i<n ;i++)
{ int y= in.readInt();
que.add(y);
sum +=y;
}
String winner ="amit";
int ltop=0,hltop=0;
int turn =0;
while(sum>=0)
{ if(turn%2==0)
{ que.add(ltop);
ltop = que.poll();
if(ltop==0)
{ winner ="HL";
break;
}
ltop--;
sum--;
}
else
{ que.add(hltop);
hltop = que.poll();
if(hltop==0)
{ winner ="T";
break;
}
hltop--;
sum --;
}
turn ++;
}
out.println(winner);
}
out.close();
}
/*
static Node lca(Node root,int x,int y)
{if(root==null)
return null;
if(root.value>x &&root.value>y )
return lca(root.left, x, y);
if(root.value<x &&root.value<y )
return lca(root.right, x, y);
return root;
}
static Node common(Node root,int x,int y)
{ if(root==null)
return null;
Node temp=null;
if(root.value ==x)
{ v1= true;
temp =new Node(x);
}
else if(root.value ==y)
{ v2= true;
temp =new Node(y);
}
Node lef =common(root.left, x, y);
Node rig =common(root.right, x, y);
if(temp!=null)
return temp;
if(lef ==null)
return rig;
if(rig==null)
return lef;
return root;
}
// static class Node {
// int value;
// Node left;
// Node right;
// Node(int value){
// this.value =value;
// right =null;
// left =null;
// }
// }
static Node insert(Node root,int v)
{ if(root==null)
return new Node(v);
if( v<=root.value)
root.left =insert(root.left, v);
else
root.right =insert(root.right,v);
return root;
}
static int minvalue(Node root)
{
while(root.left!=null)
root =root.left;
return root.value;
}
static int[] computeLPSArray(String patt)
{ int m= patt.length();
int Lps[]= new int[m];
int i=1 ,len=0;
Lps[0]=0;
while( i<m)
{ if(patt.charAt(i)==patt.charAt(len))
{ len++;
Lps[i]=len;
i++;
}
else
{ if(len!=0)
{len =Lps[len-1];
}
else //len=0
Lps[i++]=len;
}
}
return Lps;
}
static Node delete(Node root ,int val)
{ if(root ==null)
return root;
if(val<root.value)
root.left=delete(root.left, val);
else if(val>root.value)
root.right =delete(root.right,val);
else {
if(root.left==null)
return root.right;
else if(root.right==null)
return root.left;
root.value= minvalue(root.right);
root.right =delete(root.right, root.value);
}
return root;
}
*/
/*
static void inorder(Node root,OutputWriter out)
{ if(root!=null)
{inorder(root.left ,out);
out.print(root.value+" ");
inorder(root.right, out);
}
}
static void preorder(Node root ,OutputWriter out)
{ if(root!=null)
{ out.println(root.value+" ");
preorder(root.left, out);
preorder(root.right,out);
}
}
static void postorder(Node root,OutputWriter out)
{ if(root!=null)
{ postorder(root.left, out);
postorder(root.right ,out);
out.print(root.value+" ");
}
}
*/
// Input: Indices Range [0..size]
// Invariant: A[l] <= key and A[r] > key
static long modExponential(long x,long n)
{long result =1l;
while(n>0l)
{ if(n%2==1)
result =(x*result)%modp;
x= (x*x)%modp;
n=n/2;
}
return result;
}
/*
static int GetRightPosition(int A[], int l, int r, int key)
{
int m;
while( r - l > 1 )
{
m = l + (r - l)/2;
if( A[m] <= key )
l = m;
else
r = m;
}
return l;
}
// Input: Indices Range -1 to size-1
// Invariant: A[r] >= key and A[l] > key
static int GetLeftPosition(int A[], int l, int r, int key)
{
int m;
while( r - l > 1 )
{
m = l + (r - l)/2;
if( A[m] >= key )
r = m;
else
l = m;
}
return r;
}
*/
public static long gcd(long a,long b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
public static int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
public static int abs(int a,int b)
{
return (int)Math.abs(a-b);
}
public static long abs(long a,long b)
{
return (long)Math.abs(a-b);
}
public static int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
public static int min(int a,int b)
{
if(a>b)
return b;
else
return a;
}
public static long max(long a,long b)
{
if(a>b)
return a;
else
return b;
}
public static long min(long a,long b)
{
if(a>b)
return b;
else
return a;
}
/*
void countsort(int arr[],int n,int place)
{
int i,freq[range]={0}; //range for integers is 10 as digits range from 0-9
int output[n];
for(i=0;i<n;i++)
freq[(arr[i]/place)%range]++;
for(i=1;i<range;i++)
freq[i]+=freq[i-1];
for(i=n-1;i>=0;i--)
{
output[freq[(arr[i]/place)%range]-1]=arr[i];
freq[(arr[i]/place)%range]--;
}
for(i=0;i<n;i++)
arr[i]=output[i];
}
void radixsort(ll arr[],int n,int maxx) //maxx is the maximum element in the array
{
int mul=1;
while(maxx)
{
countsort(arr,n,mul);
mul*=10;
maxx/=10;
}
}*/
/* BufferedReader bf =new BufferedReader (new InputStreamReader(System.in));
int t= Integer.parseInt(bf.readLine());
StringBuffer gh =new StringBuffer("");
StringTokenizer tk=new StringTokenizer(bf.readLine());
long a= Long.parseLong(tk.nextToken());
*/
static class Pair implements Comparable<Pair>
{
int a,b;
Pair (int a,int b)
{
this.a=a;
this.b=b;
}
public int compareTo(Pair o) {
if(this.a!=o.a)
return -Integer.compare(this.a,o.a);
else
return Integer.compare(this.b, o.b);
//return 0;
}
public boolean equals(Object o) {
if (o instanceof Pair) {
Pair p = (Pair)o;
return p.a == a && p.b == b;
}
return false;
}
public int hashCode(Object o) {
Pair p = (Pair)o;
return p.a* 31 +p.b;
}
}
static class Pair1 implements Comparable<Pair1>
{
char a;
int b;
Pair1 (char a,int b)
{
this.a=a;
this.b=b;
}
public int compareTo(Pair1 o) {
if(this.a!=o.a)
return Integer.compare(this.a,o.a);
else
return Integer.compare(this.b, o.b);
//return 0;
}
public boolean equals(Object o) {
if (o instanceof Pair1) {
Pair1 p = (Pair1)o;
return p.a == a && p.b == b;
}
return false;
}
public int hashCode(Object o) {
Pair1 p = (Pair1)o;
return (int)p.a* 31 +(int)p.b;
}
}
/*
//public void solve(int testNumber, InputReader in, OutputWriter out)
// in case u want to print And take input inside and static method
static void extendedEuclid( long A, long B) {
if(B==0)
{d_ec=A;
x_ec =1;
y_ec=0;
}
else{
extendedEuclid(B, A%B);
long temp =x_ec;
x_ec = y_ec;
y_ec =temp -(A/B)*y_ec;
}
}
static long modInverse( long A, long M) //A and M are coprime i.e. Ax+My=1. In the extended Euclidean algorithm, x is the modular multiplicative inverse of A under modulo M.
{
extendedEuclid(A,M);
return (x_ec%M+M)%M; //x may be negative
}
static boolean checkprime(int N) {
int count = 0;
for( int i = 1;i * i <=N;++i ) {
if( N % i == 0) {
if( i * i == N )
count++;
else // i < sqrt(N) and (N / i) > sqrt(N)
count += 2;
}
}
if(count == 2)
return true;
else
return false;
}
static void factorize (long a,HashMap<Long,Long> map)
{
long i=2;
for( i=2;i*i<=a;i++)
{
if(a%i==0){
long f=0;
while((a>0)&&(a%i==0))
{
a= a/i;
f++;
}
map.put(i, f);
}
}
if(a>1l)
map.put(a, 1l);
}*/
/*static class DSU
{
int parent[];
int rank[];
int state[];
DSU(int n)
{parent=new int[n];
rank=new int[n];
state=new int[n+1];
}
void makeset(int n)
{
for(int i=0;i<n;i++)
{
parent[i]=i;
rank[i]=1;
state[i]=0;// for jamboard question
}
}
void decP(int x)// for jamboard question
{
if(state[x]>0)
state[x]--;
}
void incP(int x)// for jamboard question
{
state[x]++;
}
boolean getP(int x)// for jamboard question
{
return (state[x]!=0);
}
int find(int x)
{
if(x==parent[x])
return x;
parent[x]=find(parent[x]);
return parent[x];
}
void union(int x,int y)
{
int xRoot=find(x);
int yRoot=find(y);
if(xRoot==yRoot)
return;
if(rank[xRoot]>rank[yRoot])
{
parent[yRoot]=xRoot;
state[xRoot]+=state[yRoot];// for jamboard question
}
else if(rank[xRoot]<rank[yRoot])
{
parent[xRoot]=yRoot;
state[yRoot]+=state[xRoot];// for jamboard question
}
else
{
parent[xRoot]=yRoot;
rank[yRoot]++;
state[yRoot]+=state[xRoot];// for jamboard question
}
}
}
*/
}/*
class DSU
{
int parent[];
int rank[];
int diff[];
DSU(int sd){
parent=new int[sd];
rank=new int[sd];
diff=new int[sd];
}
void makeset(int n)
{
for(int i=0;i<n;i++)
{
parent[i]=i;
rank[i]=1;
diff[i]=0;
}
}
int find (int x) {
if (x == parent [x]) return x;
int t = parent [x];
parent [x] = find (parent [x]);
diff [x] ^= diff [t];
return parent [x];
}
boolean union(int x,int y,int w)
{
int xRoot=find(x);
int yRoot=find(y);
if(xRoot==yRoot)
{ if(w != (diff[x]^diff[y]))
return false;
}
else if(rank[xRoot]>rank[yRoot])
{
parent[yRoot]=xRoot;
diff[yRoot]= diff[x]^diff[y]^w;
}
else if(rank[xRoot]<rank[yRoot])
{
parent[xRoot]=yRoot;
diff[xRoot]= diff[x]^diff[y]^w;
}
else
{
parent[xRoot]=yRoot;
rank[yRoot]++;
diff[xRoot]= diff[x]^diff[y]^w;
}
return true;
}
}*/
class Gnode{
int value;
List<Gnode> neighbours;
Gnode(int x)
{value=x;
neighbours =new ArrayList<>();
}
}
class Node{
int value;
Node left;
Node right;
Node(int qw){
this.value = qw;
this.left = null;
this.right = null;
}
}
class SegTree{
long[] seg;
int[] map;
long[] arr;
SegTree(int n,long[] a){
seg=new long[4*n];
arr=a;
map=new int[n+1];
}
void build(int low,int high, int pos) {
if(low==high) {
map[low]=pos;
seg[pos]=arr[low];
}
else {
int middle=(low+high)/2;
build(low,middle,2*pos+1);
build(middle+1,high,2*pos+2);
seg[pos]=Math.max(seg[2*pos+1], seg[2*pos+2]);
}
}
void update(int low,int high, int pos,int elpos, long value) {
if(low==high) {
seg[pos]=value;
}
else {
int middle=(low+high)/2;
if(elpos<=middle) {
update(low,middle,2*pos+1,elpos,value);
}
else update(middle+1,high,2*pos+2,elpos,value);
seg[pos]=Math.max(seg[2*pos+1], seg[2*pos+2]);
}
}
}
class MinHeap {
int size;
int maxsize;
int heap[];
MinHeap(int maxsize,int size) //size = capacity
{this.size=size;
this.maxsize= maxsize;
heap = new int[maxsize];
}
boolean isEmpty()
{return size==0;
}
int peek()
{if(isEmpty())
return -99999;
return heap[0];
}
int remove()
{if(isEmpty())
return -99999;
int minItem = heap[1];
heap[1]= heap[size];
size --;
heapifyDown(1);
return minItem;
}
void print()
{
System.out.println(Arrays.toString(heap));
}
boolean add( int item)
{ if(size>= maxsize)
return false;
heap[size+1]= item;
size++;
heapifyUp(size);
return true;
}
void heapifyDown( int i)
{ int left = 2*i;
int right = 2*i +1;
int smallest =i;
if(left<= size && heap[left]<heap[smallest])
smallest =left;
if(right<= size && heap[right]<heap[smallest])
smallest =right;
if(smallest!=i)
{ int temp =heap[i];
heap[i]= heap[smallest];
heap[smallest]=temp;
heapifyDown(smallest);
}
}
void heapifyUp( int i)
{
int parent = i/2;
if( parent>0 && heap[parent]>heap[i])
{ int temp =heap[parent];
heap[parent]= heap[i];
heap[i]=temp;
heapifyUp(parent);
}
}}
class MaxHeap {
int size;
int maxsize;
int heap[];
MaxHeap(int maxsize,int size) //size = capacity
{this.size=size;
this.maxsize= maxsize;
heap = new int[maxsize];
}
void buildHeap(int arr[])
{size = arr.length+1;
for(int i=0;i<arr.length;i++)
heap[i+1]= arr[i];
for( int i=size/2;i>=1;i--)
{heapifyDown(i);
}
}
boolean isEmpty()
{return size==0;
}
int peek()
{if(isEmpty())
return -99999;
return heap[0];
}
int remove()
{if(isEmpty())
return -99999;
int minItem = heap[1];
heap[1]= heap[size];
size --;
heapifyDown(1);
return minItem;
}
void print()
{
System.out.println(Arrays.toString(heap));
}
boolean add( int item)
{ if(size>= maxsize)
return false;
heap[size+1]= item;
size++;
heapifyUp(size);
return true;
}
void heapifyDown( int i)
{ int left = 2*i;
int right = 2*i +1;
int largest =i;
if(left<= size && heap[left]>heap[largest])
largest =left;
if(right<= size && heap[right]>heap[largest])
largest =right;
if(largest!=i)
{ int temp =heap[i];
heap[i]= heap[largest];
heap[largest]=temp;
heapifyDown(largest);
}
}
void heapifyUp( int i)
{
int parent = i/2;
if( parent>0 && heap[parent]<heap[i])
{ int temp =heap[parent];
heap[parent]= heap[i];
heap[i]=temp;
heapifyUp(parent);
}
}
}
class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
} catch (IOException e)
{
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt ()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString ()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String readLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public double readDouble() {
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, readInt());
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, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
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 readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
public boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
} | Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | e0e5560ff27901dff9d68c1a336618f0 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes |
import java.io.*;
import java.util.*;
/*
By : SSD
*/
public class D {
long mod = (long) (1e9 + 7);
static class InputReader1 {
private final InputStream st;
private final byte[] buf = new byte[8192];
private int cc, sc;
private SpaceCharFilter f;
public InputReader1(InputStream st) {
this.st = st;
}
public int t() {
if (sc == -1)
throw new InputMismatchException();
if (cc >= sc) {
cc = 0;
try {
sc = st.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (sc <= 0)
return -1;
}
return buf[cc++];
}
public int nextInt() {
int c = t();
while (isSpaceChar(c)) {
c = t();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = t();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = t();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = t();
while (isSpaceChar(c)) {
c = t();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = t();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = t();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public String readString() {
int c = t();
while (isSpaceChar(c)) {
c = t();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = t();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = t();
while (isSpaceChar(c))
c = t();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = t();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (f != null)
return f.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public 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();
}
}
InputReader1 sc;
OutputWriter out;
public static void main(String[] ssd) throws Exception {
new D().run();
}
void run() throws Exception {
sc = new InputReader1(System.in);
out = new OutputWriter(System.out);
long s = System.currentTimeMillis();
solve();
tr(System.currentTimeMillis() - s + "ms");
out.close();
}
private int sum(List<Integer> list) {
return list.stream().mapToInt(i -> i).sum();
}
private void solve() {
int tt = sc.nextInt();
while (tt-- > 0) {
int n = sc.nextInt();
List<Integer> a = new ArrayList<>();
for (int i = 0; i < n; i++) {
int aa=sc.nextInt();
a.add(aa);
}
//System.out.println(a);
int max = Collections.max(a);
//System.out.println("max" +max);
//System.out.println("ssd"+sum(a));
int sum = sum(a);
if (2* max > sum || sum % 2 == 1) {
out.println("T");
} else {
out.println("HL");
}
}
}
void dbg(Object... o) {
System.err.println(Arrays.deepToString(o));
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) {
if (!oj)
out.println(Arrays.deepToString(o));
}
}
| Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | ed68f21a3c38abb9e1c5fa0fc35d421a | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.util.*;
public class div2666{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int[] arr= new int[n];
int sum=0,max=0;
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
sum+=arr[i];
max=Math.max(max,arr[i]);
}
if((max>(sum-max))|| sum%2==1)
System.out.println("T");
else
System.out.println("HL");
}
}
} | Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 26eb0beb5cc4c15db74d49e2d6eda950 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes |
import java.util.*;
import java.util.stream.Collectors;
public class problem3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0; i < t; i++)
{
int n = sc.nextInt();
sc.nextLine();
String nums = sc.nextLine();
List<Integer> ints = Arrays.stream(nums.split(" ")).map(x -> Integer.valueOf(x)).collect(Collectors.toList());
run(n, ints);
}
}
private static void run(int n, List<Integer> ints) {
// System.out.println(ints);
var pq = new PriorityQueue<int[]>((a,b)->(b[0]-a[0]));
for(int i=0; i < n; i++) {
pq.offer(new int[] { ints.get(i), i });
}
var isT = true;
Integer prev = -1;
while(pq.size() != 0) {
var curr = pq.poll();
if(prev != curr[1]) {
curr[0]--;
if(curr[0] != 0) {
pq.offer(new int[]{ curr[0], curr[1]});
}
prev = curr[1];
} else {
if(pq.size() == 0) {
break;
}
var next = pq.poll();
next[0]--;
if(next[0] != 0) {
pq.offer(new int[] { next[0], next[1]});
}
prev = next[1];
pq.offer(curr);
}
isT = !isT;
}
System.out.println(!isT ? "T" : "HL");
}
} | Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | 55f3aa6b3df6c4d5b3fb353b0d833300 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.text.DecimalFormat;
import java.util.*;
public class Test {
private static final Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int g = sc.nextInt();
for (int i = 0; i < g; i++) {
int p = sc.nextInt();
boolean win = true;
PriorityQueue<Integer> queue = new PriorityQueue<>(Collections.reverseOrder());
int prev = -1;
for (int j = 0; j < p; j++) {
queue.add(sc.nextInt());
}
while (queue.size() != 0) {
int tp = queue.poll();
if (prev - 1 > 0) {
queue.add(prev - 1);
}
prev = tp;
win = !win;
}
if (win) {
System.out.println("HL");
} else {
System.out.println("T");
}
}
}
} | Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | b3d0feb9267f9fdea9890beb60c14b84 | train_002.jsonl | 1598798100 | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game. | 256 megabytes | import java.lang.reflect.Array;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t-- > 0) {
int n = scanner.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; ++i) {
arr[i] = scanner.nextInt();
}
if (n == 1)
System.out.println("T");
else if (n == 2) {
if (arr[0] == arr[1])
System.out.println("HL");
else
System.out.println("T");
} else {
while (true) {
Arrays.sort(arr);
if (arr[n - 1] == 0) {
System.out.println("HL");
break;
} else {
arr[n - 1]--;
if (arr[n - 2] == 0) {
System.out.println("T");
break;
} else
arr[n - 2]--;
}
}
}
}
}
}
| Java | ["2\n1\n2\n2\n1 1"] | 1 second | ["T\nHL"] | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | Java 11 | standard input | [
"implementation",
"greedy",
"games",
"brute force"
] | 5bfce6c17af24959b4af3c9408536d05 | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ β the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$. | 1,800 | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | standard output | |
PASSED | b47073cd20720a07ba39f0c9327107bd | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ProblemC {
static class Target implements Comparable<Target> {
long x;
long y;
long time;
double prob;
Target(String[] l) {
x = Long.valueOf(l[0]);
y = Long.valueOf(l[1]);
time = Long.valueOf(l[2]);
prob = Double.valueOf(l[3]);
}
@Override
public int compareTo(Target arg0) {
return Long.signum(time - arg0.time);
}
}
public static void main(String[] args) throws IOException {
BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int n = Integer.valueOf(s.readLine());
Target[] t = new Target[n];
for (int i = 0 ; i < n ; i++) {
t[i] = new Target(s.readLine().split(" "));
}
Arrays.sort(t);
boolean[][] cango = new boolean[n][n];
for (int i = 0 ; i < n ; i++) {
for (int j = i+1 ; j < n ; j++) {
long dtime = t[j].time - t[i].time;
long dx = Math.abs(t[j].x - t[i].x);
long dy = Math.abs(t[j].y - t[i].y);
if (dtime * dtime >= dx * dx + dy * dy) {
cango[i][j] = true;
}
}
}
double[] dp = new double[n];
for (int i = 0 ; i < n ; i++) {
dp[i] = Math.max(dp[i], t[i].prob);
for (int j = i+1 ; j < n ; j++) {
if (cango[i][j]) {
dp[j] = Math.max(dp[j], dp[i] + t[j].prob);
}
}
}
double max = 0;
for (int i = 0 ; i < n ; i++) {
max = Math.max(max, dp[i]);
}
out.println(max);
out.flush();
}
public static void debug(Object... os){
System.err.println(Arrays.deepToString(os));
}
} | Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | f9c5b1104c0ff8174272f100c2b51f1d | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main implements Runnable {
public void _main() throws IOException {
int n = nextInt();
int[] x = new int[n];
int[] y = new int[n];
int[] t = new int[n];
double[] p = new double[n];
for (int i = 0; i < n; i++) {
x[i] = nextInt();
y[i] = nextInt();
t[i] = nextInt();
p[i] = nextDouble();
}
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if (t[i] > t[j]) {
int z;
z = x[i]; x[i] = x[j]; x[j] = z;
z = y[i]; y[i] = y[j]; y[j] = z;
z = t[i]; t[i] = t[j]; t[j] = z;
double g;
g = p[i]; p[i] = p[j]; p[j] = g;
}
double[] d = new double[n];
double res = 0;
for (int i = n - 1; i >= 0; i--) {
d[i] = p[i];
res = Math.max(res, d[i]);
for (int j = i + 1; j < n; j++) {
long dx = x[i] - x[j];
long dy = y[i] - y[j];
long dt = t[i] - t[j];
if (dx * dx + dy * dy <= dt * dt) {
d[i] = Math.max(d[i], p[i] + d[j]);
res = Math.max(res, d[i]);
}
}
}
out.printf("%.6f", res);
}
private BufferedReader in;
private PrintWriter out;
private StringTokenizer st;
private String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String rl = in.readLine();
if (rl == null)
return null;
st = new StringTokenizer(rl);
}
return st.nextToken();
}
private int nextInt() throws IOException {
return Integer.parseInt(next());
}
private long nextLong() throws IOException {
return Long.parseLong(next());
}
private double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static void main(String[] args) {
Locale.setDefault(Locale.UK);
new Thread(new Main()).start();
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
_main();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(202);
}
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | 8d5d74aec79d0498c336f95cbd6a3fc5 | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | //package round30;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class C {
private Scanner in;
private PrintWriter out;
// private String INPUT = "1 0 0 0 0.5";
// private String INPUT = "2 0 0 0 0.6 5 0 5 0.7";
// private String INPUT = "3 0 0 0 0.6 4 0 4 0.85 2 0 5 0.8";
// private String INPUT = "2 1000 1000 1000000000 0.15 -1000 -1000 500000000 0.1";
// private String INPUT = "2 2 0 1 0.5 0 3 5 0.4";
private String INPUT = "";
public void solve()
{
int n = ni();
Target[] ts = new Target[n];
for(int i = 0;i < n;i++){
ts[i] = new Target();
ts[i].x = ni();
ts[i].y = ni();
ts[i].t = ni();
ts[i].p = in.nextDouble();
}
Arrays.sort(ts);
double maxp = 0;
double[] p = new double[n];
for(int i = 0;i < n;i++){
double curmax = 0;
// if(ts[i].t * ts[i].t == ts[i].x * ts[i].x + ts[i].y * ts[i].y){
// curmax = 0;
// }
for(int j = 0;j < i;j++){
if(p[j] != -1 && (ts[i].t - ts[j].t) * (ts[i].t - ts[j].t) >= (ts[i].x - ts[j].x) * (ts[i].x - ts[j].x) + (ts[i].y - ts[j].y) * (ts[i].y - ts[j].y)){
curmax = Math.max(curmax, p[j]);
}
}
if(curmax == -1){
p[i] = -1;
}else{
p[i] = curmax + ts[i].p;
maxp = Math.max(maxp, p[i]);
}
}
out.println(maxp);
}
public static class Target implements Comparable<Target>
{
public long x, y, t;
public double p;
@Override
public int compareTo(Target o) {
return Long.signum(this.t - o.t);
}
}
public void run() throws Exception
{
in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
out = new PrintWriter(System.out);
solve();
out.flush();
}
public static void main(String[] args) throws Exception
{
new C().run();
}
private int ni() { return Integer.parseInt(in.next()); }
private void tr(Object... o) { if(INPUT.length() != 0)System.out.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | dcfdacf899b011bb15033b0f66d1a60c | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class C {
static class struct implements Comparable<struct> {
int x, y, t;
double prob;
public struct(int xx, int yy, int tt, double p) {
x = xx;
y = yy;
t = tt;
prob = p;
}
public int compareTo(struct z) {
if (z.t < t)
return 1;
return -1;
}
}
static struct[] s;
static double[][] dp;
public static double solve(int idx, int last) {
if (idx >= dp.length)
return 0;
if (dp[idx][last] != -1)
return dp[idx][last];
double dist = Math.sqrt((s[last].x - s[idx].x) * (s[last].x - s[idx].x)
+ (s[last].y - s[idx].y) * (s[last].y - s[idx].y));
if (dist <= s[idx].t - s[last].t) {
return dp[idx][last] = Math.max(s[idx].prob + solve(idx + 1, idx),
solve(idx + 1, last));
} else {
return dp[idx][last] = solve(idx + 1, last);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
s = new struct[n];
for (int i = 0; i < n; i++)
s[i] = new struct(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc
.nextDouble());
Arrays.sort(s);
dp=new double[n][n];
for(int i=0;i<n;i++) Arrays.fill(dp[i], -1);
double res=0;
for(int i=0;i<s.length;i++) {
res=Math.max(res, s[i].prob+solve(i+1,i));
}
System.out.println(res);
}
} | Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | 26e1e4f79ce075c7bf1a85e0f22f6be7 | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.util.Arrays;
import java.util.Locale;
import java.util.Scanner;
/**
* @author Sergey Kopeliovich (burunduk1@yandex-team.ru)
*/
public class C {
private double res = 0;
public static void main(String[] args) {
new C().run();
}
private void run() {
Locale.setDefault(Locale.US);
Scanner in = new Scanner(System.in);
int n = in.nextInt();
MyTarget t[] = new MyTarget[n];
for (int i = 0; i < n; i++) {
t[i] = new MyTarget(in);
}
Arrays.sort(t);
double f[] = new double[n];
for (int i = 0; i < n; i++) {
f[i] = 0.0;
for (int j = 0; j < n; j++) {
if (t[j].canGoTo(t[i])) {
f[i] = Math.max(f[i], f[j]);
}
}
f[i] += t[i].getP();
res = Math.max(res, f[i]);
}
System.out.format("%.10f\n", res);
}
private class MyTarget implements Comparable {
private int x;
private int y;
private int t;
private double p;
public MyTarget(Scanner in) {
x = in.nextInt();
y = in.nextInt();
t = in.nextInt();
p = in.nextDouble();
}
public int compareTo(Object o) {
return t - ((MyTarget)o).t;
}
public double getP() {
return p;
}
public boolean canGoTo(MyTarget target) {
return t <= target.t && sqr(x - target.x) + sqr(y - target.y) <= sqr(t - target.t);
}
private long sqr(int d) {
return (long)d * d;
}
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | 9316c994809dc676e9e19b486e013287 | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class C {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s = new String(in.readLine());
int n = Integer.parseInt(s);
int[] x = new int[n];
int[] y = new int[n];
int[] t = new int[n];
double[] p = new double[n];
for (int i=0;i<n;i++) {
s = new String(in.readLine());
String[] u=s.split(" ");
x[i] = Integer.parseInt(u[0]);
y[i] = Integer.parseInt(u[1]);
t[i] = Integer.parseInt(u[2]);
p[i] = Double.parseDouble(u[3]);
}
double max = 0;
double[] memo = new double[n];
for (int i=0;i<n;i++) {
double sc = score(i,x,y,t,p,memo);
if (sc>max) {
max = sc;
}
}
System.out.println(max);
}
public static double score(int i, int[] x, int[] y, int[] t, double[] p, double[] memo) {
if (memo[i]!=0) {
return memo[i];
}
double max = 0;
for (int j=0;j<x.length;j++) {
if (i==j) {
continue;
}
int dx = x[i]-x[j];
int dy = y[i]-y[j];
int distance = (int) Math.ceil(Math.sqrt((double)dx*dx+dy*dy));
if (t[j]<t[i]+distance) {
continue;
}
double sc = score(j,x,y,t,p,memo);
if (sc>max) {
max = sc;
}
}
memo[i] = max+p[i];
return memo[i];
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | 7fbc246d0719470cebac1591cf7beda7 | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Main {
InputStreamReader inp = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(inp);
boolean test = false;
PrintWriter writer = new PrintWriter(System.out);
String[] inData = { "2","0 0 0 0.6","5 0 5 0.7" };
static int id = -1;
public String readLine() throws IOException {
id++;
if (test)
return inData[id];
else
return in.readLine();
}
class Target{
int x;
int y;
int t;
double p;
public Target(int x, int y, int t, double p) {
super();
this.x = x;
this.y = y;
this.t = t;
this.p = p;
}
}
private void solve() throws NumberFormatException, IOException {
int lineNr = Integer.valueOf(readLine());
Target[] targets = new Target[lineNr];
for (int x = 0; x < lineNr; x++) {
String line = readLine();
String[] split = line.split(" ");
Target target = new Target(Integer.valueOf(split[0]), Integer.valueOf(split[1]), Integer.valueOf(split[2]), Double.valueOf(split[3]));
targets[x] = target;
}
List<Target> asList = Arrays.asList(targets);
Collections.sort(asList, new Comparator<Target>() {
public int compare(Target o1, Target o2) {
return Integer.valueOf(o1.t).compareTo(Integer.valueOf(o2.t));
}
});
targets = (Target[]) asList.toArray();
double[] best = new double[targets.length];
//DP Approach: each point if its reachable from the previous point
for (int i = 0; i < targets.length; i++) {
if(targets[i].p > best[i]){
best[i] = targets[i].p;
}
for (int j = i+1; j < targets.length; j++) {
if(targets[j].p + best[i] > best[j] && reachable(targets[j], targets[i])){
best[j] = targets[j].p + best[i];
}
}
}
double max = 0;
for (int i = 0; i < best.length; i++) {
if(best[i] > max){
max = best[i];
}
}
System.out.println(max);
}
private boolean reachable(Target t1, Target t2) {
if(t1.t != t2.t && Math.sqrt(Math.pow(t2.x-t1.x, 2) + Math.pow(t2.y-t1.y, 2)) <= Math.abs(t2.t - t1.t)){
return true;
}
return false;
}
public static void main(String[] args) throws Throwable{
new Main().solve();
}
} | Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | e89dc76debcc9b33559f6b9da3a04f51 | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.util.*;
public class ShootingGallery {
static double[] memo;
static double[] p,t;
static double[][] dis;
static int N;
public static void main(String[] args){
Scanner reader = new Scanner(System.in);
N = reader.nextInt();
p = new double[N];
t = new double[N];
dis = new double[N][N];
memo = new double[N];
double[] x = new double[N];
double[] y = new double[N];
for(int i = 0; i < N; i++){
x[i] = reader.nextDouble();
y[i] = reader.nextDouble();
t[i] = reader.nextDouble();
p[i] = reader.nextDouble();
}
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
dis[i][j] = Math.sqrt(Math.pow(x[i]-x[j],2) + Math.pow(y[i]-y[j],2));
Arrays.fill(memo, -1);
double max = 0;
for(int i = 0; i < N; i++)
max = Math.max(max, p[i] + f(i));
System.out.println(max);
}
public static double f(int n){
if(memo[n] == -1){
if(n == N){
memo[n] = 0;
}else{
double max = 0;
for(int i = 0; i < N; i++)
if(i != n && dis[n][i] + t[n] <= t[i])
max = Math.max(max, p[i] + f(i));
memo[n] = max;
}
}
return memo[n];
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | 2afd0ab6e6cf456e18117fec6bce9fb7 | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Locale;
public class C {
static {
final Locale us = Locale.US;
if (!Locale.getDefault().equals(us)) {
Locale.setDefault(us);
}
}
static boolean file = false;
static boolean isLocal = true;
private static int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
private static double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
static StreamTokenizer in;
static {
try {
// in = new Scanner(file ? new
// FileInputStream("f:\\var\\tmp\\in.txt")
// : System.in);
// in = new BufferedReader(new InputStreamReader(
// file ? new FileInputStream("f:\\var\\tmp\\in.txt")
// : System.in));
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(
file ? new FileInputStream("f:\\var\\tmp\\in.txt")
: System.in)));
} catch (final FileNotFoundException e) {
e.printStackTrace();
}
}
static PrintWriter out;
static {
try {
out = file ? new PrintWriter(
new FileWriter("f:\\var\\tmp\\out.txt")) : new PrintWriter(
System.out);
} catch (final IOException e) {
e.printStackTrace();
}
}
static PrintStream err;
private static double[] cache;
private static int n;
private static int[] xs;
private static int[] ys;
private static long[] ts;
private static double[] ps;
static {
err = System.err;
}
/**
* @param args
* @throws IOException
*/
public static void main(final String[] args) throws IOException {
try {
final long startTime = System.nanoTime();
final long t = 1;// nextInt();
for (long i = 0; i < t; ++i) {
solve(i + 1);
if (file) {
err.println(i + 1 + "/" + t);
}
if (!file) {
out.flush();
}
}
if (isLocal) {
err.println(String.format("Completed after %d ms.",
(System.nanoTime() - startTime) / 1000000));
}
} finally {
out.flush();
}
}
private static void solve(final long testId) throws IOException {
n = nextInt();
xs = new int[n];
ys = new int[n];
ts = new long[n];
ps = new double[n];
cache = new double[n];
Arrays.fill(cache, -1.0);
for (int i = 0; i < n; ++i) {
xs[i] = nextInt();
ys[i] = nextInt();
ts[i] = nextInt();
ps[i] = nextDouble();
}
double ans = 0.0;
for (int i = 0; i < n; ++i) {
final double candidate = value(i);
if (candidate > ans) {
ans = candidate;
}
}
out.printf("%.6f\n", ans);
}
private static double value(final int q) {
if (cache[q] == -1.0) {
double best = 0.0;
for (int i = 0; i < n; ++i) {
if (ts[i] > ts[q]) {
final long dt = ts[i] - ts[q];
final long dx = xs[i] - xs[q];
final long dy = ys[i] - ys[q];
if (dx * dx + dy * dy <= dt * dt) {
best = Math.max(best, value(i));
}
}
}
cache[q] = ps[q] + best;
}
return cache[q];
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | abb6fd4aedc8118d64deb10090c16b9b | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Solution {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
static class Pair implements Comparable<Pair> {
int x, y, t;
double p;
public Pair(int x, int y, int t, double p) {
this.x = x;
this.y = y;
this.t = t;
this.p = p;
}
@Override
public int compareTo(Pair o) {
return t - o.t;
}
}
double sqr(double a) {
return a * a;
}
double dist(double x1, double y1, double x2, double y2) {
return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}
void solve() throws IOException {
int n = ni();
Pair[] v = new Pair[n];
for (int i = 0; i < n; ++i)
v[i] = new Pair(ni(), ni(), ni(), nd());
Arrays.sort(v);
double[] dp = new double[n];
for (int i = 0; i < n; ++i)
dp[i] = v[i].p;
for (int i = 0; i < n; ++i)
for (int j = 0; j < i; ++j) {
double dist = dist(v[i].x, v[i].y, v[j].x, v[j].y);
double dt = v[i].t - v[j].t;
if (dist <= dt) {
dp[i] = max(dp[i], dp[j] + v[i].p);
}
}
double ret = 0.0;
for (int i = 0; i < n; ++i)
ret = max(ret, dp[i]);
out.println(ret);
}
public Solution() throws IOException {
Locale.setDefault(Locale.US);
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
in.close();
out.close();
}
String ns() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
int ni() throws IOException {
return Integer.valueOf(ns());
}
long nl() throws IOException {
return Long.valueOf(ns());
}
double nd() throws IOException {
return Double.valueOf(ns());
}
public static void main(String[] args) throws IOException {
new Solution();
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | 65daa898d1946da0d6df04df30434379 | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | 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 {
public static void main(String[] args) throws IOException {
try {
if (new File("input.txt").exists())
System.setIn(new FileInputStream("input.txt"));
} catch (SecurityException e) {}
new Main().run();
}
BufferedReader in;
PrintWriter out;
StringTokenizer st = new StringTokenizer("");
int N;
Event[] e;
double[] dp;
int[] cnt;
void run() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
N = nextInt();
e = new Event [N];
dp = new double [N];
cnt = new int [N];
for (int i = 0; i < N; i++)
e[i] = new Event(nextInt(), nextInt(), nextInt(), nextDouble());
sort(e);
double ans = 0.0;
for (int i = 0; i < N; i++) {
dp[i] = e[i].p;
for (int j = 0; j < i; j++) {
long ds = sqr(e[i].x - e[j].x) + sqr(e[i].y - e[j].y);
long ts = sqr(e[i].t - e[j].t);
if (ts >= ds)
dp[i] = max(dp[i], dp[j] + e[i].p);
}
ans = max(ans, dp[i]);
}
out.println(ans);
out.close();
}
long sqr(long x) {
return x * x;
}
class Event implements Comparable<Event> {
int x;
int y;
int t;
double p;
Event(int x, int y, int t, double p) {
this.x = x;
this.y = y;
this.t = t;
this.p = p;
}
@Override
public int compareTo(Event e) {
return t - e.t;
}
}
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());
}
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;
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | 75360cac4f13acefdb9864145e9bf765 | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.util.*;
public class C {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
final int N = sc.nextInt();
final int[] x = new int[N];
final int[] y = new int[N];
final int[] t = new int[N];
final double[] p = new double[N];
Integer[] order = new Integer[N];
for (int i = 0; i < N; ++i) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
t[i] = sc.nextInt();
p[i] = sc.nextDouble();
order[i] = i;
}
Arrays.sort(order, new Comparator<Integer>() {
public int compare(Integer i, Integer j) {
return new Integer(t[i]).compareTo(new Integer(t[j]));
}
});
double[] exp = new double[N];
double result = 0;
for (int i = 0; i < N; ++i) {
exp[i] = p[order[i]];
for (int j = 0; j < i; ++j) {
if ((x[order[i]] - x[order[j]]) * (x[order[i]] - x[order[j]])
+ (y[order[i]] - y[order[j]])
* (y[order[i]] - y[order[j]]) <= (long) (t[order[i]] - t[order[j]])
* (t[order[i]] - t[order[j]]))
exp[i] = Math.max(exp[i], exp[j] + p[order[i]]);
}
result = Math.max(result, exp[i]);
}
System.out.println(result);
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | fefc261e70f17e5c09c3e0e5ff36a31c | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.util.*;
public class C {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
final int N = sc.nextInt();
final int[] x = new int[N];
final int[] y = new int[N];
final int[] t = new int[N];
final double[] p = new double[N];
Integer[] order = new Integer[N];
for (int i = 0; i < N; ++i) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
t[i] = sc.nextInt();
p[i] = sc.nextDouble();
order[i] = i;
}
Arrays.sort(order, new Comparator<Integer>() {
public int compare(Integer i, Integer j) {
return new Integer(t[i]).compareTo(new Integer(t[j]));
}
});
double[] exp = new double[N];
double result = 0;
for (int i = 0; i < N; ++i) {
exp[i] = p[order[i]];
for (int j = 0; j < i; ++j) {
if ((x[order[i]] - x[order[j]]) * (x[order[i]] - x[order[j]])
+ (y[order[i]] - y[order[j]])
* (y[order[i]] - y[order[j]]) <= (long) (t[order[i]] - t[order[j]])
* (t[order[i]] - t[order[j]]))
exp[i] = Math.max(exp[i], exp[j] + p[order[i]]);
}
result = Math.max(result, exp[i]);
}
System.out.println(result);
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | d99c4fd381910c146b55a378b7555f81 | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.util.*;
public class C {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
final int N = sc.nextInt();
final int[] x = new int[N];
final int[] y = new int[N];
final int[] t = new int[N];
final double[] p = new double[N];
Integer[] order = new Integer[N];
for (int i = 0; i < N; ++i) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
t[i] = sc.nextInt();
p[i] = sc.nextDouble();
order[i] = i;
}
Arrays.sort(order, new Comparator<Integer>() {
public int compare(Integer i, Integer j) {
return new Integer(t[i]).compareTo(new Integer(t[j]));
}
});
double[] exp = new double[N];
double result = 0;
for (int i = 0; i < N; ++i) {
exp[i] = p[order[i]];
for (int j = 0; j < i; ++j) {
if ((x[order[i]] - x[order[j]]) * (x[order[i]] - x[order[j]])
+ (y[order[i]] - y[order[j]])
* (y[order[i]] - y[order[j]]) <= (long) (t[order[i]] - t[order[j]])
* (t[order[i]] - t[order[j]]))
exp[i] = Math.max(exp[i], exp[j] + p[order[i]]);
}
result = Math.max(result, exp[i]);
}
System.out.println(result);
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | 52b577a63086d86f5f3b4ec29c1bd719 | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.util.*;
public class C {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
final int N = sc.nextInt();
final int[] x = new int[N];
final int[] y = new int[N];
final int[] t = new int[N];
final double[] p = new double[N];
Integer[] order = new Integer[N];
for (int i = 0; i < N; ++i) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
t[i] = sc.nextInt();
p[i] = sc.nextDouble();
order[i] = i;
}
Arrays.sort(order, new Comparator<Integer>() {
public int compare(Integer i, Integer j) {
return new Integer(t[i]).compareTo(new Integer(t[j]));
}
});
double[] exp = new double[N];
double result = 0;
for (int i = 0; i < N; ++i) {
exp[i] = p[order[i]];
for (int j = 0; j < i; ++j) {
if ((x[order[i]] - x[order[j]]) * (x[order[i]] - x[order[j]])
+ (y[order[i]] - y[order[j]])
* (y[order[i]] - y[order[j]]) <= (long) (t[order[i]] - t[order[j]])
* (t[order[i]] - t[order[j]]))
exp[i] = Math.max(exp[i], exp[j] + p[order[i]]);
}
result = Math.max(result, exp[i]);
}
System.out.println(result);
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | 1c30c8d142fe199f1cc53f3e7882754e | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.util.*;
public class C {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
final int N = sc.nextInt();
final int[] x = new int[N];
final int[] y = new int[N];
final int[] t = new int[N];
final double[] p = new double[N];
Integer[] order = new Integer[N];
for (int i = 0; i < N; ++i) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
t[i] = sc.nextInt();
p[i] = sc.nextDouble();
order[i] = i;
}
Arrays.sort(order, new Comparator<Integer>() {
public int compare(Integer i, Integer j) {
return new Integer(t[i]).compareTo(new Integer(t[j]));
}
});
double[] exp = new double[N];
double result = 0;
for (int i = 0; i < N; ++i) {
exp[i] = p[order[i]];
for (int j = 0; j < i; ++j) {
if ((x[order[i]] - x[order[j]]) * (x[order[i]] - x[order[j]])
+ (y[order[i]] - y[order[j]])
* (y[order[i]] - y[order[j]]) <= (long) (t[order[i]] - t[order[j]])
* (t[order[i]] - t[order[j]]))
exp[i] = Math.max(exp[i], exp[j] + p[order[i]]);
}
result = Math.max(result, exp[i]);
}
System.out.println(result);
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | a9cabf83a85d611fec1fc57b0076c671 | train_002.jsonl | 1285340400 | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi,βyi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0. | 256 megabytes | import java.io.*;
import java.util.Arrays;
import static java.lang.Math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
@SuppressWarnings("unused")
public class round30C {
static class target implements Comparable<target>{
int x, y, time;
double prob;
public target(int xx, int yy, int t, double p){
x = xx;
y = yy;
time = t;
prob = p;
}
public int compareTo(target t){
if(this.time < t.time)
return -1;
if(this.time > t.time)
return 1;
return 0;
}
}
static target [] all;
static double [] dp;
public static double runDP(int idx){
if(idx >= all.length)
return 0;
if(dp[idx] != -1)
return dp[idx];
double ans = 0.0;
for(int i = idx + 1 ; i <= all.length ; ++i){
if(i == all.length){
ans = max(ans, runDP(i));
continue;
}
if((all[i].time - all[idx].time) >=
sqrt((all[i].x - all[idx].x) * (all[i].x - all[idx].x) + (all[i].y - all[idx].y) * (all[i].y - all[idx].y))){
ans = max(ans, all[i].prob + runDP(i));
}
}
return dp[idx] = ans;
}
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = parseInt(br.readLine());
String [] use = null;
all = new target [n];
for(int i = 0 ; i < n ; ++i){
use = br.readLine().split(" ");
all[i] = new target(parseInt(use[0]), parseInt(use[1]), parseInt(use[2]), parseDouble(use[3]));
}
Arrays.sort(all);
dp = new double [n + 1];
Arrays.fill(dp, -1);
double ans = 0.0;
for(int i = 0 ; i < n ; ++i)
ans = max(ans, all[i].prob + runDP(i));
System.out.println(ans);
}
}
| Java | ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"] | 2 seconds | ["0.5000000000", "1.3000000000"] | null | Java 6 | standard input | [
"dp",
"probabilities"
] | 1df8aad60e5dff95bffb9adee5f8c460 | The first line contains integer n (1ββ€βnββ€β1000) β amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti β integers, β-β1000ββ€βxi,βyiββ€β1000,β0ββ€βtiββ€β109, real number pi is given with no more than 6 digits after the decimal point, 0ββ€βpiββ€β1). No two targets may be at the same point. | 1,800 | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10β-β6. | standard output | |
PASSED | a2314b0fa798e5ba8fba579f48825c91 | train_002.jsonl | 1302706800 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. lowββ€βdββ€βhigh. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query. | 256 megabytes |
import java.io.*;
import java.util.*;
public class C
{
public static void main(String[] args)throws IOException
{
FastReader f=new FastReader();
StringBuffer sb=new StringBuffer();
int a=f.nextInt();
int b=f.nextInt();
int gcd=gcd(a,b);
List<Integer> list=divisors(gcd);
Collections.sort(list);
int n=f.nextInt();
while(n-->0)
{
int low=f.nextInt();
int high=f.nextInt();
int l=0,r=list.size()-1;
long ans=-1;
while(l<=r)
{
int mid=(l+r)/2;
int x=list.get(mid);
if(x>=low && x<=high)
{
ans=x;
l=mid+1;
}
if(x<low)
l=mid+1;
else if(x>high)
r=mid-1;
}
sb.append(ans+"\n");
}
System.out.println(sb);
}
public static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
static List<Integer> divisors(int n) {
List<Integer> fact = new ArrayList<>();
for (int i = 1; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
if (n / i == i) {
fact.add(i);
} else {
fact.add(i);
fact.add(n / i);
}
}
}
return fact;
}
}
class Pair
{
int x,y;
Pair(int x,int y)
{
this.x=x;
this.y=y;
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try{
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try{
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
| Java | ["9 27\n3\n1 5\n10 11\n9 11"] | 2 seconds | ["3\n-1\n9"] | null | Java 8 | standard input | [
"binary search",
"number theory"
] | 6551be8f4000da2288bf835169662aa2 | The first line contains two integers a and b, the two integers as described above (1ββ€βa,βbββ€β109). The second line contains one integer n, the number of queries (1ββ€βnββ€β104). Then n lines follow, each line contains one query consisting of two integers, low and high (1ββ€βlowββ€βhighββ€β109). | 1,600 | Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | standard output | |
PASSED | 22c9faff408be946d3e25df205e2edc1 | train_002.jsonl | 1475928900 | There are k sensors located in the rectangular room of size nβΓβm meters. The i-th sensor is located at point (xi,βyi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0,β0) and (n,βm). Walls of the room are parallel to coordinate axes.At the moment 0, from the point (0,β0) the laser ray is released in the direction of point (1,β1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1,β1) in exactly one second after the start.When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print β-β1 for such sensors. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Collections;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Denis Nedelyaev
*/
public class Main {
public static void main(String[] args) throws Exception {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC(in, out);
solver.solve(1);
out.close();
}
static class TaskC {
private final FastScanner in;
private final PrintWriter out;
public TaskC(FastScanner in, PrintWriter out) {
this.in = in;
this.out = out;
}
public void solve(int testNumber) throws IOException {
int n = in.nextInt();
int m = in.nextInt();
int k = in.nextInt();
int[][] coords = in.nextInts(k, 2);
Map<TaskC.Line, List<Integer>> lineDetectors = new HashMap<>();
long[] ans = new long[k];
Arrays.fill(ans, Long.MAX_VALUE);
for (int i = 0; i < k; i++) {
int x = coords[i][0];
int y = coords[i][1];
lineDetectors.computeIfAbsent(new TaskC.Line(1, y - x), key -> new ArrayList<>()).add(i);
lineDetectors.computeIfAbsent(new TaskC.Line(-1, y + x), key -> new ArrayList<>()).add(i);
}
int x = 0;
int y = 0;
int dx = 1;
int dy = 1;
long dist = 0;
do {
TaskC.Line line = new TaskC.Line(dx * dy, y - dx * dy * x);
for (int detector : lineDetectors.getOrDefault(line, Collections.emptyList())) {
int detx = coords[detector][0];
int dety = coords[detector][1];
ans[detector] = Math.min(ans[detector], dist + Math.abs(x - detx));
}
int nx = dx > 0 ? n : 0;
int ny = dy > 0 ? m : 0;
int distx = Math.abs(nx - x);
int disty = Math.abs(ny - y);
if (distx < disty) {
ny = y + distx * dy;
dx = -dx;
} else {
nx = x + disty * dx;
dy = -dy;
}
dist += Math.abs(nx - x);
x = nx;
y = ny;
} while (x > 0 && x < n || y > 0 && y < m);
for (int i = 0; i < k; i++) {
out.println(ans[i] != Long.MAX_VALUE ? ans[i] : -1);
}
}
static class Line {
final int slope;
final int intercept;
Line(int slope, int intercept) {
this.slope = slope;
this.intercept = intercept;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TaskC.Line line = (TaskC.Line) o;
if (slope != line.slope) return false;
return intercept == line.intercept;
}
public int hashCode() {
int result = slope;
result = 31 * result + intercept;
return result;
}
}
}
static class FastScanner {
private final static int BUFFER_SIZE = 4096;
private final InputStream in;
private byte[] buffer = new byte[BUFFER_SIZE];
private int pos = 0;
private int size;
public FastScanner(InputStream inputStream) throws IOException {
in = inputStream;
size = 0;
}
public int nextInt() {
int c = skipWhitespace();
int sign = -1;
if (c == '-') {
sign = 1;
c = read();
}
int ans = 0;
while (c > ' ') {
ans *= 10;
ans -= c - '0';
c = read();
}
return sign * ans;
}
public int[] nextInts(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = nextInt();
}
return res;
}
public int[][] nextInts(int n, int m) {
int[][] res = new int[n][m];
for (int i = 0; i < n; i++) {
res[i] = nextInts(m);
}
return res;
}
private int skipWhitespace() {
while (true) {
int c = read();
if (c > ' ' || c == -1) {
return c;
}
}
}
private int read() {
if (pos >= size) {
try {
size = in.read(buffer, 0, BUFFER_SIZE);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (size <= 0) {
return -1;
}
pos = 0;
}
return buffer[pos++];
}
}
}
| Java | ["3 3 4\n1 1\n1 2\n2 1\n2 2", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3"] | 2 seconds | ["1\n-1\n-1\n2", "1\n-1\n-1\n2\n5\n-1", "13\n2\n9\n5\n-1"] | NoteIn the first sample, the ray will consequently pass through the points (0,β0), (1,β1), (2,β2), (3,β3). Thus, it will stop at the point (3,β3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0,β0), (1,β1), (2,β2), (3,β3), (2,β4), (1,β3), (0,β2), (1,β1), (2,β0), (3,β1), (2,β2), (1,β3), (0,β4). The ray will stop at the point (0,β4) after 12 seconds. It will reflect at the points (3,β3), (2,β4), (0,β2), (2,β0) and (3,β1). | Java 8 | standard input | [
"hashing",
"greedy",
"number theory",
"math",
"implementation",
"sortings"
] | 27a521d4d59066e50e870e7934d4b190 | The first line of the input contains three integers n, m and k (2ββ€βn,βmββ€β100β000, 1ββ€βkββ€β100β000)Β β lengths of the room's walls and the number of sensors. Each of the following k lines contains two integers xi and yi (1ββ€βxiββ€βnβ-β1, 1ββ€βyiββ€βmβ-β1)Β β coordinates of the sensors. It's guaranteed that no two sensors are located at the same point. | 1,800 | Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or β-β1 if this will never happen. | standard output | |
PASSED | a34f1e145c9853ae74b685483d56a2bc | train_002.jsonl | 1475928900 | There are k sensors located in the rectangular room of size nβΓβm meters. The i-th sensor is located at point (xi,βyi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0,β0) and (n,βm). Walls of the room are parallel to coordinate axes.At the moment 0, from the point (0,β0) the laser ray is released in the direction of point (1,β1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1,β1) in exactly one second after the start.When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print β-β1 for such sensors. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileWriter;
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.List;
import java.util.TreeMap;
import java.util.TreeSet;
public class Main {
static ContestScanner in;static Writer out;public static void main(String[] args)
{try{in=new ContestScanner();out=new Writer();Main solve=new Main();solve.solve();
in.close();out.flush();out.close();}catch(IOException e){e.printStackTrace();}}
static void dump(int[]a){StringBuilder s=new StringBuilder();for(int i=0;i<a.length;i++)
s.append(a[i]).append(" ");out.println(s.toString().trim());}
static void dump(int[]a,int n){for(int i=0;i<a.length;i++)out.printf("%"+n+"d ",a[i]);out.println();}
static void dump(long[]a){StringBuilder s=new StringBuilder();for(int i=0;i<a.length;i++)
s.append(a[i]).append(" ");out.println(s.toString().trim());}
static void dump(char[]a){for(int i=0;i<a.length;i++)out.print(a[i]);out.println();}
static long pow(long a,int n){long r=1;while(n>0){if((n&1)==1)r*=a;a*=a;n>>=1;}return r;}
static String itob(int a,int l){return String.format("%"+l+"s",Integer.toBinaryString(a)).replace(' ','0');}
static void sort(int[]a){m_sort(a,0,a.length,new int[a.length]);}
static void sort(int[]a,int l){m_sort(a,0,l,new int[l]);}
static void sort(int[]a,int l,int[]buf){m_sort(a,0,l,buf);}
static void sort(int[]a,int s,int l,int[]buf){m_sort(a,s,l,buf);}
static void m_sort(int[]a,int s,int sz,int[]b)
{if(sz<7){for(int i=s;i<s+sz;i++)for(int j=i;j>s&&a[j-1]>a[j];j--)swap(a, j, j-1);return;}
m_sort(a,s,sz/2,b);m_sort(a,s+sz/2,sz-sz/2,b);int idx=s;int l=s,r=s+sz/2;final int le=s+sz/2,re=s+sz;
while(l<le&&r<re){if(a[l]>a[r])b[idx++]=a[r++];else b[idx++]=a[l++];}
while(r<re)b[idx++]=a[r++];while(l<le)b[idx++]=a[l++];for(int i=s;i<s+sz;i++)a[i]=b[i];
} /* qsort(3.5s)<<msort(9.5s)<<<shuffle+qsort(17s)<Arrays.sort(Integer)(20s) */
static void sort(long[]a){m_sort(a,0,a.length,new long[a.length]);}
static void sort(long[]a,int l){m_sort(a,0,l,new long[l]);}
static void sort(long[]a,int l,long[]buf){m_sort(a,0,l,buf);}
static void sort(long[]a,int s,int l,long[]buf){m_sort(a,s,l,buf);}
static void m_sort(long[]a,int s,int sz,long[]b)
{if(sz<7){for(int i=s;i<s+sz;i++)for(int j=i;j>s&&a[j-1]>a[j];j--)swap(a, j, j-1);return;}
m_sort(a,s,sz/2,b);m_sort(a,s+sz/2,sz-sz/2,b);int idx=s;int l=s,r=s+sz/2;final int le=s+sz/2,re=s+sz;
while(l<le&&r<re){if(a[l]>a[r])b[idx++]=a[r++];else b[idx++]=a[l++];}
while(r<re)b[idx++]=a[r++];while(l<le)b[idx++]=a[l++];for(int i=s;i<s+sz;i++)a[i]=b[i];}
static void swap(long[] a,int i,int j){final long t=a[i];a[i]=a[j];a[j]=t;}
static void swap(int[] a,int i,int j){final int t=a[i];a[i]=a[j];a[j]=t;}
static int binarySearchSmallerMax(int[]a,int v)// get maximum index which a[idx]<=v
{int l=-1,r=a.length-1,s=0;while(l<=r){int m=(l+r)/2;if(a[m]>v)r=m-1;else{l=m+1;s=m;}}return s;}
static int binarySearchSmallerMax(int[]a,int v,int l,int r)
{int s=-1;while(l<=r){int m=(l+r)/2;if(a[m]>v)r=m-1;else{l=m+1;s=m;}}return s;}
@SuppressWarnings("unchecked")
static List<Integer>[]createGraph(int n)
{List<Integer>[]g=new List[n];for(int i=0;i<n;i++)g[i]=new ArrayList<>();return g;}
void solve() throws IOException{
int w = in.nextInt();
int h = in.nextInt();
int k = in.nextInt();
TreeMap<Integer, List<Integer>> map = new TreeMap<>();
long[] ans = new long[k];
int[] X = new int[k];
int[] Y = new int[k];
Arrays.fill(ans, -1);
for(int i=0; i<k; i++){
int x = in.nextInt();
int y = in.nextInt();
X[i] = x;
Y[i] = y;
int upper = (x+y<<1)+1;
int lower = (x-y<<1);
if(map.containsKey(upper)){
map.get(upper).add(i);
}else{
List<Integer> list = new ArrayList<>();
list.add(i);
map.put(upper, list);
}
if(map.containsKey(lower)){
map.get(lower).add(i);
}else{
List<Integer> list = new ArrayList<>();
list.add(i);
map.put(lower, list);
}
}
TreeSet<Integer> used = new TreeSet<>();
int status = 0;
int y = 0;
int x = 0;
int dx = 1;
int dy = 1;
long time = 0;
while(true){
if(used.contains(status)) break;
used.add(status);
if(map.containsKey(status)){
for(int i: map.get(status)){
if(ans[i]==-1) ans[i] = time+Math.abs(x-X[i]);
}
}
int distX, distY;
if(dx==1){
distX = w-x;
}else{
distX = x;
}
if(dy==1){
distY = h-y;
}else{
distY = y;
}
int dist;
int ndy = dy, ndx = dx;
if(distX>distY){
dist = distY;
ndy = -dy;
}else{
dist = distX;
ndx = -dx;
}
y += dist*dy;
x += dist*dx;
dx = ndx;
dy = ndy;
time += dist;
if(dy*dx<0){
status = (x+y<<1)+1;
}else{
status = (x-y<<1);
}
}
for(int i=0; i<ans.length; i++){
out.println(ans[i]);
}
}
}
@SuppressWarnings("serial")
class MultiSet<T> extends HashMap<T, Integer>{
@Override public Integer get(Object key){return containsKey(key)?super.get(key):0;}
public void add(T key,int v){put(key,get(key)+v);}
public void add(T key){put(key,get(key)+1);}
public void sub(T key){final int v=get(key);if(v==1)remove(key);else put(key,v-1);}
public MultiSet<T> merge(MultiSet<T> set)
{MultiSet<T>s,l;if(this.size()<set.size()){s=this;l=set;}else{s=set;l=this;}
for(Entry<T,Integer>e:s.entrySet())l.add(e.getKey(),e.getValue());return l;}
}
@SuppressWarnings("serial")
class OrderedMultiSet<T> extends TreeMap<T, Integer>{
@Override public Integer get(Object key){return containsKey(key)?super.get(key):0;}
public void add(T key,int v){put(key,get(key)+v);}
public void add(T key){put(key,get(key)+1);}
public void sub(T key){final int v=get(key);if(v==1)remove(key);else put(key,v-1);}
public OrderedMultiSet<T> merge(OrderedMultiSet<T> set)
{OrderedMultiSet<T>s,l;if(this.size()<set.size()){s=this;l=set;}else{s=set;l=this;}
while(!s.isEmpty()){l.add(s.firstEntry().getKey(),s.pollFirstEntry().getValue());}return l;}
}
class Pair implements Comparable<Pair>{
int a,b;final int hash;Pair(int a,int b){this.a=a;this.b=b;hash=(a<<16|a>>16)^b;}
public boolean equals(Object obj){Pair o=(Pair)(obj);return a==o.a&&b==o.b;}
public int hashCode(){return hash;}
public int compareTo(Pair o){if(a!=o.a)return a<o.a?-1:1;else if(b!=o.b)return b<o.b?-1:1;return 0;}
}
class Timer{
long time;public void set(){time=System.currentTimeMillis();}
public long stop(){return time=System.currentTimeMillis()-time;}
public void print(){System.out.println("Time: "+(System.currentTimeMillis()-time)+"ms");}
@Override public String toString(){return"Time: "+time+"ms";}
}
class Writer extends PrintWriter{
public Writer(String filename)throws IOException
{super(new BufferedWriter(new FileWriter(filename)));}
public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
private BufferedReader in;private int c=-2;
public ContestScanner()throws IOException
{in=new BufferedReader(new InputStreamReader(System.in));}
public ContestScanner(String filename)throws IOException
{in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
public String nextToken()throws IOException {
StringBuilder sb=new StringBuilder();
while((c=in.read())!=-1&&Character.isWhitespace(c));
while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
return sb.toString();
}
public String readLine()throws IOException{
StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
return sb.toString();
}
public long nextLong()throws IOException,NumberFormatException
{return Long.parseLong(nextToken());}
public int nextInt()throws NumberFormatException,IOException
{return(int)nextLong();}
public double nextDouble()throws NumberFormatException,IOException
{return Double.parseDouble(nextToken());}
public void close() throws IOException {in.close();}
} | Java | ["3 3 4\n1 1\n1 2\n2 1\n2 2", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3"] | 2 seconds | ["1\n-1\n-1\n2", "1\n-1\n-1\n2\n5\n-1", "13\n2\n9\n5\n-1"] | NoteIn the first sample, the ray will consequently pass through the points (0,β0), (1,β1), (2,β2), (3,β3). Thus, it will stop at the point (3,β3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0,β0), (1,β1), (2,β2), (3,β3), (2,β4), (1,β3), (0,β2), (1,β1), (2,β0), (3,β1), (2,β2), (1,β3), (0,β4). The ray will stop at the point (0,β4) after 12 seconds. It will reflect at the points (3,β3), (2,β4), (0,β2), (2,β0) and (3,β1). | Java 8 | standard input | [
"hashing",
"greedy",
"number theory",
"math",
"implementation",
"sortings"
] | 27a521d4d59066e50e870e7934d4b190 | The first line of the input contains three integers n, m and k (2ββ€βn,βmββ€β100β000, 1ββ€βkββ€β100β000)Β β lengths of the room's walls and the number of sensors. Each of the following k lines contains two integers xi and yi (1ββ€βxiββ€βnβ-β1, 1ββ€βyiββ€βmβ-β1)Β β coordinates of the sensors. It's guaranteed that no two sensors are located at the same point. | 1,800 | Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or β-β1 if this will never happen. | standard output | |
PASSED | 3c5197e095033a9abd6065172a9096d5 | train_002.jsonl | 1475928900 | There are k sensors located in the rectangular room of size nβΓβm meters. The i-th sensor is located at point (xi,βyi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0,β0) and (n,βm). Walls of the room are parallel to coordinate axes.At the moment 0, from the point (0,β0) the laser ray is released in the direction of point (1,β1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1,β1) in exactly one second after the start.When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print β-β1 for such sensors. | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
@SuppressWarnings("unchecked")
public static void solution(BufferedReader reader, PrintWriter out)
throws IOException {
In in = new In(reader);
int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
int[][] point = new int[k][2];
for (int i = 0; i < k; i++)
point[i] = new int[] { in.nextInt(), in.nextInt() };
ArrayList<Integer>[] sumList = new ArrayList[n + m + 1];
for (int i = 0; i <= n + m; i++)
sumList[i] = new ArrayList<Integer>();
int shift = Math.max(n, m);
ArrayList<Integer>[] subList = new ArrayList[shift + shift + 1];
for (int i = 0; i <= shift + shift; i++)
subList[i] = new ArrayList<Integer>();
for (int i = 0; i < k; i++) {
sumList[point[i][0] + point[i][1]].add(i);
subList[point[i][0] - point[i][1] + shift].add(i);
}
int[] pre = new int[] { 0, 0 };
int d = 0;
int[] nChange = new int[] { 1, 1, -1, -1 };
int[] mChange = new int[] { 1, -1, -1, 1 };
boolean[] sumCheck = new boolean[n + m + 1];
boolean[] subCheck = new boolean[shift + shift + 1];
long[] rst = new long[k];
Arrays.fill(rst, -1);
long time = 0;
while (true) {
int nToGo = nChange[d] == 1 ? n - pre[0] : pre[0];
int mToGo = mChange[d] == 1 ? m - pre[1] : pre[1];
int move = Math.min(nToGo, mToGo);
int[] next = new int[] { pre[0] + nChange[d] * move,
pre[1] + mChange[d] * move };
if (pre[0] == next[0] && pre[1] == next[1])
break;
if (pre[0] + pre[1] == next[0] + next[1]) {
int sum = pre[0] + pre[1];
if (sumCheck[sum])
break;
sumCheck[sum] = true;
for (Integer i : sumList[sum])
if (rst[i] == -1)
rst[i] = time + Math.abs(point[i][0] - pre[0]);
}
else if (pre[0] - pre[1] == next[0] - next[1]) {
int sub = pre[0] - pre[1] + shift;
if (subCheck[sub])
break;
subCheck[sub] = true;
for (Integer i : subList[sub])
if (rst[i] == -1)
rst[i] = time + Math.abs(point[i][0] - pre[0]);
}
time += move;
if (next[1] == 0 || next[1] == m)
d ^= 1;
else if (next[0] == 0 || next[0] == n)
d ^= 3;
pre = next;
}
for (int i = 0; i < k; i++)
out.println(rst[i]);
}
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(
new BufferedWriter(new OutputStreamWriter(System.out)));
solution(reader, out);
out.close();
}
protected static class In {
private BufferedReader reader;
private StringTokenizer tokenizer = new StringTokenizer("");
public In(BufferedReader reader) {
this.reader = reader;
}
public String next() throws IOException {
while (!tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
return tokenizer.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
}
}
| Java | ["3 3 4\n1 1\n1 2\n2 1\n2 2", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3"] | 2 seconds | ["1\n-1\n-1\n2", "1\n-1\n-1\n2\n5\n-1", "13\n2\n9\n5\n-1"] | NoteIn the first sample, the ray will consequently pass through the points (0,β0), (1,β1), (2,β2), (3,β3). Thus, it will stop at the point (3,β3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0,β0), (1,β1), (2,β2), (3,β3), (2,β4), (1,β3), (0,β2), (1,β1), (2,β0), (3,β1), (2,β2), (1,β3), (0,β4). The ray will stop at the point (0,β4) after 12 seconds. It will reflect at the points (3,β3), (2,β4), (0,β2), (2,β0) and (3,β1). | Java 8 | standard input | [
"hashing",
"greedy",
"number theory",
"math",
"implementation",
"sortings"
] | 27a521d4d59066e50e870e7934d4b190 | The first line of the input contains three integers n, m and k (2ββ€βn,βmββ€β100β000, 1ββ€βkββ€β100β000)Β β lengths of the room's walls and the number of sensors. Each of the following k lines contains two integers xi and yi (1ββ€βxiββ€βnβ-β1, 1ββ€βyiββ€βmβ-β1)Β β coordinates of the sensors. It's guaranteed that no two sensors are located at the same point. | 1,800 | Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or β-β1 if this will never happen. | standard output | |
PASSED | 18d2f7b041872957da247a7a42a13492 | train_002.jsonl | 1475928900 | There are k sensors located in the rectangular room of size nβΓβm meters. The i-th sensor is located at point (xi,βyi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0,β0) and (n,βm). Walls of the room are parallel to coordinate axes.At the moment 0, from the point (0,β0) the laser ray is released in the direction of point (1,β1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1,β1) in exactly one second after the start.When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print β-β1 for such sensors. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;
public class IntelDiv2C {
static class Line{
int k,b,px1,py1,px2,py2;
long t;
public Line(int kk,int bb,int px11,int py11,int px22,int py22,long tt){
k=kk;
b=bb;
px1=px11;
py1=py11;
px2=px22;
py2=py22;
t=tt;
}
}
public static void main(String[] args){
FastScanner in=new FastScanner();
int n=in.nextInt();
int m=in.nextInt();
int k=in.nextInt();
int[] px=new int[Math.max(n,m)*2+1];
int[] py=new int[Math.max(n,m)*2+1];
int p=0;
px[p]=0;
py[p]=0;
boolean xflg=true,yflg=true;
for(int x=0,y=0;;){
if(x==n)
xflg=false;
else if(x==0)
xflg=true;
if(y==m)
yflg=false;
else if(y==0)
yflg=true;
if(xflg&&yflg){
if(n-x<m-y){
p++;
px[p]=n;
py[p]=y+(n-x);
y+=n-x;
x=n;
}else if(n-x>m-y){
p++;
px[p]=x+(m-y);
py[p]=m;
x+=m-y;
y=m;
}else{
p++;
px[p]=n;
py[p]=m;
x=n;
y=m;
}
}else if(xflg&&!yflg){
if(n-x<y-0){
p++;
px[p]=n;
py[p]=y-(n-x);
y-=n-x;
x=n;
}else if(n-x>y-0){
p++;
px[p]=x+y;
py[p]=0;
x+=y;
y=0;
}else{
p++;
px[p]=n;
py[p]=0;
x=n;
y=0;
}
}else if(!xflg&&yflg){
if(x-0>m-y){
p++;
px[p]=x-(m-y);
py[p]=m;
x-=m-y;
y=m;
}else if(x-0<m-y){
p++;
px[p]=0;
py[p]=y+x;
y+=x;
x=0;
}else{
p++;
px[p]=0;
py[p]=m;
x=0;
y=m;
}
}else if(!xflg&&!yflg){
if(x-0>y-0){
p++;
px[p]=x-y;
py[p]=0;
x-=y;
y=0;
}else if(x-0<y-0){
p++;
px[p]=0;
py[p]=y-x;
y-=x;
x=0;
}else{
p++;
px[p]=0;
py[p]=0;
x=0;
y=0;
}
}
if((x==0||x==n)&&(y==0||y==m))
break;
}
Line[] f=new Line[p];
HashMap<Integer,HashMap<Integer,Line>> map=new HashMap<Integer,HashMap<Integer,Line>>(p);
for(int i=0;i<p;++i){
int kk=(py[i+1]-py[i])/(px[i+1]-px[i]);
int bb=py[i]-px[i]*kk;
f[i]=new Line(kk,bb,px[i],py[i],px[i+1],py[i+1],i==0?0:(Math.abs(py[i]-py[i-1])+f[i-1].t));
if(!map.containsKey(kk))
map.put(kk,new HashMap<Integer,Line>());
map.get(kk).put(bb,f[i]);
}
PrintWriter out=new PrintWriter(System.out);
for(int i=0;i<k;++i){
int x=in.nextInt();
int y=in.nextInt();
int kk1=Integer.MAX_VALUE,bb1=Integer.MAX_VALUE,kk2=Integer.MAX_VALUE,bb2=Integer.MAX_VALUE;
int x1,y1,x2,y2;
if(x==0&&y==0||x==n&&y==m){
kk1=1;
bb1=0;
}else if(x==0&&y==m||x==n&&y==0){
kk1=-1;
bb1=0;
}else{
if(x==0){
if(n-x<m-y){
x1=n;
y1=y+(n-x);
}else if(n-x>m-y){
x1=x+(m-y);
y1=m;
}else{
x1=n;
y1=m;
}
if(n-x<y-0){
x2=n;
y2=y-(n-x);
}else if(n-x>y-0){
x2=x+y;
y2=0;
}else{
x2=n;
y2=0;
}
}else if(y==0){
if(n-x<m-y){
x1=n;
y1=y+(n-x);
}else if(n-x>m-y){
x1=x+(m-y);
y1=m;
}else{
x1=n;
y1=m;
}
if(x-0>m-y){
x2=x-(m-y);
y2=m;
}else if(x-0<m-y){
x2=0;
y2=y+x;
}else{
x2=0;
y2=m;
}
}else if(x==n){
if(x-0>m-y){
x1=x-(m-y);
y1=m;
}else if(x-0<m-y){
x1=0;
y1=y+x;
}else{
x1=0;
y1=m;
}
if(x-0>y-0){
x2=x-y;
y2=0;
}else if(x-0<y-0){
x2=0;
y2=y-x;
}else{
x2=0;
y2=0;
}
}else if(y==m){
if(x-0>y-0){
x1=x-y;
y1=0;
}else if(x-0<y-0){
x1=0;
y1=y-x;
}else{
x1=0;
y1=0;
}
if(n-x<y-0){
x2=n;
y2=y-(n-x);
}else if(n-x>y-0){
x2=x+y;
y2=0;
}else{
x2=n;
y2=0;
}
}else{
if(n-x<m-y){
x1=n;
y1=y+(n-x);
}else if(n-x>m-y){
x1=x+(m-y);
y1=m;
}else{
x1=n;
y1=m;
}
if(n-x<y-0){
x2=n;
y2=y-(n-x);
}else if(n-x>y-0){
x2=x+y;
y2=0;
}else{
x2=n;
y2=0;
}
kk1=(y1-y)/(x1-x);
bb1=y1-x1*kk1;
kk2=(y2-y)/(x2-x);
bb2=y2-x2*kk2;
}
if(map.containsKey(kk1)&&map.get(kk1).containsKey(bb1)&&map.containsKey(kk2)&&map.get(kk2).containsKey(bb2)){
Line line1=map.get(kk1).get(bb1);
Line line2=map.get(kk2).get(bb2);
out.println(Math.min(line1.t+Math.abs(line1.px1-x),line2.t+Math.abs(line2.px1-x)));
}else if(map.containsKey(kk1)&&map.get(kk1).containsKey(bb1)){
Line line=map.get(kk1).get(bb1);
out.println(line.t+Math.abs(line.px1-x));
}else if(map.containsKey(kk2)&&map.get(kk2).containsKey(bb2)){
Line line=map.get(kk2).get(bb2);
out.println(line.t+Math.abs(line.px1-x));
}else{
out.println(-1);
}
}
}
out.flush();
out.close();
}
static class FastScanner{
BufferedReader br;
StringTokenizer st;
public FastScanner()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String nextToken()
{
while(st==null||!st.hasMoreElements())
try
{
st=new StringTokenizer(br.readLine());
}catch(Exception e)
{
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(nextToken());
}
long nextLong()
{
return Long.parseLong(nextToken());
}
double nextDouble()
{
return Double.parseDouble(nextToken());
}
}
}
| Java | ["3 3 4\n1 1\n1 2\n2 1\n2 2", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3"] | 2 seconds | ["1\n-1\n-1\n2", "1\n-1\n-1\n2\n5\n-1", "13\n2\n9\n5\n-1"] | NoteIn the first sample, the ray will consequently pass through the points (0,β0), (1,β1), (2,β2), (3,β3). Thus, it will stop at the point (3,β3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0,β0), (1,β1), (2,β2), (3,β3), (2,β4), (1,β3), (0,β2), (1,β1), (2,β0), (3,β1), (2,β2), (1,β3), (0,β4). The ray will stop at the point (0,β4) after 12 seconds. It will reflect at the points (3,β3), (2,β4), (0,β2), (2,β0) and (3,β1). | Java 8 | standard input | [
"hashing",
"greedy",
"number theory",
"math",
"implementation",
"sortings"
] | 27a521d4d59066e50e870e7934d4b190 | The first line of the input contains three integers n, m and k (2ββ€βn,βmββ€β100β000, 1ββ€βkββ€β100β000)Β β lengths of the room's walls and the number of sensors. Each of the following k lines contains two integers xi and yi (1ββ€βxiββ€βnβ-β1, 1ββ€βyiββ€βmβ-β1)Β β coordinates of the sensors. It's guaranteed that no two sensors are located at the same point. | 1,800 | Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or β-β1 if this will never happen. | standard output | |
PASSED | 83598264c6f483faf057c779ec979ba3 | train_002.jsonl | 1475928900 | There are k sensors located in the rectangular room of size nβΓβm meters. The i-th sensor is located at point (xi,βyi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0,β0) and (n,βm). Walls of the room are parallel to coordinate axes.At the moment 0, from the point (0,β0) the laser ray is released in the direction of point (1,β1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1,β1) in exactly one second after the start.When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print β-β1 for such sensors. | 256 megabytes |
import java.io.*;
import java.math.*;
import java.util.*;
import static java.util.Arrays.*;
public class C {
private static final int mod = (int)1e9+7;
final Random random = new Random(0);
final IOFast io = new IOFast();
/// MAIN CODE
public void run() throws IOException {
// int TEST_CASE = Integer.parseInt(new String(io.nextLine()).trim());
int TEST_CASE = 1;
while(TEST_CASE-- != 0) {
int w = io.nextInt();
int h = io.nextInt();
int K = io.nextInt();
int[][] pos = io.nextIntArray2D(K, 2);
long[][][] vis = new long[2][w+h][2];
for(long[][] a : vis) for(long[] b : a) b[1] = -1;
int dx = 1, dy = 1;
// dump(0, 0, -1);
long t = 0;
for(int x = 0, y = 0; ; ) {
int x1 = x;
int y1 = y;
int d = 1<<29;
if(dx > 0) d = Math.min(d, w-x);
if(dx < 0) d = Math.min(d, x);
if(dy > 0) d = Math.min(d, h-y);
if(dy < 0) d = Math.min(d, y);
x += d*dx;
y += d*dy;
// if(!(x%w != 0 && y%h != 0)) {
// break;
// }
int x2 = x;
int y2 = y;
if(dx*dy == 1) {
int xx = dx < 0 ? x2 : x1;
int yy = dx < 0 ? y2 : y1;
if(vis[0][xx-yy+h-1][1] == -1) {
vis[0][xx-yy+h-1][0] = t;
vis[0][xx-yy+h-1][1] = dx > 0 ? 0 : 1;
// dump(t, xx, yy, vis[0][xx-yy+h-1][1]);
}
} else {
int xx = dx < 0 ? x2 : x1;
int yy = dx < 0 ? y2 : y1;
if(vis[1][xx+yy][1] == -1) {
vis[1][xx+yy][0] = t;
vis[1][xx+yy][1] = dx > 0 ? 2 : 3;
// dump(t, xx, yy, vis[1][xx+yy][1]);
}
}
t += d;
// dump(x, y, i);
if(x%w == 0 && y%h == 0) {
break;
}
if(x % w == 0) dx = -dx;
if(y % h == 0) dy = -dy;
}
// dump(tt);
// dump(idx);
for(int[] p : pos) {
long tt = 1L<<60;
int xx = p[0];
int yy = p[1];
if(vis[0][xx-yy+h-1][1] == 0) {
tt = Math.min(tt, vis[0][xx-yy+h-1][0] + Math.min(xx, yy));
// dump(0, tt);
}
if(vis[0][xx-yy+h-1][1] == 1) {
tt = Math.min(tt, vis[0][xx-yy+h-1][0] + Math.min(w-xx, h-yy));
// dump(1, tt);
}
if(vis[1][xx+yy][1] == 2) {
tt = Math.min(tt, vis[1][xx+yy][0] + Math.min(xx, h-yy));
// dump(2, tt);
}
if(vis[1][xx+yy][1] == 3) {
tt = Math.min(tt, vis[1][xx+yy][0] + Math.min(w-xx, yy));
// dump(3, tt);
}
io.out.println(tt >= 1L<<60 ? -1 : tt);
}
}
}
/// TEMPLATE
static int gcd(int n, int r) { return r == 0 ? n : gcd(r, n%r); }
static long gcd(long n, long r) { return r == 0 ? n : gcd(r, n%r); }
static <T> void swap(T[] x, int i, int j) { T t = x[i]; x[i] = x[j]; x[j] = t; }
static void swap(int[] x, int i, int j) { int t = x[i]; x[i] = x[j]; x[j] = t; }
void printArrayLn(int[] xs) { for(int i = 0; i < xs.length; i++) io.out.print(xs[i] + (i==xs.length-1?"\n":" ")); }
void printArrayLn(long[] xs) { for(int i = 0; i < xs.length; i++) io.out.print(xs[i] + (i==xs.length-1?"\n":" ")); }
static void dump(Object... o) { System.err.println(Arrays.deepToString(o)); }
void main() throws IOException {
// IOFast.setFileIO("rle-size.in", "rle-size.out");
try { run(); }
catch (EndOfFileRuntimeException e) { }
io.out.flush();
}
public static void main(String[] args) throws IOException { new C().main(); }
static class EndOfFileRuntimeException extends RuntimeException {
private static final long serialVersionUID = -8565341110209207657L; }
static
public class IOFast {
private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
private PrintWriter out = new PrintWriter(System.out);
void setFileIn(String ins) throws IOException { in.close(); in = new BufferedReader(new FileReader(ins)); }
void setFileOut(String outs) throws IOException { out.flush(); out.close(); out = new PrintWriter(new FileWriter(outs)); }
void setFileIO(String ins, String outs) throws IOException { setFileIn(ins); setFileOut(outs); }
private static int pos, readLen;
private static final char[] buffer = new char[1024 * 8];
private static char[] str = new char[500*8*2];
private static boolean[] isDigit = new boolean[256];
private static boolean[] isSpace = new boolean[256];
private static boolean[] isLineSep = new boolean[256];
static { for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; } isDigit['-'] = true; isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true; isLineSep['\r'] = isLineSep['\n'] = true; }
public int read() throws IOException { if(pos >= readLen) { pos = 0; readLen = in.read(buffer); if(readLen <= 0) { throw new EndOfFileRuntimeException(); } } return buffer[pos++]; }
public int nextInt() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; int ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; }
public long nextLong() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; long ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; }
public char nextChar() throws IOException { while(true) { final int c = read(); if(!isSpace[c]) { return (char)c; } } }
int reads(int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } if(str.length == len) { char[] rep = new char[str.length * 3 / 2]; System.arraycopy(str, 0, rep, 0, str.length); str = rep; } str[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; }
int reads(char[] cs, int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } cs[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; }
public char[] nextLine() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isLineSep); try { if(str[len-1] == '\r') { len--; read(); } } catch(EndOfFileRuntimeException e) { ; } return Arrays.copyOf(str, len); }
public String nextString() throws IOException { return new String(next()); }
public char[] next() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); return Arrays.copyOf(str, len); }
// public int next(char[] cs) throws IOException { int len = 0; cs[len++] = nextChar(); len = reads(cs, len, isSpace); return len; }
public double nextDouble() throws IOException { return Double.parseDouble(nextString()); }
public long[] nextLongArray(final int n) throws IOException { final long[] res = new long[n]; for(int i = 0; i < n; i++) { res[i] = nextLong(); } return res; }
public int[] nextIntArray(final int n) throws IOException { final int[] res = new int[n]; for(int i = 0; i < n; i++) { res[i] = nextInt(); } return res; }
public int[][] nextIntArray2D(final int n, final int k) throws IOException { final int[][] res = new int[n][]; for(int i = 0; i < n; i++) { res[i] = nextIntArray(k); } return res; }
public int[][] nextIntArray2DWithIndex(final int n, final int k) throws IOException { final int[][] res = new int[n][k+1]; for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { res[i][j] = nextInt(); } res[i][k] = i; } return res; }
public double[] nextDoubleArray(final int n) throws IOException { final double[] res = new double[n]; for(int i = 0; i < n; i++) { res[i] = nextDouble(); } return res; }
}
}
| Java | ["3 3 4\n1 1\n1 2\n2 1\n2 2", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3"] | 2 seconds | ["1\n-1\n-1\n2", "1\n-1\n-1\n2\n5\n-1", "13\n2\n9\n5\n-1"] | NoteIn the first sample, the ray will consequently pass through the points (0,β0), (1,β1), (2,β2), (3,β3). Thus, it will stop at the point (3,β3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0,β0), (1,β1), (2,β2), (3,β3), (2,β4), (1,β3), (0,β2), (1,β1), (2,β0), (3,β1), (2,β2), (1,β3), (0,β4). The ray will stop at the point (0,β4) after 12 seconds. It will reflect at the points (3,β3), (2,β4), (0,β2), (2,β0) and (3,β1). | Java 8 | standard input | [
"hashing",
"greedy",
"number theory",
"math",
"implementation",
"sortings"
] | 27a521d4d59066e50e870e7934d4b190 | The first line of the input contains three integers n, m and k (2ββ€βn,βmββ€β100β000, 1ββ€βkββ€β100β000)Β β lengths of the room's walls and the number of sensors. Each of the following k lines contains two integers xi and yi (1ββ€βxiββ€βnβ-β1, 1ββ€βyiββ€βmβ-β1)Β β coordinates of the sensors. It's guaranteed that no two sensors are located at the same point. | 1,800 | Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or β-β1 if this will never happen. | standard output | |
PASSED | 532c3bd4cc472f5c830c49fb221babae | train_002.jsonl | 1475928900 | There are k sensors located in the rectangular room of size nβΓβm meters. The i-th sensor is located at point (xi,βyi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0,β0) and (n,βm). Walls of the room are parallel to coordinate axes.At the moment 0, from the point (0,β0) the laser ray is released in the direction of point (1,β1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1,β1) in exactly one second after the start.When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print β-β1 for such sensors. | 256 megabytes |
import java.io.*;
import java.util.*;
/**
*
* @author Sourav Kumar Paul
*/
public class SolveC {
public static void fn0()
{
int tx=0,ty=0;
if(ptr==0)
{
int min = (n-xx < m-yy)? n-xx : m-yy;
tx = xx+min;
ty = yy+min;
if(marked.containsKey(xx+" "+yy+" "+tx+" "+ty))
flag = false;
if(tlr.containsKey(xx+" "+yy+" "+tx+" "+ty))
{
ArrayList<Integer> list = tlr.get(xx+" "+yy+" "+tx+" "+ty);
for(int i: list)
{
if(ans[i] == -1)
{
ans[i] = cost + (long)(px[i] - xx);
}
}
}
cost += (long)(tx-xx);
xx =tx;
yy =ty;
if(yy==m)
ptr =1;
else if(xx==n)
ptr = 3;
}
}
public static void fn1()
{
int min = Math.min(n-xx,yy);
int tx = xx+min;
int ty = yy-min;
if(marked.containsKey(xx+" "+yy+" "+tx+" "+ty))
flag = false;
if(lrt.containsKey(xx+" "+yy+" "+tx+" "+ty))
{
ArrayList<Integer> list = lrt.get(xx+" "+yy+" "+tx+" "+ty);
for(int i: list)
{
if(ans[i] == -1)
{
ans[i] = cost + (long)(px[i] - xx);
}
}
}
cost += (long)(tx-xx);
xx = tx;
yy = ty;
if(xx==n)
ptr =2;
else if(yy==0)
ptr =0;
}
public static void fn2()
{
int min = Math.min(xx,yy);
int tx = xx-min;
int ty = yy-min;
if(marked.containsKey(xx+" "+yy+" "+tx+" "+ty))
flag = false;
if(tlr.containsKey(xx+" "+yy+" "+tx+" "+ty))
{
ArrayList<Integer> list = tlr.get(xx+" "+yy+" "+tx+" "+ty);
for(int i: list)
{
if(ans[i] == -1)
{
ans[i] = cost + (long)(xx - px[i]) ;
}
}
}
cost += (long)(xx - tx);
xx = tx;
yy = ty;
if(yy==0)
ptr = 3;
else if(xx==0)
ptr =1;
}
public static void fn3()
{
int min = Math.min(xx, m-yy);
int tx = xx-min;
int ty = yy+min;
if(marked.containsKey(xx+" "+yy+" "+tx+" "+ty))
flag = false;
if(lrt.containsKey(xx+" "+yy+" "+tx+" "+ty))
{
ArrayList<Integer> list = lrt.get(xx+" "+yy+" "+tx+" "+ty);
for(int i: list)
{
if(ans[i] == -1)
{
ans[i] = cost + (long)(xx - px[i]) ;
}
}
}
cost += (long)(xx - tx);
xx = tx;
yy = ty;
if(xx==0)
ptr =0;
else if(yy==m)
ptr =2;
}
public static boolean flag ;
public static HashMap<String, Boolean> marked;
public static HashMap<String, ArrayList<Integer>> lrt, tlr;
public static int n,m,xx,yy,ptr,px[];
public static long cost,ans[];
public static void main(String[] args) throws IOException{
Reader in = new Reader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
n = in.nextInt();
m = in.nextInt();
int k = in.nextInt();
ans = new long[k];
Arrays.fill(ans,-1);
tlr = new HashMap<>();
lrt = new HashMap<>();
px = new int[k];
for(int i=0; i<k; i++)
{
int x = in.nextInt();
int y = in.nextInt();
px[i] = x;
int min = Math.min(x,y);
int tx = x-min;
int ty = y-min;
min = (n-x < m-y)? n-x : m-y;
int ttx = x+min;
int tty = y+min;
ArrayList<Integer> list = tlr.containsKey(tx+" "+ty+" "+ttx+" "+tty)? tlr.get(tx+" "+ty+" "+ttx+" "+tty) : new ArrayList<>();
list.add(i);
tlr.put(tx+" "+ty+" "+ttx+" "+tty, list);
list = tlr.containsKey(ttx+" "+tty+" "+tx+" "+ty)? tlr.get(ttx+" "+tty+" "+tx+" "+ty) : new ArrayList<>();
list.add(i);
tlr.put(ttx+" "+tty+" "+tx+" "+ty, list);
min = Math.min(x, m-y);
tx = x-min;
ty = y+min;
min = Math.min(n-x,y);
ttx = x+min;
tty = y-min;
list = lrt.containsKey(tx+" "+ty+" "+ttx+" "+tty)? lrt.get(tx+" "+ty+" "+ttx+" "+tty) : new ArrayList<>();
list.add(i);
lrt.put(tx+" "+ty+" "+ttx+" "+tty, list);
list = lrt.containsKey(ttx+" "+tty+" "+tx+" "+ty)? lrt.get(ttx+" "+tty+" "+tx+" "+ty) : new ArrayList<>();
list.add(i);
lrt.put(ttx+" "+tty+" "+tx+" "+ty, list);
}
// out.println("hello");
marked = new HashMap<>();
ptr = 0;
xx =0;yy=0;
flag = true;
cost = 0l;
while(flag)
{
//out.println(xx+" "+yy);
// out.println("hello"+tx+" "+ty);
if(ptr == 0)
fn0();
else if(ptr==1)
{
fn1();
}
else if(ptr ==2)
{
fn2();
}
else if(ptr ==3)
{
fn3();
}
// out.println(xx+" "+yy);
if((xx == 0 && yy==0) || (xx==n && yy ==m) || (xx==0 && yy==m) || (xx==n && yy==0))
break;
}
for(int i=0; i<k; i++)
{
out.println(ans[i]);
}
out.flush();
out.close();
}
public static class Reader {
public BufferedReader reader;
public StringTokenizer st;
public Reader(InputStreamReader stream) {
reader = new BufferedReader(stream);
st = null;
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public String nextLine() throws IOException{
return reader.readLine();
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
}
}
| Java | ["3 3 4\n1 1\n1 2\n2 1\n2 2", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3"] | 2 seconds | ["1\n-1\n-1\n2", "1\n-1\n-1\n2\n5\n-1", "13\n2\n9\n5\n-1"] | NoteIn the first sample, the ray will consequently pass through the points (0,β0), (1,β1), (2,β2), (3,β3). Thus, it will stop at the point (3,β3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0,β0), (1,β1), (2,β2), (3,β3), (2,β4), (1,β3), (0,β2), (1,β1), (2,β0), (3,β1), (2,β2), (1,β3), (0,β4). The ray will stop at the point (0,β4) after 12 seconds. It will reflect at the points (3,β3), (2,β4), (0,β2), (2,β0) and (3,β1). | Java 8 | standard input | [
"hashing",
"greedy",
"number theory",
"math",
"implementation",
"sortings"
] | 27a521d4d59066e50e870e7934d4b190 | The first line of the input contains three integers n, m and k (2ββ€βn,βmββ€β100β000, 1ββ€βkββ€β100β000)Β β lengths of the room's walls and the number of sensors. Each of the following k lines contains two integers xi and yi (1ββ€βxiββ€βnβ-β1, 1ββ€βyiββ€βmβ-β1)Β β coordinates of the sensors. It's guaranteed that no two sensors are located at the same point. | 1,800 | Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or β-β1 if this will never happen. | standard output | |
PASSED | 047f12fe8bc0c705842722d733c475b1 | train_002.jsonl | 1475928900 | There are k sensors located in the rectangular room of size nβΓβm meters. The i-th sensor is located at point (xi,βyi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0,β0) and (n,βm). Walls of the room are parallel to coordinate axes.At the moment 0, from the point (0,β0) the laser ray is released in the direction of point (1,β1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1,β1) in exactly one second after the start.When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print β-β1 for such sensors. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Main {
class Point{
int x;
int y;
long time = -1;
public Point(int x, int y){
this.x = x;
this.y = y;
}
public int plusIdx(){
return pIdx(x, y);
}
public int minusIdx(){
return mIdx(x, y);
}
}
int N;
int M;
int K;
Point[] points;
ArrayList<ArrayList<Point>> plus;
ArrayList<ArrayList<Point>> minus;
boolean[] pFlg;
boolean[] mFlg;
public void solve() {
N = nextInt();
M = nextInt();
K = nextInt();
points = new Point[K];
plus = new ArrayList<>(200020);
pFlg = new boolean[200020];
minus = new ArrayList<>(200020);
mFlg = new boolean[200020];
for(int i = 0; i < 200020; i++){
plus.add(new ArrayList<>());
minus.add(new ArrayList<>());
}
for(int i = 0; i < K; i++){
points[i] = new Point(nextInt(), nextInt());
plus.get(points[i].plusIdx()).add(points[i]);
minus.get(points[i].minusIdx()).add(points[i]);
}
int cx = 0;
int cy = 0;
long time = 0;
while(true){
{
int mi = mIdx(cx, cy);
if(mFlg[mi]) break;
mFlg[mi] = true;
if(cx == 0 || cy == 0){
for(Point p : minus.get(mi)){
if(p.time == -1){
p.time = time + p.x - cx;
}
}
if(N - cx < M - cy){
time += (N - cx);
cy = cy + (N - cx);
cx = N;
}else{
time += (M - cy);
cx = cx + (M - cy);
cy = M;
}
}else{
for(Point p : minus.get(mi)){
if(p.time == -1){
p.time = time + cx - p.x;
}
}
if(cx < cy){
time += cx;
cy = cy - cx;
cx = 0;
}else{
time += cy;
cx = cx - cy;
cy = 0;
}
}
if((cx == 0 && cy == 0) || (cx == N && cy == M)) break;
}
{
int pi = pIdx(cx, cy);
if(pFlg[pi]) break;
pFlg[pi] = true;
if(cx == 0 || cy == M){
for(Point p : plus.get(pi)){
if(p.time == -1){
p.time = time + p.x - cx;
}
}
if(N - cx < cy){
time += (N - cx);
cy = cy - (N - cx);
cx = N;
}else{
time += cy;
cx = cx + cy;
cy = 0;
}
}else{
for(Point p : plus.get(pi)){
if(p.time == -1){
p.time = time + cx - p.x;
}
}
if(cx < M - cy){
time += cx;
cy = cy + cx;
cx = 0;
}else{
time += (M - cy);
cx = cx - (M - cy);
cy = M;
}
}
if((cx == 0 && cy == M) || (cx == N && cy == 0)) break;
}
}
for(int i = 0; i < K; i++){
out.println(points[i].time);
}
}
public int pIdx(int x, int y){
return x + y;
}
public int mIdx(int x, int y){
return x - y + 100000;
}
private static PrintWriter out;
public static void main(String[] args) {
out = new PrintWriter(System.out);
new Main().solve();
out.flush();
}
public static int nextInt() {
int num = 0;
String str = next();
boolean minus = false;
int i = 0;
if(str.charAt(0) == '-'){
minus = true;
i++;
}
int len = str.length();
for(; i < len; i++){
char c = str.charAt(i);
if(!('0' <= c && c <= '9')) throw new RuntimeException();
num = num * 10 + (c - '0');
}
return minus ? -num : num;
}
public static long nextLong() {
long num = 0;
String str = next();
boolean minus = false;
int i = 0;
if(str.charAt(0) == '-'){
minus = true;
i++;
}
int len = str.length();
for(; i < len; i++){
char c = str.charAt(i);
if(!('0' <= c && c <= '9')) throw new RuntimeException();
num = num * 10l + (c - '0');
}
return minus ? -num : num;
}
public static String next() {
int c;
while(!isAlNum(c = read())){}
StringBuilder build = new StringBuilder();
build.append((char)c);
while(isAlNum(c = read())){
build.append((char)c);
}
return build.toString();
}
private static byte[] inputBuffer = new byte[1024];
private static int bufferLength = 0;
private static int bufferIndex = 0;
private static int read() {
if(bufferLength < 0) throw new RuntimeException();
if(bufferIndex >= bufferLength){
try{
bufferLength = System.in.read(inputBuffer);
bufferIndex = 0;
}catch(IOException e){
throw new RuntimeException(e);
}
if(bufferLength <= 0) return(bufferLength = -1);
}
return inputBuffer[bufferIndex++];
}
private static boolean isAlNum(int c) {
return '!' <= c && c <= '~';
}
}
| Java | ["3 3 4\n1 1\n1 2\n2 1\n2 2", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3"] | 2 seconds | ["1\n-1\n-1\n2", "1\n-1\n-1\n2\n5\n-1", "13\n2\n9\n5\n-1"] | NoteIn the first sample, the ray will consequently pass through the points (0,β0), (1,β1), (2,β2), (3,β3). Thus, it will stop at the point (3,β3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0,β0), (1,β1), (2,β2), (3,β3), (2,β4), (1,β3), (0,β2), (1,β1), (2,β0), (3,β1), (2,β2), (1,β3), (0,β4). The ray will stop at the point (0,β4) after 12 seconds. It will reflect at the points (3,β3), (2,β4), (0,β2), (2,β0) and (3,β1). | Java 8 | standard input | [
"hashing",
"greedy",
"number theory",
"math",
"implementation",
"sortings"
] | 27a521d4d59066e50e870e7934d4b190 | The first line of the input contains three integers n, m and k (2ββ€βn,βmββ€β100β000, 1ββ€βkββ€β100β000)Β β lengths of the room's walls and the number of sensors. Each of the following k lines contains two integers xi and yi (1ββ€βxiββ€βnβ-β1, 1ββ€βyiββ€βmβ-β1)Β β coordinates of the sensors. It's guaranteed that no two sensors are located at the same point. | 1,800 | Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or β-β1 if this will never happen. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.