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
bb6315f489403d5f139506e87eb1dcf0
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.File; import java.io.PrintStream; import java.util.Scanner; public class B { public static void main(String[] args) { try { //* File in = new File("input.txt"); File out = new File("output.txt"); PrintStream writer = new PrintStream(out); Scanner sc = new Scanner(in); /* PrintStream writer = new PrintStream(System.out); Scanner sc = new Scanner(System.in); */ int n = sc.nextInt(), k = sc.nextInt(); boolean[] selected = new boolean[n]; for(int i = 0; i < n; i++) selected[i] = sc.nextInt() == 0; for(int i = k-1; ; i=(i+1)%n) { if(!selected[i]) { writer.println(i+1); break; } } } catch (Exception e) { } finally { } } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
0d1882705982a6c6886a9ff4d636e522
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.util.*; import java.io.*; import java.math.BigInteger; public class Main implements Runnable { private void solve() throws IOException { int n = nextInt(), k = nextInt() - 1; int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } while (a[k] == 0) { k++; k %= n; } out.println(k + 1); } public void run() { try { in = new BufferedReader(new FileReader(new File("input.txt"))); out = new PrintWriter(new File("output.txt")); //in = new BufferedReader(new InputStreamReader(System.in)); //out = new PrintWriter(System.out); tokenizer = null; solve(); out.close(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { new Main().run(); } private BufferedReader in; private PrintWriter out; private StringTokenizer tokenizer; private String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreElements()) { tokenizer = new StringTokenizer(in.readLine()); } return tokenizer.nextToken(); } private int nextInt() throws IOException { return Integer.parseInt(nextToken()); } private long nextLong() throws IOException { return Long.parseLong(nextToken()); } private double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
0e366cdb834f46ceabedd6b3cc3da2c9
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class QuizLeague { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(new FileReader("input.txt")); BufferedWriter out = new BufferedWriter(new FileWriter("output.txt")); int n = sc.nextInt(); int k = sc.nextInt() - 1; int[] a = new int[n]; for (int i = 0; i < a.length; i++) a[i] = sc.nextInt(); int i = k; for (; i <= n; i++) { i %= n; if (a[i] == 1) break; } out.write((i + 1) + ""); out.close(); } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
17407d52a434b4b7dac5c65041b92c7d
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.util.Scanner; public class Main { public static void main(String args[]) { try { Scanner in; PrintWriter out; in = new Scanner(new File("input.txt")); out = new PrintWriter("output.txt"); int n = in.nextInt(); int k = in.nextInt(); int[] d = new int[n]; for (int i = 0; i < n; ++i) { d[i] = in.nextInt(); } while (d[k-1]==0) { ++k; if (k==n+1) k=1; } out.write(Integer.toString(k)); out.write("\n"); out.close(); } catch (IOException ex) { throw new RuntimeException(ex); } } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
72ce6203bb2b5ff6f57ba98129e90903
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
/* ********QUESTION DESCRIPTION************* * @author (codeKNIGHT) */ import java.util.*; import java.math.*; import java.io.*; public class saratov_b { public static void main(String args[])throws IOException { //Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter("output.txt"); //PrintWriter out=new PrintWriter(System.out); FileReader f=new FileReader("input.txt"); Scanner in=new Scanner(f); //int t=in.nextInt(); int i; String s; int n,k; n=in.nextInt(); k=in.nextInt(); int a[]=new int [n+1]; for(i=1;i<=n;i++) { a[i]=in.nextInt(); } while(a[k]!=1) { k++; if(k==n+1) k=1; } out.println(k); out.flush(); } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
cab4fbfa23a8d2fce3a1e3b6f9772a45
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; import static java.lang.Math.*; public class problemB implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer st; public static void main(String[] args) throws Exception { new Thread(new problemB()).start(); } private String next() throws Exception { if (st == null || !st.hasMoreElements()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } private int nextInt() throws Exception { return Integer.parseInt(next()); } private long nextLong() throws Exception { return Long.parseLong(next()); } private double nextDouble() throws Exception { return Double.parseDouble(next()); } public void run() { try { if (file) in = new BufferedReader(new FileReader("input.txt")); else in = new BufferedReader(new InputStreamReader(System.in)); if (file) out = new PrintWriter(new FileWriter("output.txt")); else out = new PrintWriter(System.out); solve(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { out.close(); } } boolean file = true; public void solve() throws Exception { int n = nextInt(), k = nextInt(), a[] = new int[n+1], curr = k; for(int i=1; i<=n; i++){ a[i] = nextInt(); } while(true){ if(a[curr] > 0){ out.println(curr); return; } curr++; if (curr == n+1) curr = 1; } } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
f2ea4eb9d8baaeefd81f3c71538164d9
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; public class P1 { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Scanner in = new Scanner(new File("input.txt")); PrintWriter out = new PrintWriter("output.txt"); while(in.hasNext()){ int n = in.nextInt(); int k = in.nextInt(); int [] q = new int[n]; for (int i = 0; i < q.length; i++) q[i]=in.nextInt(); for (int i = k-1; ; i++) {if(i==n)i=0;if(q[i]==1){out.print(i+1);break;}} out.flush(); } } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
b2acccdbbe37a6d9c1bfc588d40cbedf
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.util.StringTokenizer; /** * * @author Mohamed Ibrahim (MIM) */ public class QuizLeague { public static void main(String[] args) throws Exception { BufferedReader r = new BufferedReader(new FileReader("input.txt")); PrintWriter w = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); String s = r.readLine(); StringTokenizer st = new StringTokenizer(s); int n = Integer.parseInt(st.nextToken()); int cur = Integer.parseInt(st.nextToken())-1; s = r.readLine(); boolean bArr[] = new boolean[n]; st = new StringTokenizer(s); for (int i = 0; i < n; i++) { if (Integer.parseInt(st.nextToken()) == 1) { bArr[i] = true; } else { bArr[i] = false; } } while (true) { if(bArr[cur]) { w.println(cur+1); break; } cur++; if(cur==n)cur=0; } w.close(); } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
5fe3cb3537d4f1bfe3495ef96d141076
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.*; import java.util.*; public class B { public static void main(String[] args) throws Exception { Scanner s = new Scanner(new File("input.txt")); PrintWriter pw = new PrintWriter(new File("output.txt")); int n = s.nextInt(), k = s.nextInt() - 1; int[] a = new int[n]; for (int i = 0; i < n; ++i) { a[i] = s.nextInt(); } for (int i = k;; i = (i + 1) % n) { if (a[i] == 1) { pw.println(i + 1); pw.close(); return; } } } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
48c8464a8be2efae96269fc474672a18
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Arrays; import java.util.Scanner; public class B_Schools { public static void main(String[] args) throws IOException { FileReader f = new FileReader("input.txt"); FileWriter fr = new FileWriter("output.txt"); Scanner sa = new Scanner(f); int n = sa.nextInt(); int k = sa.nextInt(); int [] ar2 = new int[n]; for(int i = 0 ; i < n ; i ++) ar2[i] = sa.nextInt(); k-=1; while(ar2[k] == 0) { k++; if(k==n) k=0; } fr.write((k+1)+"\n"); fr.close(); } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
d0125d0a2402c1929a5be1bfe7fd45ac
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.Locale; import java.util.StringTokenizer; public class Main implements Runnable { void solve() throws IOException { int n = nextInt(); int k = nextInt() - 1; boolean[] a = new boolean[n]; for (int i = 0; i < a.length; i++) { a[i] = nextInt() == 0; } while (a[k]) { k = (k + 1) % n; } out.println(k + 1); } private BufferedReader in; private PrintWriter out; private StringTokenizer st; private void eat(String s) { st = new StringTokenizer(s); } String next() throws IOException { while (!st.hasMoreTokens()) { String line = in.readLine(); if (line == null) { return null; } eat(line); } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } public static void main(String[] args) throws IOException { new Thread(null, new Main(), "Main", 1 << 23).start(); } public void run() { try { Locale.setDefault(Locale.US); // in = new BufferedReader(new InputStreamReader(System.in)); // out = new PrintWriter(System.out); in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); eat(""); solve(); in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
7e9d0cc5c0c156628c13c4c1f1fa3d1a
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Locale; import java.util.StringTokenizer; public class Main { static BufferedReader in; static PrintWriter out; public static void main(String args[]) throws IOException { //in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); StringTokenizer s = new StringTokenizer(in.readLine()); int n = Integer.parseInt(s.nextToken()); int k =Integer.parseInt(s.nextToken())-1; s = new StringTokenizer(in.readLine()); int a[] = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(s.nextToken()); for(int i=k; i<n; i++) { if(a[i]==1) { out.print(i+1); out.close(); return; } } for(int i=0; i<k; i++) if(a[i]==1) { out.print(i+1); out.close(); return; } out.close(); } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
1ac55fd4dd796a478b9349d92bb292da
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.util.*; import java.io.*; public class cf120b { public static void main(String[] args) throws Exception { Scanner in = new Scanner(new File("input.txt")); PrintWriter out = new PrintWriter(new File("output.txt")); int n = in.nextInt(); int k = in.nextInt()-1; int[] v = new int[n]; for(int i=0; i<n; i++) v[i] = in.nextInt(); while(v[k]==0) k = (k+1)%n; out.println((k+1)); out.close(); } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
0f4f6f93bc9a67801579184cb5ed3d3a
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.*; import java.util.*; public class Main { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); static FileReader reader; static FileWriter writer; public static void main(String[] args) throws IOException { reader = new FileReader("input.txt"); writer = new FileWriter("output.txt"); BufferedReader r = new BufferedReader(reader); BufferedWriter w = new BufferedWriter(writer); String[]f = r.readLine().split(" "); int all = Integer.parseInt(f[0]); int count = Integer.parseInt(f[1]); String[]task = r.readLine().split(" "); int[]tab = new int[all]; for (int i = 0; i < all; i++) { tab[i] = Integer.parseInt(task[i]); } boolean flag = false; for (int i = count - 1; i < tab.length; i++) { if (tab[i] != 0) { w.write(Integer.toString(i + 1)); flag = true; break; } } if (!flag) { for (int i = 0; i < count; i++) { if (tab[i] != 0) { w.write(Integer.toString(i + 1)); flag = true; break; } } } r.close(); w.close(); } } // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { System.err.println(e); return ""; } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } void close() { try { br.close(); } catch (IOException e) { } } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
c7867a7302dcb066554142a5980be883
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.*; import java.util.*; public class Main { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); static FileReader reader; static FileWriter writer; public static void main(String[] args) throws IOException { reader = new FileReader("input.txt"); writer = new FileWriter("output.txt"); BufferedReader r = new BufferedReader(reader); BufferedWriter w = new BufferedWriter(writer); String[]f = r.readLine().split(" "); int all = Integer.parseInt(f[0]); int count = Integer.parseInt(f[1]); String[]task = r.readLine().split(" "); int[]tab = new int[all]; for (int i = 0; i < all; i++) { tab[i] = Integer.parseInt(task[i]); } boolean flag = false; for (int i = count - 1; i < tab.length; i++) { if (tab[i] != 0) { w.write(Integer.toString(i + 1)); flag = true; break; } } if (!flag) { for (int i = 0; i < count; i++) { if (tab[i] != 0) { w.write(Integer.toString(i + 1)); flag = true; break; } } } r.close(); w.close(); } } // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { System.err.println(e); return ""; } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } void close() { try { br.close(); } catch (IOException e) { } } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
d350cfbac16c8a8ed3b2166179e1437b
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { static int INF=1<<28; // static int key=1; /*int x,y; Main(int x,int y){ this.x=x; this.y=y; }*/ //static int sum=0; public static void main(String[] args)throws Exception{ Scanner sc =new Scanner(new File("input.txt")); // Scanner sc =new Scanner(System.in); File file = new File("output.txt"); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file))); // sc.useDelimiter("(\\s)+|[,]"); // ArrayList<Integer> lis = new ArrayList<Integer>(); while(sc.hasNext()){ int n=ni(sc),k=ni(sc),r=0; int x[]=new int[n]; for(int t=0;t<n;t++)x[t]=ni(sc); if(x[k-1]==1){r=k;} else{ for(int i=k;i<n;i++){if(x[i]==1){r=i+1; break;} } if(r==0){ for(int i=0;i<k;i++){if(x[i]==1){r=i+1;break;} } } } System.out.println(r); pw.println(r); }pw.flush(); pw.close(); } static void pr(int x){ System.out.println(x); } static void db(Object... os){ System.err.println(Arrays.deepToString(os)); } static int ni(Scanner in){ return in.nextInt(); } static void out(int[] a){ String r=""; for(int i=0;i<a.length;i++){ r+=((i==0) ?"":" ")+a[i]; } System.out.println(r); } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
46904087d65c37976b16b16524dde3cd
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.*; import java.util.*; public class Main { Scanner in; PrintWriter out; void solve() { int n = in.nextInt(); int k = in.nextInt() - 1; int[] a = new int[2 * n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); a[i + n] = a[i]; } int i = k; while (true) { if (a[i] == 1) { out.println((i + 1) % n == 0 ? i + 1 : (i + 1) % n); return; } i++; } } void run() { try { in = new Scanner(new File("input.txt")); out = new PrintWriter("output.txt"); } catch (IOException e) { throw new Error(e); } try { solve(); } finally { out.close(); } } public static void main(String args[]) { new Main().run(); } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
5071f2c8f1808739b7a75f479a97edd4
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.IOException; import java.util.InputMismatchException; import java.io.FileOutputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.FileInputStream; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author bkand1908 */ public class Main { public static void main(String[] args) { InputStream inputStream; try { inputStream = new FileInputStream("input.txt"); } catch (IOException e) { throw new RuntimeException(e); } OutputStream outputStream; try { outputStream = new FileOutputStream("output.txt"); } catch (IOException e) { throw new RuntimeException(e); } InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.readInt(); int k = in.readInt(); int[] a = new int[n]; for (int i = 0; i < n; ++i) a[i] = in.readInt(); int i = k - 1; while (a[i] == 0) i = (i + 1) % n; out.println(i + 1); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; 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 boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
b357045428838b5dda5b49e69cb4e605
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class A implements Runnable { public void run() { long startTime = System.nanoTime(); int n = nextInt(); int t = nextInt(); boolean[] b = new boolean[n + 1]; for (int i = 0; i < n; i++) { b[i + 1] = nextInt() == 0; } while (b[t]) { if (++t == n + 1) { t = 1; } } println(t); if (fileIOMode) { System.out.println((System.nanoTime() - startTime) / 1e9); } out.close(); } //----------------------------------------------------------------------------------- private static boolean fileIOMode; private static String problemName = "a"; private static BufferedReader in; private static PrintWriter out; private static StringTokenizer tokenizer; public static void main(String[] args) throws Exception { fileIOMode = true; if (fileIOMode) { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } else { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } tokenizer = new StringTokenizer(""); new Thread(new A()).start(); } private static String nextLine() { try { return in.readLine(); } catch (IOException e) { return null; } } private static String nextToken() { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(nextLine()); } return tokenizer.nextToken(); } private static int nextInt() { return Integer.parseInt(nextToken()); } private static long nextLong() { return Long.parseLong(nextToken()); } private static double nextDouble() { return Double.parseDouble(nextToken()); } private static BigInteger nextBigInteger() { return new BigInteger(nextToken()); } private static void print(Object o) { if (fileIOMode) { System.out.print(o); } out.print(o); } private static void println(Object o) { if (fileIOMode) { System.out.println(o); } out.println(o); } private static void printf(String s, Object... o) { if (fileIOMode) { System.out.printf(s, o); } out.printf(s, o); } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
2ce64de5e355a84178e9e293c1e4aeee
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub //BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); //PrintWriter out=new PrintWriter(System.out); BufferedReader in=new BufferedReader(new FileReader("input.txt")); PrintWriter out=new PrintWriter(new FileWriter("output.txt")); String[] fLine=in.readLine().split(" "); int n=Integer.parseInt(fLine[0]); int k=Integer.parseInt(fLine[1])-1; String[] q=in.readLine().split(" "); while (q[k].compareTo("1")!=0) { k++; if (k>=n) k=0; } out.println(k+1); out.close(); } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
fc8f9426cc4ddd7e1687114090e6b543
train_002.jsonl
1318919400
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; public class Main{ public static void main(String[]args){ InputStream in = System.in; PrintWriter out = new PrintWriter(System.out); try{ in = new BufferedInputStream(new FileInputStream(new File("input.txt"))); out = new PrintWriter(new BufferedOutputStream(new FileOutputStream("output.txt"))); }catch (Exception e) { } new Main().run(in,out); out.flush(); } private void debug(Object...os){ System.err.println(deepToString(os)); } private void run(InputStream in,PrintWriter out){ int n=nextInt(in),k=nextInt(in)-1; int[] as=new int[n]; for(int i=0;i<n;i++)as[i]=nextInt(in); for(int i=k;;i++)if(as[i%n]==1){ out.println(i%n+1); return; } } private String next(InputStream in) { try { StringBuilder res = new StringBuilder(""); int c = in.read(); while (Character.isWhitespace(c)) c = in.read(); do { res.append((char) c); } while (!Character.isWhitespace(c = in.read())); return res.toString(); } catch (Exception e) { return null; } } private int nextInt(InputStream in){ try{ int c=in.read(); if(c==-1) return c; while(c!='-'&&(c<'0'||'9'<c)){ c=in.read(); if(c==-1) return c; } if(c=='-') return -nextInt(in); int res=0; do{ res*=10; res+=c-'0'; c=in.read(); }while('0'<=c&&c<='9'); return res; }catch(Exception e){ return -1; } } }
Java
["5 5\n0 1 0 1 0", "2 1\n1 1"]
1 second
["2", "1"]
null
Java 6
input.txt
[ "implementation" ]
1378b4c9ba8029d310f07a1027a8c7a6
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
1,100
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
output.txt
PASSED
3d8c7d5ca285233ca6296bf4350d117d
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; import java.math.*; public class Main{ public static int mod=(int)Math.pow(10,9)+7; public static void main (String[] args) throws java.lang.Exception{ //BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); int n=in.readInt(); //0-2*n-2 -n+1 n-1 long[] a=new long[2*n-1]; long[] b=new long[2*n-1]; int[][] xyz=new int[n][n]; long maxeven=0,maxodd=0,evenx=0,eveny=0,oddx=0,oddy=1; for(int i=0;i<n;i++) for(int j=0;j<n;j++){ int x=in.readInt(); xyz[i][j]=x; a[i+j]+=x; b[n-1+i-j]+=x; } for(int i=0;i<n;i++) for(int j=0;j<n;j++){ int x=xyz[i][j]; if((i+j)%2==0){ if(maxeven<a[i+j]+b[n-1+i-j]-x){ evenx=i; eveny=j; maxeven=a[i+j]+b[n-1+i-j]-x; } }else{ if(maxodd<a[i+j]+b[n-1+i-j]-x){ oddx=i;oddy=j; maxodd=a[i+j]+b[n-1+i-j]-x; } } } out.println(maxeven+maxodd); out.println((evenx+1)+" "+(eveny+1)+" "+(oddx+1)+" "+(oddy+1)); out.close(); } static final class InputReader{ private final InputStream stream; private final byte[] buf=new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream){this.stream=stream;} private int read()throws IOException{ if(curChar>=numChars){ curChar=0; numChars=stream.read(buf); if(numChars<=0) return -1; } return buf[curChar++]; } public final int readInt()throws IOException{return (int)readLong();} public final long readLong()throws IOException{ int c=read(); while(isSpaceChar(c)){ c=read(); if(c==-1) throw new IOException(); } boolean negative=false; if(c=='-'){ negative=true; 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 negative?(-res):(res); } public final int[] readIntBrray(int size)throws IOException{ int[] arr=new int[size]; for(int i=0;i<size;i++)arr[i]=readInt(); return arr; } public final String readString()throws IOException{ int c=read(); while(isSpaceChar(c))c=read(); StringBuilder res=new StringBuilder(); do{ res.append((char)c); c=read(); }while(!isSpaceChar(c)); return res.toString(); } public final String readLine()throws IOException{ int c=read(); while(isSpaceChar(c))c=read(); StringBuilder res=new StringBuilder(); do{ res.append((char)c); c=read(); }while(!isSpaceChar(c)); return res.toString(); } private boolean isSpaceChar(int c){ return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1; } } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
5580f588b2baed8cd7c7ba9837f29b0f
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
/* * Remember a 7.0 student can know more than a 10.0 student. * Grades don't determine intelligence, they test obedience. * I Never Give Up. */ import java.util.*; import java.util.Map.Entry; import java.io.*; import javax.xml.stream.events.Characters; import sun.security.x509.IPAddressName; import static java.lang.System.out; import static java.util.Arrays.*; import static java.lang.Math.*; public class ContestMain { private static Reader in=new Reader(); private static StringBuilder ans=new StringBuilder(); private static long MOD=1000000007;//10^9+7 private static final int N=1000000;//10^6 private static final int LIM=26; // private static final double PI=3.1415; // private static ArrayList<Integer> v[]=new ArrayList[N]; // private static int color[]=new int[N]; //For Graph Coloring // private static boolean mark[]=new boolean[N]; // private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); // private static void dfs(int node){mark[node]=true;for(int x:v[node]){if(!mark[x]){dfs(x);}}} private static long powmod(long x,long n,long m){ if(n==0)return 1; else if(n%2==0)return(powmod((x*x)%m,n/2,m)); else return (x*(powmod((x*x)%m,(n-1)/2,m)))%m; } // private static void shuffle(String[] arr) { // for (int i = arr.length - 1; i >= 2; i--) { // int x = new Random().nextInt(i - 1); // String temp = arr[x]; // arr[x] = arr[i]; // arr[i] = temp; // } // } //OJ Doing = Codeforces //Double check the code public static void main(String[] args) throws IOException{ int n=in.nextInt(); long ar[][]=new long[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++) ar[i][j]=in.nextLong(); } long dr[][]=new long[n][n]; long dl[][]=new long[n][n]; long sum=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(j-1<0||i-1<0)dr[i][j]=ar[i][j]; else dr[i][j]=dr[i-1][j-1]+ar[i][j]; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i-1<0||j+1>n-1)dl[i][j]=ar[i][j]; else dl[i][j]=dl[i-1][j+1]+ar[i][j]; } } int m,d; int x1=0,y1=0,x2=0,y2=0; long s1=0,s2=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ m=min(n-i-1,n-j-1); d=min(n-i-1,j); sum=dr[i+m][j+m]+dl[i+d][j-d]-ar[i][j]; // out.println(i+" "+j+" "+sum); if((i+j)%2==0&&sum>=s1){ s1=sum; x1=i+1; y1=j+1; } else if((i+j)%2!=0&&sum>=s2){ s2=sum; x2=i+1; y2=j+1; } } } out.println(s1+s2); out.println(x1+" "+y1+" "+x2+" "+y2); } static class Pair implements Comparable<Pair>{ long l; long r; Pair(){ l=0; r=0; } Pair(long k,long v){ l=k; r=v; } @Override public int compareTo(Pair o) { if(l!=o.l)return (int) (l-o.l); else return (int) -(r-o.r); //changed } } static class Reader{ BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
99207a0de00835dad04b8c6ad42f00d2
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.*; import java.util.*; public class Abc { static int arr[][]; static long sum[][]; static int n; public static void main(String[] args) { FastReader sc = new FastReader(); n=sc.nextInt(); arr=new int[n][n];sum=new long[n][n]; long sec[]=new long[2*n],prim[]=new long[2*n]; for (int i=0;i<n;i++){ for (int j=0;j<n;j++){ arr[i][j]=sc.nextInt(); sec[i+j]+=arr[i][j]; prim[i-j+n]+=arr[i][j]; } } long maxE=-1,maxO=-1; int ans[]=new int[4]; for (int i=0;i<n;i++){ for (int j=0;j<n;j++){ long sum=prim[i-j+n]+sec[i+j]-arr[i][j]; if ((i+j)%2==0){ if (maxE<sum){ maxE=sum; ans[0]=i;ans[1]=j; } }else { if (maxO<sum){ maxO=sum; ans[2]=i;ans[3]=j; } } } } System.out.println(maxE+maxO); for (int i=0;i<4;i++)ans[i]++; System.out.println(ans[0]+" "+ans[1]+" "+ans[2]+" "+ans[3]); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
08032027b141935618c863edae4f2be3
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.*; import java.util.*; public class Abc { static int arr[][]; static long sum[][]; static int n; public static void main(String[] args) { FastReader sc = new FastReader(); n=sc.nextInt(); arr=new int[n][n];sum=new long[n][n]; long sec[]=new long[2*n],prim[]=new long[2*n]; for (int i=0;i<n;i++){ for (int j=0;j<n;j++){ arr[i][j]=sc.nextInt(); sec[i+j]+=arr[i][j]; prim[-i+j+n]+=arr[i][j]; } } long maxE=-1,maxO=-1; int ans[]=new int[4]; for (int i=0;i<n;i++){ for (int j=0;j<n;j++){ long sum=prim[-i+j+n]+sec[i+j]-arr[i][j]; if ((i+j)%2==0){ if (maxE<sum){ maxE=sum; ans[0]=i;ans[1]=j; } }else { if (maxO<sum){ maxO=sum; ans[2]=i;ans[3]=j; } } } } System.out.println(maxE+maxO); for (int i=0;i<4;i++)ans[i]++; System.out.println(ans[0]+" "+ans[1]+" "+ans[2]+" "+ans[3]); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
14a586d4b089c35ab6207eb99358f5ad
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; public class quedt { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); long[][] arr = new long[n][n]; HashMap<Integer, Long> left = new HashMap<>(); HashMap<Integer, Long> right = new HashMap<>(); for (int i = 0; i < n; i++) { String []str=br.readLine().split(" "); for (int j = 0; j < n; j++) { arr[i][j] = Long.parseLong(str[j]); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { long val=arr[i][j]; long pehle= left.getOrDefault(i-j, 0L); left.put((i-j), pehle+val); long pehle2= right.getOrDefault(n-1-(i+j), 0L); right.put(n-1-(i+j), pehle2+val); } } long maxe=0,maxo=0; int x1=1,x2=1,y1=1,y2=2; int [][]dir={{0,-1},{-1,0},{0,1},{1,0}}; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ long val= left.get((i-j))+right.get((n-1-(i+j)))-arr[i][j]; if((i+j)%2==0){ if(val>maxe){ x1=i+1; y1=j+1; maxe=val; } }else{ if(val>maxo){ x2=i+1; y2=j+1; maxo=val; } } } } System.out.println(maxe+maxo); System.out.println(x1+" "+y1+" "+x2+" "+y2); } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
48b970fb9f7698a4c2e965ecbc7b7413
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Application { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.valueOf(reader.readLine()); int[][] matrix = new int[n][]; for (int i = 0; i < n; i++) matrix[i] = parse(reader.readLine()); long[] lDown = new long[2 * n - 1]; long[] rDown = new long[2 * n - 1]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { lDown[i + j] += matrix[i][j]; rDown[i - j + n - 1] += matrix[i][j]; } } long max = 0, maxI = 0, maxJ = 0; for (int i = 0; i < lDown.length; i++) { if (lDown[i] > max) { max = lDown[i]; maxI = i; } } max = 0; for (int i = 0; i < rDown.length; i++) { if (rDown[i] > max) { max = rDown[i]; maxJ = i; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { long val = lDown[i + j] + rDown[i - j + n - 1] - matrix[i][j]; if (val > max) { max = val; maxI = i; maxJ = j; } } } boolean xor = (maxI % 2 == 0) ^ (maxJ % 2 == 0); long totalMax = 0, totalMaxI = 0, totalMaxJ = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { boolean currXor = (i % 2 == 0) ^ (j % 2 == 0); if (xor == currXor) continue; long val = lDown[i + j] + rDown[i - j + n - 1] - matrix[i][j]; if (val > totalMax) { totalMax = val; totalMaxI = i; totalMaxJ = j; } } } totalMax += max; System.out.println(totalMax); System.out.println((maxI + 1) + " " + (maxJ + 1) + " " + (totalMaxI + 1) + " " + (totalMaxJ + 1)); } private static int[] parse(String line) { String[] arr = line.split(" "); int[] res = new int[arr.length]; for (int i = 0; i < res.length; i++) res[i] = Integer.valueOf(arr[i]); return res; } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
4527604e79cb1203b45d26883def1425
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
// FOR YOU A THOUSAND TIMES OVER.// // Author :- Saurabh// //BIT MESRA, RANCHI// import java.io.*; import java.util.*; import static java.lang.Math.*; public class gargariAndBishops { static void Bolo_Jai_Mata_Di() { n=ni(); long ar[][]=new long[n+2][n+2]; tsc(); for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)ar[i][j]=ni(); long w[][]=new long[n+2][n+2],x[][]=new long[n+2][n+2],y[][]=new long[n+2][n+2],z[][]=new long[n+2][n+2]; long ans1=-12345,ans2=-12345; int x1,y1,x2,y2;x1=y1=x2=y2=1; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) w[i][j]=ar[i][j]+w[i-1][j-1]; for(int i=1;i<=n;i++) for(int j=n;j>=1;j--) x[i][j]=ar[i][j]+x[i-1][j+1]; for(int i=n;i>=1;i--) for(int j=1;j<=n;j++) y[i][j]=ar[i][j]+y[i+1][j-1]; for(int i=n;i>=1;i--) for(int j=n;j>=1;j--) z[i][j]=ar[i][j]+z[i+1][j+1]; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ long temp=w[i][j]+x[i][j]+y[i][j]+z[i][j]-3*ar[i][j]; if((i+j)%2==0){ if(temp>ans1){ ans1=temp;x1=i;y1=j; } } else{ if(temp>ans2){ ans2=temp;x2=i;y2=j; } } } } pl(ans1+ans2); p(x1);p(y1);p(x2);p(y2); tec(); //calculates the ending time of execution //pwt(); //prints the time taken to execute the program flush(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //THE DON'T CARE ZONE BEGINS HERE...// static Calendar ts, te; //For time calculation static int mod9 = 1000000007; static int n, m, k, t, mod = 998244353; static Lelo input = new Lelo(System.in); static PrintWriter pw = new PrintWriter(System.out, true); public static void main(String[] args) { //threading has been used to increase the stack size. new Thread(null, null, "BlackRise", 1 << 25) //the last parameter is stack size desired., { public void run() { try { Bolo_Jai_Mata_Di(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } static class Lelo { //Lelo class for fast input private InputStream ayega; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public Lelo(InputStream ayega) { this.ayega = ayega; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = ayega.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public 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 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); } } // functions to take input// static int ni() { return input.nextInt(); } static long nl() { return input.nextLong(); } static double nd() { return input.nextDouble(); } static String ns() { return input.readString(); } //functions to give output static void pl() { pw.println(); } static void p(Object o) { pw.print(o + " "); } static void pws(Object o) { pw.print(o + ""); } static void pl(Object o) { pw.println(o); } static void tsc() //calculates the starting time of execution { ts = Calendar.getInstance(); ts.setTime(new Date()); } static void tec() //calculates the ending time of execution { te = Calendar.getInstance(); te.setTime(new Date()); } static void pwt() //prints the time taken for execution { pw.printf("\nExecution time was :- %f s\n", (te.getTimeInMillis() - ts.getTimeInMillis()) / 1000.00); } static void flush() { pw.flush(); pw.close(); } static void sort(int ar[], int n) { for (int i = 0; i < n; i++) { int ran = (int) (Math.random() * n); int temp = ar[i]; ar[i] = ar[ran]; ar[ran] = temp; } Arrays.sort(ar); } static void sort(long ar[], int n) { for (int i = 0; i < n; i++) { int ran = (int) (Math.random() * n); long temp = ar[i]; ar[i] = ar[ran]; ar[ran] = temp; } Arrays.sort(ar); } static void sort(char ar[], int n) { for (int i = 0; i < n; i++) { int ran = (int) (Math.random() * n); char temp = ar[i]; ar[i] = ar[ran]; ar[ran] = temp; } Arrays.sort(ar); } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
966cb830fc6f9d3bd33697d408218826
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static int n; static long[][] a; static int[] dx = {1,-1,1,-1}; static int[] dy = {1,1,-1,-1}; static long[] lr , rl; static int x , y; static boolean isValid(int x,int y) {return x>=0 && x<n && y>=0 && y<n;} static void fill() { lr = new long[n<<1]; rl = new long[n<<1]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { lr[i+j]+=a[i][j]; rl[i+(n-1-j)]+=a[i][j]; } } static void solve(int off) { long max = -1; for (int i = 0; i < n; i++) { for (int j = i%2+off; j < n; j+=2) { long cur = lr[i+j] + rl[i+(n-1-j)] - a[i][j]; if(cur>max) { max = cur; x = i;y=j; } } } } public static void main(String[] args) throws Throwable { Scanner sc = new Scanner(System.in); n = sc.nextInt(); a = new long[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) a[i][j] = sc.nextLong(); fill(); x = y = -1; long ans = 0; solve(0); ans += lr[x+y] + rl[x+(n-1-y)] - a[x][y]; int x1 = x+1 , y1 = y+1; solve(1); ans += lr[x+y] + rl[x+(n-1-y)] - a[x][y]; System.out.println(ans); System.out.println(x1+" "+y1+" "+ ++x+" "+ ++y); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String file) throws FileNotFoundException { 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 int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public int[] nexIntArray() throws Throwable { st = new StringTokenizer(br.readLine()); int[] a = new int[st.countTokens()]; for (int i = 0; i < a.length; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
fc8ad982bd2e893148e427e20113b37e
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.util.*; import java.io.*; public class Main{ static long res[]; static int ans[][]; public static void main(String args[]) throws IOException{ BufferedReader sc=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int n=Integer.parseInt(sc.readLine().trim()); res=new long[2]; ans=new int[2][2]; res[0]=res[1]=-1; long a[][]=new long[n+1][n+1]; long d1[]=new long[2*n+100]; long d2[]=new long[2*n+100]; for(int i=1;i<=n;i++){ String s[]=sc.readLine().trim().split(" "); for(int j=1;j<=n;j++){ long x=Long.parseLong(s[j-1]); a[i][j]=x; d1[i+j]+=x; d2[i-j+n]+=x; } } for(int i=1;i<=n;i++){ for(int j=1;j<n;j++){ upd((i+j)&1,i,j,d1[i+j]+d2[i-j+n]-a[i][j]); } } pw.println(res[0]+res[1]); pw.print(ans[0][0]+" "+ans[0][1]+" "); pw.println(ans[1][0]+" "+ans[1][1]); pw.flush(); pw.close(); sc.close(); } public static void upd(int c,int i,int j,long val){ if(val>res[c]){ res[c]=val; ans[c][0]=i; ans[c][1]=j; } } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
4889c78e1a24ba6e413f2bebbfd4c5c6
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.awt.List; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.util.*; public class Watermelon2 { public static void main(String[] args) throws IOException{ Main2 m=new Main2(); m.solve(); } } class Main2{ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private int[] array; private int[] tempMergArr; private int length; BigInteger[] temp=new BigInteger[31]; BigInteger x,y,z; 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()); } int marr[]=null; void solve() throws IOException { int n=this.nextInt(); int[][] arr=new int[n][n]; long[] ipj=new long[n+n]; long[] imj=new long[n+n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ arr[i][j]=this.nextInt(); ipj[i+j]+=arr[i][j]; imj[i-j+n]+=arr[i][j]; } } long max=-1,max0=-1; int x=-1,y=-1,x0=-1,y0=-1; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ // System.out.println(xarr[i][j]+" "+max+" "+max0); long sum=ipj[i+j]+imj[i-j+n]-arr[i][j]; if((i+j)%2==0&&sum>max){ max=sum; x=i+1; y=j+1; } if((i+j)%2==1&&sum>max0){ max0=sum; x0=i+1; y0=j+1; } } } System.out.println(max+max0); System.out.println(x+" "+y+" "+x0+" "+y0); } public String recurs(char[] carr,int k){ int count=0; for(int i=0;i<carr.length;i++){ if(i+k-1<carr.length) if(carr[i]=='-'){ for(int j=i;j<i+k;j++){ if(carr[j]=='+') {carr[j]='-';continue;} if(carr[j]=='-') {carr[j]='+';continue;} // System.out.println(j+" "+i+" "+carr[j]); } count++; } // display(carr); } for(int i=0;i<carr.length;i++){ if(carr[i]=='-') return "IMPOSSIBLE"; } return Integer.toString(count); } static int max_LIS=0; public int LIS(int[] arr,int n){ if(n==0) { marr[0]=1; return 1; } int current =1; for(int i=0;i<n;i++){ int subproblem=0; if(marr[i]==0) { subproblem=LIS(arr,i); marr[i]=subproblem; } else{ // System.out.println("Hey"); subproblem=marr[i]; } System.out.println(current+" "+subproblem+" "+i); if(arr[i]<arr[n]&&current<(1+subproblem)){ current=(1+subproblem); } } if(max_LIS<current) max_LIS=current; return current; } public BigInteger comb(int n,int r){ x=this.temp[n]; y=this.temp[r]; z=this.temp[n-r]; // System.out.println(x+" "+y+" "+z); BigInteger ret=x.divide(y.multiply(z)); return ret; } public void fact(){ this.temp[0]=BigInteger.ONE; this.temp[1]=BigInteger.ONE; for(int i=2;i<this.temp.length;i++){ temp[i]=(temp[i-1].multiply(BigInteger.valueOf(i))); } } private static int gcd(int a, int b) { while (b > 0) { int temp = b; b = a % b; // % is remainder a = temp; } return a; } private static int lcm(int a, int b) { return a * (b / gcd(a, b)); } static int[] toFractionPos(int x,int y){ int a=gcd(x,y); int[] arr={x/a,y/a}; //display(arr); return arr; } static void display(long[][] arr){ for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[i].length;j++){ System.out.print(arr[i][j]+" "); } System.out.println(); } System.out.println(); } static void display(String[] arr){ for(int i=0;i<arr.length;i++){ System.out.println(arr[i]+" "); } //System.out.println(); } static void display(long[] arr){ for(int i=0;i<arr.length;i++) System.out.print(arr[i]+" "); System.out.println(); } static void display(double[] arr){ for(int i=0;i<arr.length;i++){ System.out.print(arr[i]+" "); } System.out.println(); } static void display(char[] arr){ // System.out.println(); int t=0; for(int i=0;i<arr.length;i++){ if(arr[i]!='0'){t=i;break;} } while(t!=arr.length){ System.out.print(arr[t]); t++; } System.out.println(); } static String str(char[] carr){ String str=""; for(int i=0;i<carr.length;i++){ str=str+carr[i]; } return str; } public void sort(int inputArr[]) { this.array = inputArr; this.length = inputArr.length; this.tempMergArr = new int[length]; doMergeSort(0, length - 1); } private void doMergeSort(int lowerIndex, int higherIndex) { if (lowerIndex < higherIndex) { int middle = lowerIndex + (higherIndex - lowerIndex) / 2; // Below step sorts the left side of the array doMergeSort(lowerIndex, middle); // Below step sorts the right side of the array doMergeSort(middle + 1, higherIndex); // Now merge both sides mergeParts(lowerIndex, middle, higherIndex); } } private void mergeParts(int lowerIndex, int middle, int higherIndex) { for (int i = lowerIndex; i <= higherIndex; i++) { tempMergArr[i] = array[i]; } int i = lowerIndex; int j = middle + 1; int k = lowerIndex; while (i <= middle && j <= higherIndex) { if (tempMergArr[i] <= tempMergArr[j]) { array[k] = tempMergArr[i]; i++; } else { array[k] = tempMergArr[j]; j++; } k++; } while (i <= middle) { array[k] = tempMergArr[i]; k++; i++; } } } class Count2 implements Comparable { Integer i; Integer j; Count2(int i,int j){ this.j=j; this.i=i; } void display(){ System.out.println(i+" "+j); } @Override public int compareTo(Object o) { // TODO Auto-generated method stub Count2 c=(Count2)o; if(i.compareTo(c.i)>0) return 1; else if(i.compareTo(c.i)<0) return -1; else{ return 0; } } } class Counti2 implements Comparable { Integer i; Integer j; Long k; Counti2(int i,int j,long k){ this.j=j; this.i=i; this.k=k; } void display(){ System.out.println(i+" "+j+" "+k); } @Override public int compareTo(Object o) { // TODO Auto-generated method stub Counti2 c=(Counti2)o; if(k.compareTo(c.k)>0) return 1; else if(k.compareTo(c.k)<0) return -1; else return 0; } } class Counti3 implements Comparable { Integer i; Integer j; Integer k; Integer l; Long sum; Counti3(int i,int j,int k,int l,long sum){ this.j=j; this.i=i; this.k=k; this.l=l; this.sum=sum; } void display(){ System.out.println(i+" "+j+" "+k+" "+l+" "+sum); } @Override public int compareTo(Object o) { // TODO Auto-generated method stub Counti3 c=(Counti3)o; if(sum.compareTo(c.sum)>0) return 1; else if(sum.compareTo(c.sum)<0) return -1; else return 0; } } class Extra2{ ArrayList<Integer> list=new ArrayList<>(); Extra2(int i){ list.add(i); } void display(){ System.out.println(list.size()); for(int i=0;i<list.size();i++){ System.out.print(list.get(i)+" "); } System.out.println(); } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
2a73d53108a8dd24d5f625fbf432dde7
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.*; public class C { static StreamTokenizer st; static int n; static int[][] a; public static void main(String[] args) throws IOException { st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in), 60 * 1024 * 1024)); read(); long[] mainDiagonal = mainDiagonalsSum(); long[] secondaryDiagonal = secondaryDiagolanSum(); long b1 = -1, b2 = -1; int r1 = 0, r2 = 0, c1 = 0, c2 = 0; for (int r = 0; r < n; r++) { for (int c = 0; c < n; c++) { int main = c - r + n - 1; int second = c + r; if (main % 2 == 1) { if (mainDiagonal[main] + secondaryDiagonal[second] - a[r][c] > b1) { b1 = mainDiagonal[main] + secondaryDiagonal[second] - a[r][c]; r1 = r + 1; c1 = c + 1; } } else if (mainDiagonal[main] + secondaryDiagonal[second] - a[r][c] > b2) { b2 = mainDiagonal[main] + secondaryDiagonal[second] - a[r][c]; r2 = r + 1; c2 = c + 1; } } } System.out.println(b1 + b2); System.out.printf("%d %d %d %d%n", r1, c1, r2, c2); } static long[] mainDiagonalsSum() { long[] mainDiagonal = new long[2 * n - 1]; mainDiagonal[n - 1] = diagonalSum(0, 0); for (int i = 1; i < n; i++) { mainDiagonal[-i + n - 1] = diagonalSum(i, 0); mainDiagonal[i + n - 1] = diagonalSum(0, i); } return mainDiagonal; } static long diagonalSum(int r, int c) { long res = 0; for (int i = r, j = c; i < n && j < n; i++, j++) { res += (long) a[i][j]; } return res; } static long sDiagonalSum(int r, int c) { long res = 0; for (int i = r, j = c; i < n && j >= 0; i++, j--) { res += (long) a[i][j]; } return res; } static void read() throws IOException { n = ri(); a = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = ri(); } } } static int ri() throws IOException { st.nextToken(); return (int) st.nval; } static String rs() throws IOException { st.nextToken(); return st.sval; } static long[] secondaryDiagolanSum() { long[] res = new long[2 * n - 1]; res[n - 1] = sDiagonalSum(0, n - 1); for (int i = 1; i < n; i++) { res[n - 1 - i] = sDiagonalSum(0, n - 1 - i); res[n - 1 + i] = sDiagonalSum(i, n - 1); } return res; } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
2b172327dece924f86c3ef536e6746e4
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.*; public class C { static StreamTokenizer st; static int n; static int[][] a; public static void main(String[] args) throws IOException { st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); read(); long[] mainDiagonal = mainDiagonalsSum(); long[] secondaryDiagonal = secondaryDiagolanSum(); long b1 = -1, b2 = -1; int r1 = 0, r2 = 0, c1 = 0, c2 = 0; for (int r = 0; r < n; r++) { for (int c = 0; c < n; c++) { int main = c - r + n - 1; int second = c + r; if (main % 2 == 1) { if (mainDiagonal[main] + secondaryDiagonal[second] - a[r][c] > b1) { b1 = mainDiagonal[main] + secondaryDiagonal[second] - a[r][c]; r1 = r + 1; c1 = c + 1; } } else if (mainDiagonal[main] + secondaryDiagonal[second] - a[r][c] > b2) { b2 = mainDiagonal[main] + secondaryDiagonal[second] - a[r][c]; r2 = r + 1; c2 = c + 1; } } } System.out.println(b1 + b2); System.out.printf("%d %d %d %d%n", r1, c1, r2, c2); } static long[] mainDiagonalsSum() { long[] mainDiagonal = new long[2 * n - 1]; mainDiagonal[n - 1] = diagonalSum(0, 0); for (int i = 1; i < n; i++) { mainDiagonal[-i + n - 1] = diagonalSum(i, 0); mainDiagonal[i + n - 1] = diagonalSum(0, i); } return mainDiagonal; } static long diagonalSum(int r, int c) { long res = 0; for (int i = r, j = c; i < n && j < n; i++, j++) { res += (long) a[i][j]; } return res; } static long sDiagonalSum(int r, int c) { long res = 0; for (int i = r, j = c; i < n && j >= 0; i++, j--) { res += (long) a[i][j]; } return res; } static void read() throws IOException { n = ri(); a = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = ri(); } } } static int ri() throws IOException { st.nextToken(); return (int) st.nval; } static String rs() throws IOException { st.nextToken(); return st.sval; } static long[] secondaryDiagolanSum() { long[] res = new long[2 * n - 1]; res[n - 1] = sDiagonalSum(0, n - 1); for (int i = 1; i < n; i++) { res[n - 1 - i] = sDiagonalSum(0, n - 1 - i); res[n - 1 + i] = sDiagonalSum(i, n - 1); } return res; } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
a7358a48e2e4abf67760a43d5dde6677
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main (String[] args) {new Main();} Main () { FastScanner fs = new FastScanner(); Scanner s = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = fs.nextInt(); long[][][] sum = new long[5][n][n]; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) { long x = fs.nextLong(); for(int k = 0; k < 4; k++) { sum[k][i][j] = x; } sum[4][i][j] = 3L * sum[0][i][j]; } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(i-1 >= 0 && j-1 >= 0) { sum[0][i][j] += sum[0][i-1][j-1]; } if(i - 1 >= 0 && j + 1 < n) { sum[1][i][j] += sum[1][i-1][j+1]; } } } for(int i = n-1; i >= 0; i--) { for(int j = n-1; j >= 0; j--) { if(i + 1 < n && j - 1 >= 0) { sum[2][i][j] += sum[2][i+1][j-1]; } if(i + 1 < n && j + 1 < n) { sum[3][i][j] += sum[3][i+1][j+1]; } } } Point[] diagonals = new Point[2]; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { int x = i + 1, y = j + 1; long sums = 0; for(int k = 0; k < 4; k++) sums += sum[k][i][j]; sums -= sum[4][i][j]; if(diagonals[(x + y) % 2] == null) diagonals[(x + y) % 2] = new Point(x, y, sums); else if(diagonals[(x + y) % 2].sum < sums) diagonals[(x + y) % 2] = new Point(x, y, sums); } } out.println(diagonals[0].sum + diagonals[1].sum); out.printf("%d %d %d %d\n", diagonals[0].i, diagonals[0].j, diagonals[1].i, diagonals[1].j); out.close(); } class Point { int i, j; long sum; Point (int a, int b, long s) { i = a; j = b; sum = s; } public String toString() { return "i = " + i + " j = " + j + " sum = " + sum; } } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new FileReader("testdata.out")); st = new StringTokenizer(""); } catch (Exception e){e.printStackTrace();} } public String next() { if (st.hasMoreTokens()) return st.nextToken(); try {st = new StringTokenizer(br.readLine());} catch (Exception e) {e.printStackTrace();} return st.nextToken(); } public int nextInt() {return Integer.parseInt(next());} public long nextLong() {return Long.parseLong(next());} public double nextDouble() {return Double.parseDouble(next());} public String nextLine() { String line = ""; try {line = br.readLine();} catch (Exception e) {e.printStackTrace();} return line; } public Integer[] nextIntegerArray(int n) { Integer[] a = new Integer[n]; for(int i = 0; i < n; i++) a[i] = nextInt(); return a; } public int[] nextIntArray(int n) { int[] a = new int[n]; for(int i = 0; i < n; i++) a[i] = nextInt(); return a; } public char[] nextCharArray() {return nextLine().toCharArray();} } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
9cde7610d545bbeb3f5e597277e9008a
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
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.HashMap; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author prakhar897 */ 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); CGargariAndBishops solver = new CGargariAndBishops(); solver.solve(1, in, out); out.close(); } static class CGargariAndBishops { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(); long mat[][] = new long[n][n]; long sum[][] = new long[n][n]; HashMap<Integer, Long> hm1 = new HashMap<>(); HashMap<Integer, Long> hm2 = new HashMap<>(); int i, j; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { mat[i][j] = in.nextLong(); hm1.put(i + j, hm1.getOrDefault(i + j, 0l) + mat[i][j]); hm2.put(i - j, hm2.getOrDefault(i - j, 0l) + mat[i][j]); } } //out.println(hm1); //out.println(hm2); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { sum[i][j] = hm1.get(i + j) + hm2.get(i - j) - mat[i][j]; } } //out.println(sum); int x1 = -1, x2 = -1, y1 = -1, y2 = -1; long maxe = -1, maxo = -1; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if ((i + j) % 2 == 0 && sum[i][j] > maxe) { maxe = sum[i][j]; x1 = i + 1; y1 = j + 1; } else if ((i + j) % 2 == 1 && sum[i][j] > maxo) { maxo = sum[i][j]; x2 = i + 1; y2 = j + 1; } } } out.println(maxe + maxo); out.println(x1 + " " + y1 + " " + x2 + " " + y2); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void println(long i) { writer.println(i); } } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
a40931fc87a1014db769aa3c10d58ac8
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class C { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[][] cost = new int[n][n]; for (int r = 0; r < n; r++) { StringTokenizer st = new StringTokenizer(br.readLine()); for (int c = 0; c < n; c++) { cost[r][c] = Integer.parseInt(st.nextToken()); } } long[][] ov = new long[n][n]; for (int i = 0; i < n; i++) { long diag = 0; int r = i; int c = 0; while (r < n) { diag += cost[r][c]; r++; c++; } r = i; c = 0; while (r < n) { ov[r][c] = diag - cost[r][c]; r++; c++; } } for (int i = 1; i < n; i++) { long diag = 0; int r = 0; int c = i; while (c < n) { diag += cost[r][c]; r++; c++; } r = 0; c = i; while (c < n) { ov[r][c] = diag - cost[r][c]; r++; c++; } } long maxEven = 0; long maxOdd = 0; String even = ""; String odd = ""; for (int i = 0; i < n; i++) { long diag = 0; int r = 0; int c = i; while (c >= 0) { diag += cost[r][c]; r++; c--; } r = 0; c = i; while (c >= 0) { ov[r][c] += diag; if ((r + c) % 2 == 0) { if (ov[r][c] >= maxEven) { maxEven = ov[r][c]; even = (r + 1) + " " + (c + 1); } } else { if (ov[r][c] >= maxOdd) { maxOdd = ov[r][c]; odd = (r + 1) + " " + (c + 1); } } r++; c--; } } for (int i = 1; i < n; i++) { long diag = 0; int r = i; int c = n - 1; while (r < n) { diag += cost[r][c]; r++; c--; } r = i; c = n - 1; while (r < n) { ov[r][c] += diag; if ((r + c) % 2 == 0) { if (ov[r][c] >= maxEven) { maxEven = ov[r][c]; even = (r + 1) + " " + (c + 1); } } else { if (ov[r][c] >= maxOdd) { maxOdd = ov[r][c]; odd = (r + 1) + " " + (c + 1); } } r++; c--; } } System.out.println(maxOdd + maxEven); System.out.println(even + " " + odd); } public static long hash(int r, int c) { return 10000L * r + c; } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
7dd67b75007a2b825492e80c338a967f
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.ObjectInputStream.GetField; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.InputMismatchException; import java.util.LinkedList; import java.util.Queue; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; public class Q21 { static long MOD = 1000000007; static boolean b[]; static ArrayList<Integer>[] amp; static int sum[],dist[]; static long ans = 0; static int p = 0; static FasterScanner sc = new FasterScanner(); static Queue<Integer> q = new LinkedList<>(); static ArrayList<String>[] arr; static ArrayList<Integer> parent = new ArrayList<>(); static BufferedWriter log; static HashMap<Long,Long> hm; static HashSet<String> hs = new HashSet<>(); static Stack<Integer> s = new Stack<>(); static Pair prr[]; public static void main(String[] args) throws IOException { log = new BufferedWriter(new OutputStreamWriter(System.out)); int n = sc.nextInt(); long arr[][] = new long[n][n]; Pair prr[][] = new Pair[n][n]; for(int i = 0; i < n; i++) arr[i] = sc.nextLongArray(n); HashMap<Integer,Long> hm1 = new HashMap<>(); HashMap<Integer,Long> hm2 = new HashMap<>(); int cnt = 0; for(int i = 0;i<n;i++){ long ans = 0; for(int j = 0;j<n-cnt;j++){ ans+=arr[j][j+cnt]; prr[j][j+cnt] = new Pair(cnt,0); } hm1.put(cnt, ans); cnt++; } int temp = 1; for(int i = 0;i<n-1;i++){ long ans = 0; for(int j = 0;j<n-temp;j++){ ans+=arr[j+temp][j]; prr[j+temp][j] = new Pair(cnt,0); } hm1.put(cnt, ans); cnt++; temp++; } temp =0; cnt =0; //System.out.println(hm1+" "+hm2); for(int i = 0;i<n;i++){ long ans = 0; for(int j = 0;j<n-cnt;j++){ ans+=arr[j+cnt][n-1-j]; prr[j+cnt][n-1-j].v = cnt; } hm2.put(cnt, ans); cnt++; } temp = 1; for(int i = 0;i<n-1;i++){ long ans = 0; for(int j = 0;j<n-temp;j++){ ans+=arr[n-1-j-temp][j]; prr[n-1-j-temp][j].v = cnt; } hm2.put(cnt, ans); cnt++; temp++; } for(int i =0 ;i<n;i++) { //for(int j =0 ;j <n;j++) System.out.print(prr[i][j]); //System.out.println(); } long max = -1; int ans1 = 0,ans2 = 0; for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ if(hm1.get(prr[i][j].u)+hm2.get(prr[i][j].v)-arr[i][j]>max){ max = hm1.get(prr[i][j].u)+hm2.get(prr[i][j].v)-arr[i][j]; ans1 = i;ans2 = j; } } } hm1.put(prr[ans1][ans2].u, -1000000000000000L); hm2.put(prr[ans1][ans2].v, -1000000000000000L); //System.out.println(hm1+" "+hm2); boolean b = false; if((ans1+ans2)%2==0){ b = true; } //System.out.println(max); long max1 = -1; int ans3 = 0,ans4 = 0; for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ if(b){ if((i+j)%2==1){ if(hm1.get(prr[i][j].u)+hm2.get(prr[i][j].v)-arr[i][j]>max1){ max1 = hm1.get(prr[i][j].u)+hm2.get(prr[i][j].v)-arr[i][j]; ans3 = i;ans4 = j; } } } else if(!b && (i+j)%2==0){ if(hm1.get(prr[i][j].u)+hm2.get(prr[i][j].v)-arr[i][j]>max1){ max1 = hm1.get(prr[i][j].u)+hm2.get(prr[i][j].v)-arr[i][j]; ans3 = i;ans4 = j; } } } } System.out.println(max+max1); ans1++;ans2++;ans3++;ans4++; System.out.println(ans1+" "+ans2+" "+ans3+" "+ans4); log.close(); } static long power(long x, long y, long m) { if (y == 0) return 1; long p = power(x, y/2, m) % m; p = (p * p) % m; return (y%2 == 0)? p : (x * p) % m; } private static void permutation(String prefix, String str) { int n = str.length(); if (n == 0) hs.add(prefix); else { for (int i = 0; i < n; i++) permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n)); } } public static char give(char c1,char c2){ if(c1!='a' && c2!='a') return 'a'; if(c1!='b' && c2!='b') return 'b'; return 'c'; } static class Graph{ int vertex; long weight; } public static void buildTree(int n){ int arr[] = sc.nextIntArray(n); for(int i = 0;i<n;i++){ int x = arr[i]-1; amp[i+1].add(x); amp[x].add(i+1); } } public static void bfs(int x,long arr[]){ b[x] = true; q.add(x); while(!q.isEmpty()){ int y = q.poll(); for(int i = 0;i<amp[y].size();i++) { if(!b[amp[y].get(i)]){ q.add(amp[y].get(i)); b[amp[y].get(i)] = true; } } } } public static void buildGraph(int n){ for(int i =0;i<n;i++){ int x = sc.nextInt(), y = sc.nextInt(); amp[--x].add(--y); amp[y].add(x); } } public static void dfs(int x){ b[x] = true; for(int i =0 ;i<amp[x].size();i++){ if(!b[amp[x].get(i)]){ dfs(amp[x].get(i)); } } } static class Pair implements Comparable<Pair> { int u; int v; int z; public Pair(){ } public Pair(int u, int v) { this.u = u; this.v = v; } public int hashCode() { int hu = (int) (u ^ (u >>> 32)); int hv = (int) (v ^ (v >>> 32)); return 31*hu + hv; } public boolean equals(Object o) { Pair other = (Pair) o; return (u == other.u && v == other.v); } public int compareTo(Pair other) { return Integer.compare(u, other.u) != 0 ? (Integer.compare(u, other.u)) : (Integer.compare(v, other.v)); } public String toString() { return "[u=" + u + ", v=" + v + "]"; } } static class SegmentTree{ int st[]; SegmentTree(int arr[], int n){ int size = 4*n+1; st = new int[size]; build(arr,0,n-1,0); } int build(int arr[], int ss, int se, int si){ if(ss==se){ st[si] = arr[ss]; return st[si]; } int mid = (ss+se)/2; st[si] = build(arr,ss,mid,si*2+1)^build(arr,mid+1,se,si*2+2); return st[si]; } int getXor(int qs, int qe, int ss, int se, int si){ if(qe<ss || qs>se){ return 0; } if(qs<=ss && qe>=se) return st[si]; int mid = (ss+se)/2; return getXor(qs,qe,ss,mid,2*si+1)^getXor(qs,qe, mid+1, se, 2*si+2); } void print(){ for(int i = 0;i<st.length;i++){ System.out.print(st[i]+" "); System.out.println("----------------------"); } } } static int convert(int x){ int cnt = 0; String str = Integer.toBinaryString(x); //System.out.println(str); for(int i = 0;i<str.length();i++){ if(str.charAt(i)=='1'){ cnt++; } } int ans = (int) Math.pow(3, 6-cnt); return ans; } static class Node2{ Node2 left = null; Node2 right = null; Node2 parent = null; int data; } static class BinarySearchTree{ Node2 root = null; int height = 0; int max = 0; int cnt = 1; ArrayList<Integer> parent = new ArrayList<>(); HashMap<Integer, Integer> hm = new HashMap<>(); public void insert(int x){ Node2 n = new Node2(); n.data = x; if(root==null){ root = n; } else{ Node2 temp = root,temp2 = null; while(temp!=null){ temp2 = temp; if(x>temp.data) temp = temp.right; else temp = temp.left; } if(x>temp2.data) temp2.right = n; else temp2.left = n; n.parent = temp2; parent.add(temp2.data); } } public Node2 getSomething(int x, int y, Node2 n){ if(n.data==x || n.data==y) return n; else if(n.data>x && n.data<y) return n; else if(n.data<x && n.data<y) return getSomething(x,y,n.right); else return getSomething(x,y,n.left); } public Node2 search(int x,Node2 n){ if(x==n.data){ max = Math.max(max, n.data); return n; } if(x>n.data){ max = Math.max(max, n.data); return search(x,n.right); } else{ max = Math.max(max, n.data); return search(x,n.left); } } public int getHeight(Node2 n){ if(n==null) return 0; height = 1+ Math.max(getHeight(n.left), getHeight(n.right)); return height; } } static long findDiff(long[] arr, long[] brr, int m){ int i = 0, j = 0; long fa = 1000000000000L; while(i<m && j<m){ long x = arr[i]-brr[j]; if(x>=0){ if(x<fa) fa = x; j++; } else{ if((-x)<fa) fa = -x; i++; } } return fa; } public static long max(long x, long y, long z){ if(x>=y && x>=z) return x; if(y>=x && y>=z) return y; return z; } public static void seive(long n){ b = new boolean[(int) (n+1)]; Arrays.fill(b, true); for(int i = 2;i*i<=n;i++){ if(b[i]){ for(int p = 2*i;p<=n;p+=i){ b[p] = false; } } } } static long modInverse(long a, long mOD2){ return power(a, mOD2-2, mOD2); } static long power2(long x,BigInteger y,long m){ long ans = 1; BigInteger two = new BigInteger("2"); while(y.compareTo(BigInteger.ZERO)>0){ if(y.getLowestSetBit()==y.bitCount()){ x = (x*x)%MOD; y = y.divide(two); } else{ ans = (ans*x)%MOD; y = y.subtract(BigInteger.ONE); } } return ans; } static BigInteger power2(BigInteger x, BigInteger y, BigInteger m){ BigInteger ans = new BigInteger("1"); BigInteger one = new BigInteger("1"); BigInteger two = new BigInteger("2"); BigInteger zero = new BigInteger("0"); while(y.compareTo(zero)>0){ //System.out.println(y); if(y.mod(two).equals(one)){ ans = ans.multiply(x).mod(m); y = y.subtract(one); } else{ x = x.multiply(x).mod(m); y = y.divide(two); } } return ans; } static BigInteger power(BigInteger x, BigInteger y, BigInteger m) { if (y.equals(0)) return (new BigInteger("1")); BigInteger p = power(x, y.divide(new BigInteger("2")), m).mod(m); p = (p.multiply(p)).mod(m); return (y.mod(new BigInteger("2")).equals(0))? p : (p.multiply(x)).mod(m); } static long d,x,y; public static void extendedEuclidian(long a, long b){ if(b == 0) { d = a; x = 1; y = 0; } else { extendedEuclidian(b, a%b); int temp = (int) x; x = y; y = temp - (a/b)*y; } } public static long gcd(long n, long m){ if(m!=0) return gcd(m,n%m); else return n; } public static class FasterScanner { private byte[] buf = new byte[1024]; private int curChar; private int numChars; public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { return nextIntArray(n, 0); } public int[] nextIntArray(int n, int off) { int[] arr = new int[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextInt(); } return arr; } public long[] nextLongArray(int n) { return nextLongArray(n, 0); } public long[] nextLongArray(int n, int off) { long[] arr = new long[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
6a6a9058132df98648adceadaf9dd22c
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.StringTokenizer; import java.io.PrintWriter; public class Ideone { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class aksh { int x, y; public aksh(int a, int b) { x = a; y = b; } } public static void main (String[] args) throws java.lang.Exception { // your code goes here FastReader sc=new FastReader(); int n=sc.nextInt(); int ch[][]=new int[n][n]; for(int i=0; i<n; i++) for(int j=0; j<n; j++) ch[i][j]=sc.nextInt(); long pd[]=new long[2*n-1]; long sd[]=new long[2*n-1]; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { pd[n-1-i+j]+=ch[i][j]; sd[i+j]+=ch[i][j]; } } long vals[][]=new long[n][n]; for(int i=0; i<n; i++) for(int j=0; j<n; j++) vals[i][j]+=pd[n-1-i+j]+sd[i+j]-ch[i][j]; int x1=0,y1=0,x2=0,y2=0; long val1=-1,val2=-1; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { if((i+j)%2==0&&val1<vals[i][j]) { val1=vals[i][j]; x1=i; y1=j; } if((i+j)%2!=0&&val2<vals[i][j]) { val2=vals[i][j]; x2=i; y2=j; } } } x1++; x2++; y1++; y2++; System.out.println(val1+val2); System.out.println(x1+" "+y1+" "+x2+" "+y2); } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
605679cd45efa4d77a1f8c990cddd498
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] agrs) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int a[][] = new int[n + 1][n + 1]; int x[] = new int[2], y[] = new int[2]; long d1[] = new long[2 * (n + 1)], d2[] = new long[2 * (n + 1)]; long res[] = new long[2]; for (int i = 1; i <= n; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); for (int j = 1; j <= n; j++) { a[i][j] = Integer.parseInt(st.nextToken()); d1[i + j] += a[i][j]; d2[i - j + n] += a[i][j]; } } res[0] = res[1] = -1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { int pos = (i + j) & 1; long sum = d1[i + j] + d2[i - j + n] - a[i][j]; if (sum > res[pos]) { res[pos] = sum; x[pos] = i; y[pos] = j; } } } System.out.println(res[0] + res[1]); System.out.println(x[0] + " " + y[0] + " " + x[1] + " " + y[1]); } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
8a027f63bde476e1b1ae35892f067047
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.util.*; import java.io.*; public class GargariBishops { private static long sum(int r, int c, int[][] grid) { long total = grid[r][c]; int tempR = r; int tempC = c; /* int[] arrayX = new int[] {1,1,-1,-1}; int[] arrayY = new int[] {1,-1,1,-1}; for (int x = 0; x < 4; x++) { while (true) { tempR += arrayX[x]; tempC += arrayY[x]; if (tempR >= 0 && tempC >= 0 && tempR < grid.length && tempC < grid.length) { total += grid[tempR][tempC]; } else { break; } } tempR = r; tempC = c; } */ return total; } private static long[] totals1,totals2; public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int quant = Integer.parseInt(in.readLine()); int[][] grid = new int[quant][quant]; for (int x = 0; x < quant; x++) { StringTokenizer s1 = new StringTokenizer(in.readLine()); for (int y = 0; y < quant; y++) { grid[x][y] = Integer.parseInt(s1.nextToken()); } } totals1 = new long[2*quant-1]; totals2 = new long[2*quant-1]; for (int x = 0; x < quant; x++) { for (int y = 0; y < quant; y++) { totals1[x+y] += grid[x][y]; totals2[x+quant-y-1] += grid[x][y]; } } long[][] total = new long[quant][quant]; for (int x = 0; x < quant; x++) { for (int y = 0; y < quant; y++) { total[x][y] = totals1[x+y]+totals2[x+quant-y-1]-grid[x][y]; //sum(x,y,grid); } } long maxEven = 0; int evenX = -1; int evenY = -1; long maxOdd = 0; int oddX = -1; int oddY = -1; for (int x = 0; x < quant; x++) { for (int y = 0; y < quant; y++) { //System.out.println(total[x][y]); if ( (x+y) % 2 == 0 && maxEven < total[x][y]) { maxEven = total[x][y]; evenX = x; evenY = y; } else if ( (x+y) % 2 == 1 && maxOdd < total[x][y]) { maxOdd = total[x][y]; oddX = x; oddY = y; } } } if(evenX < 0 && evenY < 0) { evenX = 0; evenY = 0; } if(oddX < 0 && oddY < 0) { oddX = 0; oddY = 1; } System.out.println(maxEven+maxOdd); System.out.println((evenX+1) + " " + (evenY+1) + " " + (oddX+1) + " " + (oddY+1)); } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
06e7d6fa3c5349cd6dfef61999d9719c
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.*; public class Solution { static StreamTokenizer in = new StreamTokenizer(new BufferedReader( new InputStreamReader(System.in))); static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static int nextInt() throws IOException { in.nextToken(); return (int)in.nval; } static long f (int n, int i, int j, int[][] v, long[] v1, long[] v2, long []v3, long []v4) { long r = -v[i][j]; if (i <= j) { r += v2[j - i]; } else { r += v1[i - j]; } if (i + j < n) { r += v3[i + j]; } else { r += v4[i + j - n + 1]; } return r; } public static void main(String[] args) throws IOException { int i, n = nextInt(), j = 0, x1 = 1, y1 = 1, x2 = 1, y2 = 2; long r1 = 0, r2 = 0, z; int [][]v = new int[n][n]; for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { v[i][j] = nextInt(); } } long []v1 = new long[n], v2 = new long[n], v3 = new long[n], v4 = new long[n]; for (i = 0; i < n; ++i) { for (j = 0; i + j < n; ++j) { v1[i] += v[i + j][j]; v2[i] += v[j][i + j]; v4[i] += v[i + j][n - 1 - j]; } } for (i = 0; i < n; ++i) { for (j = 0; j <= i; ++j) { v3[i] += v[j][i - j]; } } for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { z = f(n, i, j, v, v1, v2, v3, v4); if ((i + j) % 2 == 0) { if (r1 < z) { r1 = z; x1 = i; y1 = j; } } else { if (r2 < z) { r2 = z; x2 = i; y2 = j; } } } } out.println(r1 + r2); out.println((x1 + 1) + " " + (y1 + 1) + " " + (x2 + 1) + " " + (y2 + 1)); out.flush(); } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
4526fbd2cc8085b1a4915bad6a7a0c68
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class CF463C { //***************************************** VARIABLE DECLERATION SECTION ********************************************************************; //static ArrayList<Integer> al; //static PriorityQueue<Integer> pq; //static TreeMap<Integer,Integer> tm; //static TreeSet<Integer> ts; //static ArrayList<ArrayList<Integer>> graph; // static int[][] dp; //***************************************** VARIABLE DECLERATION ENDS ********************************************************************; //************************************************ MAIN FUNCTION *************************************************************************; public static void main(String[] args) { //al=new ArrayList<Integer>(); //graph=new ArrayList<ArrayList<Integer>>();op //pq=new PriorityQueue<Integer>(); //ts=new TreeSet<Integer>(); //tm=new TreeMap<Integer,Integer>(); //dp=new int[][]; //System.out.println(""); FastReader scan=new FastReader(); { int n=scan.nextInt(); long[][] arr=new long[n][n]; long[][] dp1=new long[n][n]; long[][] dp2=new long[n][n]; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { arr[i][j]=scan.nextLong(); dp1[i][j]=arr[i][j]; dp2[i][j]=arr[i][j]; if(i>0&&j>0) dp1[i][j]+=dp1[i-1][j-1]; if(i>0&&j<n-1) dp2[i][j]+=dp2[i-1][j+1]; } } long[][] res=new long[n][n]; //Arrays.fill(res,0); for(int i=0;i<n;i++) { int k=0; while(i-k>=0&&k<n) { res[i-k][k]=dp2[i][0]; k++; } } for(int j=1;j<n;j++) { int k=0; while(n-1-k>=0&&j+k<n) { res[n-1-k][j+k]=dp2[n-1][j]; k++; } } for(int i=0;i<n-1;i++) { int k=0; while(i-k>=0&&n-1-k>0) { res[i-k][n-1-k]+=dp1[i][n-1]; k++; } } for(int j=0;j<n;j++) { int k=0; while(n-1-k>=0&&j-k>=0) { res[n-1-k][j-k]+=dp1[n-1][j]; k++; } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { res[i][j]-=arr[i][j]; } } /*System.out.println("*****"); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) System.out.print(res[i][j]+" "); System.out.println(""); }*/ int xb=0,yb=0,xw=0,yw=1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if((i+j)%2==0) { if(res[i][j]>res[xb][yb]){xb=i;yb=j;} } else { if(res[i][j]>res[xw][yw]){xw=i;yw=j;} } } } System.out.println(res[xb][yb]+res[xw][yw]); System.out.println((1+xb)+" "+(1+yb)+" "+(1+xw)+" "+(1+yw)); } } //*********************************************** MAIN FUNCTION ENDS *********************************************************************; //********************************************** AUXILIARY FUNCTIONS **********************************************************************; /*static void function() { }*/ //********************************************** AUXILIARY FUNCTIONS ENDS **********************************************************************; //********************************************** INPUT FUNCTIONS ******************************************************************************; static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } //********************************************** INPUT FUNCTIONS ******************************************************************************; }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
a5f608fad41d0bcb5633aea184850d87
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.util.*;import java.io.*;import java.math.*; public class Main { public static void process()throws IOException { int n=ni(); long[][]A=new long[n][n]; for(int i=0;i<n;i++) for(int j=0;j<n;j++) A[i][j]=nl(); int[][]fl=new int[n][n]; int[][]fr=new int[n][n]; ArrayList<Long>left = new ArrayList<>(); ArrayList<Long>right = new ArrayList<>(); for(int i=n-1;i>=0;i--) { long temp=0; for(int j=0;j<n;j++) { if(i+j>=n) break; temp+=A[i+j][j]; fl[i+j][j]=left.size(); } left.add(temp); } for(int i=1;i<n;i++) { long temp=0; for(int j=i;j<n;j++) { temp+=A[j-i][j]; fl[j-i][j]=left.size(); } left.add(temp); } for(int i=n-1;i>=0;i--) { long temp=0; int c=i; for(int j=n-1;j>=0;j--) { if(c>=n) break; temp+=A[c][j]; fr[c][j]=right.size(); c++; } right.add(temp); } for(int i=n-2;i>=0;i--) { long temp=0; int c=0; for(int j=i;j>=0;j--) { temp+=A[c][j]; fr[c][j]=right.size(); c++; } right.add(temp); } long m1=-1l,m2=-1l; int x1=0,x2=0,y1=0,y2=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { long temp=left.get(fl[i][j])+right.get(fr[i][j])-A[i][j]; if((i+j)%2==0) { if(m1<temp) { m1=temp; x1=i+1; y1=j+1; } } else { if(m2<temp) { m2=temp; x2=i+1; y2=j+1; } } } } pn(m1+m2); pn(x1+" "+y1+" "+x2+" "+y2); } static AnotherReader sc; static PrintWriter out; public static void main(String[]args)throws IOException { boolean oj = System.getProperty("ONLINE_JUDGE") != null; if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);} else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");} int t=1; // t=ni(); while(t-->0) {process();} out.flush();out.close(); } static void pn(Object o){out.println(o);} static void p(Object o){out.print(o);} static void pni(Object o){out.println(o);out.flush();} static int ni()throws IOException{return sc.nextInt();} static long nl()throws IOException{return sc.nextLong();} static double nd()throws IOException{return sc.nextDouble();} static String nln()throws IOException{return sc.nextLine();} static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;} static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;} static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));} ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class AnotherReader{BufferedReader br; StringTokenizer st; AnotherReader()throws FileNotFoundException{ br=new BufferedReader(new InputStreamReader(System.in));} AnotherReader(int a)throws FileNotFoundException{ br = new BufferedReader(new FileReader("input.txt"));} String next()throws IOException{ while (st == null || !st.hasMoreElements()) {try{ st = new StringTokenizer(br.readLine());} catch (IOException e){ e.printStackTrace(); }} return st.nextToken(); } int nextInt() throws IOException{ return Integer.parseInt(next());} long nextLong() throws IOException {return Long.parseLong(next());} double nextDouble()throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException{ String str = ""; try{ str = br.readLine();} catch (IOException e){ e.printStackTrace();} return str;}} ///////////////////////////////////////////////////////////////////////////////////////////////////////////// }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
39f606bd6a2d78cedea708ce0fce003c
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; public class C463 { public static BufferedReader in; public static PrintWriter out; public static StringTokenizer tokenizer; public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; in = new BufferedReader(new InputStreamReader(inputStream), 32768); out = new PrintWriter(outputStream); solve(); out.close(); } public static void solve() { int n = nextInt(); long[] d1 = new long[2 * n]; long[] d2 = new long[2 * n]; long[][] map = new long[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { long x = nextLong(); d1[i + j] += x; d2[n + i - j - 1] += x; map[i][j] = x; } } int[][] result = new int[2][2]; long[] sum = new long[2]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int r = (i + j) % 2; if (d1[i + j] + d2[n + i - j - 1] - map[i][j] >= sum[r]) { sum[r] = d1[i + j] + d2[n + i - j - 1] - map[i][j]; result[r][0] = i + 1; result[r][1] = j + 1; } } } out.println(sum[0] + sum[1]); out.println(result[0][0] + " " + result[0][1] + " " + result[1][0] + " " + result[1][1]); } public static String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(in.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public static int nextInt() { return Integer.parseInt(next()); } public static long nextLong() { return Long.parseLong(next()); } public static double nextDouble() { return Double.parseDouble(next()); } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
d6f690c011c727120701cd39d05dd468
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.util.*; import java.io.*; public class codeforces { public static void main(String args []) { InputReader obj = new InputReader(System.in); int n = obj.nextInt(); int arr[][] = new int[n][n]; HashMap<Integer, Long> d1 = new HashMap<Integer, Long>(); HashMap<Integer, Long> d2 = new HashMap<Integer, Long>(); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { arr[i][j]=obj.nextInt(); if(d1.get(i-j)==null) { d1.put(i-j, (long)arr[i][j]); } else { d1.put(i-j, (long)arr[i][j]+(long)d1.get(i-j)); } if(d2.get(i+j)==null) { d2.put(i+j, (long)arr[i][j]); } else { d2.put(i+j, (long)arr[i][j]+(long)d2.get(i+j)); } } } int x1=-1; int x2=-1; int y2=-1; int y1=-1; long val1=0; long val2=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if((i+j)%2==0) { if(d1.get(i-j)+d2.get(i+j)-arr[i][j]>=val1) { val1=d1.get(i-j)+d2.get(i+j)-arr[i][j]; x1=i+1; y1=j+1; } } else { if(d1.get(i-j)+d2.get(i+j)-arr[i][j]>=val2) { val2=d1.get(i-j)+d2.get(i+j)-arr[i][j]; x2=i+1; y2=j+1; } } } } System.out.println((val1+val2)); System.out.print(x1+" "+y1+" "+x2+" "+y2); } public 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()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
cb039cb49a5636af18b1b6b328413d2d
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class cf { public static void main(String args[])throws IOException { PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); Reader sc = new Reader(); int n = sc.nextInt(); int arr[][]=new int[n][n]; int counter1=0;int counter2=0; long scounter[]=new long[n+5000]; long dcounter[]=new long[n+5000]; for(int i = 0 ;i<n;i++) { for(int j = 0 ;j<n;j++) arr[i][j]=sc.nextInt(); } for(int i = 0 ;i<n;i++) { for(int j =0;j<n;j++) { scounter[i+j+2005]+=arr[i][j]; dcounter[i-j+2005]+=arr[i][j]; } } long max1=-1; long max2=-1; long x1=-1; long y1=-1; long x2=-1; long y2=-1; long sum =0; for(int i=0;i<n;i++) { for(int j = 0 ;j<n;j++) { sum=0; sum += scounter[i+j+2005]; sum += dcounter[i-j+2005]; sum-=arr[i][j]; if((i+j)%2==0) { if(sum>max1) { max1=sum; x1=i; y1=j; } } else { if(sum>max2) { max2=sum; x2=i; y2=j; } } } } out.println(max1+max2); out.println((x1+1)+" "+(y1+1)+" "+(x2+1)+" "+(y2+1)); out.close(); } } class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
c8f58fa0ede3d55fd2dd69a4ae9c5fc3
train_002.jsonl
1409383800
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
256 megabytes
/* Author: prakashn ProblemLink: Thanks to uwi for the code template */ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Task463C { InputStream is; PrintWriter out; String INPUT = "\n" + "4\n" + "1 1 1 1\n" + "2 1 1 0\n" + "1 1 1 0\n" + "1 0 0 1"; void solve() { int n = ni(); int[][] a = new int[n][n]; for(int i = 0; i < n; i++) { a[i] = na(n); } // printa(a); long[][] l = new long[n][n]; long[][] r = new long[n][n]; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(i == 0 || j == 0) l[i][j] = a[i][j]; else l[i][j] = l[i-1][j-1] + a[i][j]; } } for(int i = n-1; i >= 0; i--) { for(int j = n-1; j >= 0; j--) { if(i == n-1 || j == n-1) continue; else l[i][j] = l[i+1][j+1]; } } // printa(l); for(int i = 0; i < n; i++) { for(int j = n-1; j >= 0; j--) { if(i == 0 || j == n-1) r[i][j] = a[i][j]; else r[i][j] = r[i-1][j+1] + a[i][j]; } } for(int i = n-1; i >= 0; i--) { for(int j = 0; j < n; j++) { if(i == n-1 || j == 0) continue; else r[i][j] = r[i+1][j-1]; } } // printa(r); long[][] b = new long[n][n]; long max = Integer.MIN_VALUE; int x1 = -1, y1 = -1; long max2 = Integer.MIN_VALUE; int x2 = -1, y2 = -1; boolean isEven = true; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { b[i][j] = l[i][j] + r[i][j] - a[i][j]; isEven = (i+j) % 2 == 0; if(max < b[i][j] && isEven) { max = b[i][j]; x1 = i; y1 = j; } if(max2 < b[i][j] && !isEven) { max2 = b[i][j]; x2 = i; y2 = j; } } } // printa(b); // // for(int i = 0; i < n; i++) { // for(int j = 0; j < n; j++) { // if(max2 < b[i][j]) { // if(i == x1 && j == y1) continue; // max2 = b[i][j]; // x2 = i; // y2 = j; // } // } // } out.println(max+max2); out.println((x1+1) + " " + (y1+1) + " " + (x2+1) + " " + (y2+1)); } void printa(int[][] a) { out.printf("\t"); for(int i = 0; i < a[0].length; i++) out.printf("%5d ", i); out.println(); out.println("----------------"); for(int i = 0; i < a.length; i++) { out.printf(i + " =>" ); for(int j = 0; j < a[i].length; j++) { out.printf("%5d ", a[i][j]); } out.println(); } out.println(); } void run() throws Exception { is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(System.currentTimeMillis() - s + "ms"); } public static void main(String[] args) throws Exception { new Task463C().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char) skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if (!oj) System.out.println(Arrays.deepToString(o)); } }
Java
["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"]
3 seconds
["12\n2 2 3 2"]
null
Java 8
standard input
[ "implementation", "hashing", "greedy" ]
a55d6c4af876e9c88b43d088f2b81817
The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard.
1,900
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them.
standard output
PASSED
6c6edbbe451eea1a578cbb7490aede5c
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner (System.in); int numOfLines = in.nextInt(); int length = numOfLines - 1; int [] result = new int [numOfLines]; while (numOfLines > 0) { int coder = in.nextInt(); int math = in.nextInt(); int other = in.nextInt(); int small = Math.min(coder, math); if (small <= (other+math+coder)/3) { result[numOfLines - 1] = small; } else { result[numOfLines - 1] = (coder + math + other) / 3; } --numOfLines; } while (length >= 0) { System.out.println(result[length]); --length; } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
3b5913efeaf33b6a11127e8465bceed3
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner in=new Scanner(System.in); int q=in.nextInt(); for(int i=0;i<q;i++) { int a=in.nextInt(); int b=in.nextInt(); int c=in.nextInt(); int min1=Math.min(a,b); int min2=min1; min1=Math.min(min1,c); if(min1<min2) { int s=a+b+c; s=s/3; if(s<=min2) System.out.println(s); else System.out.println(min2); } else System.out.println(min2); } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
c257041cf3cd6c186dbe5ce9842f8087
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.util.*; public class C1221 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); for (int tt = scan.nextInt(), t = 1; t <= tt; ++t) { int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); System.out.println(Math.min(Math.min(a, b), (a + b + c) / 3)); } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
d8c47bb9b76bd55bf9657c2f554db087
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.*; import java.util.*; public class cp1 { static int find(int a, int b){ if(a >= 2 * b) return b; if(b >= 2 * a) return a; return (a + b) / 3; // if(a>=2*b) // return b; // else if(b>=2*a) // return a; // else if((a+b)%3==0) // return (a+b)/3; // int ans=(a+b)/3; // a=a%3; // b=b%3; // if(a>0 && b>0 && a+b>=3) // ans++; // return ans; } public static void main(String args[]) { int t=II(); while(--t>=0){ int c=II(); int m=II(); int x=II(); int min=Math.min(c, Math.min(m, x)); c=c-min; m=m-min; x=x-min; if(c==0 || m==0){ System.out.println(min); } else{ // System.out.println(c+"//"+m); System.out.println(min+find(c, m)); } } } //////////////////////////////////// static scan in=new scan(System.in); static int II() { return in.nextInt(); } static long IL() { return in.nextLong(); } static int[] IIA(int n) { int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=II(); } return a; } static String IS() { return in.next(); } static char IC(){ return in.next().charAt(0); } static String[] ISA(int n) { String a[]=new String[n]; for(int i=0;i<n;i++) { a[i]=IS(); } return a; } static char[] ICA(int n) { char a[]=new char[n]; for(int i=0;i<n;i++) { a[i]=IC(); } return a; } } class scan { public static BufferedReader reader; public static StringTokenizer token; scan(InputStream str) { reader=new BufferedReader(new InputStreamReader(str)); token=null; } static int nextInt() { while(token==null||!token.hasMoreTokens()) { try { token=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return Integer.parseInt(token.nextToken()); } static long nextLong() { while(token==null||!token.hasMoreTokens()) { try { token=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return Long.parseLong(token.nextToken()); } static String next() { while(token==null||!token.hasMoreTokens()) { try { token=new StringTokenizer(reader.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } return token.nextToken(); } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
4b3468a1f0c92d2016406b593010c939
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.util.*; import java.io.*; public class A { public static void main(String[] args) throws Exception { // FileInputStream inputStream = new FileInputStream("input.txt"); // FileOutputStream outputStream = new FileOutputStream("output.txt"); InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.solve(1, in, out); out.close(); } static class Solver { public void solve(int testNumber, InputReader in, PrintWriter out) { int t = in.nextInt(); for (int tt = 0 ; tt < t ; tt++) { int c = in.nextInt(); int m = in.nextInt(); int x = in.nextInt(); int l = -1; int r = 100000001; while (l < r - 1) { int mid = (l + r) / 2; if (canBuild(mid, c, m, x)) { l = mid; } else { r = mid; } } out.println(l); } } public static boolean canBuild(int teams, int c, int m, int x) { if (c != m) { x += Math.max(c, m) - Math.min(c, m); int d = Math.min(c, m); c = d; m = d; } int cnt = Math.min(c, x); c -= cnt; m -= cnt; cnt += (c + m) / 3; return (teams <= cnt); } } 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()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public float nextFloat() { return Float.parseFloat(next()); } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
58144dcbc6458ca4ebb1abc848371b89
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.util.*; import java.io.*; public class A { public static void main(String[] args) throws Exception { // FileInputStream inputStream = new FileInputStream("input.txt"); // FileOutputStream outputStream = new FileOutputStream("output.txt"); InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.solve(1, in, out); out.close(); } static class Solver { public void solve(int testNumber, InputReader in, PrintWriter out) { int t = in.nextInt(); for (int tt = 0 ; tt < t ; tt++) { int c = in.nextInt(); int m = in.nextInt(); int x = in.nextInt(); int l = -1; int r = 100000001; while (l < r - 1) { int mid = (l + r) / 2; if (canBuild(mid, c, m, x)) { l = mid; } else { r = mid; } } out.println(l); } } public static boolean canBuild(int teams, int c, int m, int x) { if (x <= Math.min(c, m)) { int cnt = x; c -= x; m -= x; cnt += Math.min((c + m) / 3, Math.min(c, m)); return (teams <= cnt); } else return (teams <= Math.min(c, m)); } } 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()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public float nextFloat() { return Float.parseFloat(next()); } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
c18f75d70a9c4056fdcccf0dba66509b
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
//package Div3; import java.io.*; import java.util.StringTokenizer; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; import java.util.Queue; import java.util.HashMap; import java.util.TreeSet; import java.util.TreeMap; import java.util.Arrays; import java.util.Collections; public class Submission { public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int q = sc.nextInt(); while (q-- > 0) { long n = sc.nextLong(); long m = sc.nextLong(); long ans = Math.min(n, Math.min(m, (n + m + sc.nextLong()) / 3)); System.out.println(ans); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } 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(4000); } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
8d48d33ae81f26ffebc8aa2fae0905c3
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
//package Jobeel; import java.util.*; import java.io.*; import java.lang.*; import java.math.*; import java.util.Map.*; public class codeforces { static int count =0; static boolean f=false; static int [] arr; static PrintWriter pw=new PrintWriter(System.out); static void bruteforce(int index,int mask) { if(index==arr.length) { int sum=0; for(int i=0;i<arr.length;i++) if((mask & 1<<i)!=0) sum+=arr[i]; if(sum==count-sum) f=true; return; } bruteforce(index+1, mask|1<<index); bruteforce(index+1, mask); } public static void main(String [] args) throws IOException, InterruptedException { Scanner sc=new Scanner(System.in); int x=sc.nextInt(); while(x-->0) { int coders =sc.nextInt(); int math=sc.nextInt(); int no=sc.nextInt(); pw.println(Math.min(Math.min(coders, math), (coders+math+no)/3)); } pw.flush(); pw.close(); } static class pair implements Comparable<pair>{ String name; int x,y ; public pair(String name , int x) { this.name=name; this.x=x; } public pair (int x,int y) { this.x=x; this.y=y; } public int compareTo(pair o) { if(!name.equals(o.name)) return name.compareTo(o.name); return x-o.x; } public String toString() { return name +" "+x; } } 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); } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
a5d34d384fcdeb57a4fbccdbaca29915
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class e { public static class FastReader { BufferedReader br; StringTokenizer st; //it reads the data about the specified point and divide the data about it ,it is quite fast //than using direct public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception r) { r.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next());//converts string to integer } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception r) { r.printStackTrace(); } return str; } } static ArrayList<String>list1=new ArrayList<String>(); static void combine(String instr, StringBuffer outstr, int index,int k) { if(outstr.length()==k) { list1.add(outstr.toString());return; } if(outstr.toString().length()==0) outstr.append(instr.charAt(index)); for (int i = 0; i < instr.length(); i++) { outstr.append(instr.charAt(i)); combine(instr, outstr, i + 1,k); outstr.deleteCharAt(outstr.length() - 1); } index++; } static ArrayList<ArrayList<Integer>>l=new ArrayList<>(); static void comb(int n,int k,int ind,ArrayList<Integer>list) { if(k==0) { l.add(new ArrayList<>(list)); return; } for(int i=ind;i<=n;i++) { list.add(i); comb(n,k-1,ind+1,list); list.remove(list.size()-1); } } static class Pair implements Comparable<Pair>{ int x;int y; Pair(int x,int y){ this.x=x; this.y=y; // this.i=i; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return (o.x*y-o.y*x); } } public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out)); static HashMap<Long, Pair> sort(HashMap<Long, Pair> hm) { // Create a list from elements of HashMap List<Map.Entry<Long, Pair> > list = new LinkedList<Map.Entry<Long, Pair> >(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator<Map.Entry<Long, Pair> >() { public int compare(Map.Entry<Long, Pair> o1, Map.Entry<Long, Pair> o2) { return (o1.getValue().y)-(o2.getValue().y); } }); // put data from sorted list to hashmap HashMap<Long, Pair> temp = new LinkedHashMap<Long, Pair>(); for (Map.Entry<Long, Pair> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static long ncr(long n, int k) { long m=(long)1e9+7; long C[] = new long[k + 1]; // nC0 is 1 C[0] = 1; for (int i = 1; i <= n; i++) { // Compute next row of pascal // triangle using the previous row for (int j = Math.min(i, k); j > 0; j--) C[j] = (C[j]%m + C[j-1]%m)%m; } return C[k]%m; } static long high(long n) { long p = (long)(Math.log(n) / Math.log(2L)); return (long)Math.pow(2L, p); } static int findd(int a){ if (parent[a]!=a){ parent[a] = findd(parent[a]); } return parent[a]; } static int parent[]; static ArrayList<Integer>list=new ArrayList<Integer>(); static HashMap<Integer,Integer>map; static boolean find(int n,int f) { if(map.containsKey(n)) { if(map.get(n)>=f) { map.put(n, map.get(n)-f); if(map.get(n)==0) map.remove(n); return true; } else { f-=map.get(n); map.remove(n); if(find(n/2,2*f)) return true; else return false; } } else if(n>1) { if(find(n/2,2*f)) return true; else return false; } else return false; } public static void main(String[] args) { // TODO Auto-generated method stub FastReader in=new FastReader(); ArrayList<String>list=new ArrayList<String>(); TreeSet<Character>set=new TreeSet<Character>(); int t=in.nextInt(); while(t-->0) { int c=in.nextInt(); int m=in.nextInt(); int x=in.nextInt(); int min=Math.min(c, Math.min(m, x)); c-=min;m-=min; int ans=min; ans+=Math.min(c, Math.min(m, (c+m)/3)); out.println(ans); } out.close(); } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
ee2ac967abef9f00564e3f6869ea8d93
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.util.*; public class a { static int mod = (int) 1e9 + 7; static int Infinity=Integer.MAX_VALUE; static int negInfinity=Integer.MIN_VALUE; public static void main(String args[]) { Scanner d= new Scanner(System.in); int q,x,c,m,min,l,h,mid,z,st; q=d.nextInt(); st=0; for(;q>0;q--) { z=0; c=d.nextInt(); m=d.nextInt(); x=d.nextInt(); min=Math.min(c,m); if(min<=x) System.out.println(min); else { x+=(c-min)+(m-min); h=min; l=1; if(min<=x) System.out.println(min); else{ while(l<=h) { mid=(l+h)/2; if((min-mid)>(x+mid*2)) l=mid+1; else if((min-mid)<(x+mid*2)) { h=mid-1; st=min-mid; } else {System.out.println(min-mid); z=1; break;} } if(z==0) System.out.println(st); } } } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
3496916f1796b9595607ddc8e93f4d79
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader sc = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(1, sc, out); out.close(); } static class Task { public boolean check(int ans,int c,int m,int x) { if(ans>c||ans>m) return false; if(ans*3>c+m+x) return false; return true; } public void solve(int testNumber, InputReader sc, PrintWriter out) { int q=sc.nextInt(); while(q-->0) { int c=sc.nextInt(); int m=sc.nextInt(); int x=sc.nextInt(); int a=Math.min(c, m); int ans=0; int l=0; int r=(int) (1e8+50); while(l<=r) { int mid=(l+r)>>1; if(check(mid,c,m,x)) { ans=mid; l=mid+1; } else r=mid-1; } out.println(ans); } } } 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()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
840e4e61c6f414d665192c89bc1f1455
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class CF1221C { public static void main(String[] args) { FastReader input = new FastReader(); int q = input.nextInt(); while(q > 0){ long a = input.nextLong(); long b = input.nextLong(); long c = input.nextLong(); int low = 0; int high = 100000000; int mid = 0; int ans = 0; while(low <= high){ mid = (low + high) / 2; boolean con = false; if(mid <= a && mid <= b){ long left = (a - mid + b - mid); if(c + left >= mid){ con = true; } } if(con){ ans = mid; low = mid + 1; } else{ high = mid - 1; } } System.out.println(ans); q--; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
ed05cf6cf1872988904a1cbb881a7322
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class CF1221C { public static void main(String[] args) { FastReader input = new FastReader(); int q = input.nextInt(); while(q > 0){ long a = input.nextLong(); long b = input.nextLong(); long c = input.nextLong(); System.out.println(Math.min(Math.min(a,b),(a+b+c)/3)); q--; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
1b9f6de87af0601c86fc5a56d1aec0e5
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; import java.util.TreeMap; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int n=in.nextInt(); while(n>0){ int x=in.nextInt(); int y=in.nextInt(); int z=in.nextInt(); int min=Math.min(x,y); min=Math.min(min,z); int ans=min; x=x-min; y=y-min; z=z-min; if(x==0||y==0){ out.println(ans); n--; continue; } else{ if(x!=y){ int mn=Math.min(x,y); int mx=Math.max(x,y); int gap=mx-mn; gap = Math.min(gap,mn); mn=mn-gap; mx=mx-2*gap; ans+=gap; x=Math.min(mx,mn); y=x; } ans+=(x+y)/3; out.println(ans); } n--; } out.close(); } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
3c9af878e602e49e44b3a74af3a0e0da
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; public class CR73A { static FastReader sc = new FastReader(); static OutputStream outputstream = System.out; static PrintWriter out = new PrintWriter(outputstream); static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { int q = sc.nextInt(); for(int i = 1; i <= q; i++) { long c = sc.nextLong(), m = sc.nextLong(), x = sc.nextLong(); // if(i==185) { // out.println(c + "," + m + "," + x); // continue; // } long common = Math.min(c, m); long rest = 0; if(c>=m) { rest = c-common; } else { rest = m - common; } long ans = 0; if(c==0 || m==0) { ans = 0; } else if(x>=common) { ans = common; } else { ans = x; c -= x; m -= x; long min = Math.min(c, m); long max = Math.max(c, m); long l = 1, r = min; long tmp = 0; while(l<=r) { long mid = (r+l)/2; long restm = min - mid; long restmx = max - mid; long minm = restm+restmx; // minm *= 2; minm = Math.min(minm,mid); if(minm>tmp) { tmp = minm; l = tmp+1; } else { r = mid-1; } // out.println(mid + " " + tmp); } ans += tmp; } out.println(ans); } out.close(); } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
f9f2e5ca6bc91996a3a55b49df8a8f0b
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class a{ static int[] count,count1; static Node[] arr; static char[] ch,ch1; static long[] darr; static long[][] mat; static long x; static long maxl; static double dec; static String s; // static long minl; static int mx = (int)1e6; static long mod = 998244353l; // static int minl = -1; // static long n; static int n,n1,n2; static long a; static long b; static long c; static long d; static long y; static long m; static long k; static int q; static String[] str,str1; static Set<Character> set,set1; static List<Long> list; static Map<Long,Integer> map; static StringBuilder sb; public static void solve(){ long first = Math.min(Math.min(m,c),x); x -= first; m -= first; c -= first; if((m == 0 )|| (c == 0)){ System.out.println(first); return; } if(Math.abs(m-c) >= Math.min(m,c)){ first += Math.min(m,c); System.out.println(first); return; } first += Math.abs(m-c); long j = Math.abs(m-c); m -= j; c -= j; if(m > c) m = c; else c = m; if((m == 0 )|| (c == 0)){ System.out.println(first); return; } System.out.println(first + (m+c)/3); } public static void main(String[] args) { FastScanner sc = new FastScanner(); // Scanner sc = new Scanner(System.in); int t = sc.nextInt(); // int t = 1; while(t > 0){ // set = new HashSet<>(); // map = new HashMap<>(); // x = sc.nextLong(); // y = sc.nextLong(); // n = sc.nextInt(); // n1 = sc.nextInt(); // n1 = sc.nextInt(); // a = sc.nextLong(); // b = sc.nextLong(); c = sc.nextLong(); // d = sc.nextLong(); // k = sc.nextLong(); // d = sc.nextLong(); // n = sc.nextLong(); // x = sc.nextLong(); // ch = sc.next().toCharArray(); // ch1 = sc.next().toCharArray(); // s = sc.next(); // long x = sc.nextLong(); // k = sc.nextLong(); // dec = sc.nextDouble(); // n = sc.nextInt(); m = sc.nextLong(); x = sc.nextLong(); // arr = new Node[n]; // for(int i = 0; i < n ; i++){ // arr[i] = new Node(sc.nextInt(),i+1); // } // // set = new HashSet<>(); // for(int i = 0 ; i < n ; i++) // set.add(sc.next().charAt(0)); // n1 = sc.nextInt(); // darr = new long[n1]; // for(int i = 0; i < n1 ; i++){ // darr[i] = sc.nextLong(); // } // mat = new long[n][n1]; // for(int i = 0 ; i < n ; i++){ // for(int j = 0 ; j < n1 ; j++){ // mat[i][j] = sc.nextLong(); // } // } // System.out.println(solve()?"YES":"NO"); solve(); // System.out.println(solve()); // sb = new StringBuilder(); // sb.append(str); t -= 1; } } public static int log(long n){ if(n == 0 || n == 1) return 0; if(n == 2) return 1; double num = Math.log(n); double den = Math.log(2); if(den == 0) return 0; return (int)(num/den); } public static long gcd(long a,long b){ if(b%a == 0) return a; return gcd(b%a,a); } // public static void swap(int i,int j){ // long temp = arr[j]; // arr[j] = arr[i]; // arr[i] = temp; // } static final Random random=new Random(); static void ruffleSort(long[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n); long temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static class Node{ int first; int second; Node(int f,int s){ this.first = f; this.second = s; } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
b0bbc60733c44e5286b3a62c062c2dda
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class a{ static int[] count,count1; static Node[] arr; static char[] ch,ch1; static long[] darr; static long[][] mat; static long x; static long maxl; static double dec; static String s; // static long minl; static int mx = (int)1e6; static long mod = 998244353l; // static int minl = -1; // static long n; static int n,n1,n2; static long a; static long b; static long c; static long d; static long y; static long m; static long k; static int q; static String[] str,str1; static Set<Character> set,set1; static List<Long> list; static Map<Long,Integer> map; static StringBuilder sb; public static void solve(){ long first = Math.max(m,c) - Math.min(m,c); m = Math.min(m,c); c = Math.min(m,c); x += first; long ans = Math.min(Math.min(m,c),x); m -= ans; c -= ans; ans += (m+c)/3; System.out.println(ans); } public static void main(String[] args) { FastScanner sc = new FastScanner(); // Scanner sc = new Scanner(System.in); int t = sc.nextInt(); // int t = 1; while(t > 0){ // set = new HashSet<>(); // map = new HashMap<>(); // x = sc.nextLong(); // y = sc.nextLong(); // n = sc.nextInt(); // n1 = sc.nextInt(); // n1 = sc.nextInt(); // a = sc.nextLong(); // b = sc.nextLong(); c = sc.nextLong(); // d = sc.nextLong(); // k = sc.nextLong(); // d = sc.nextLong(); // n = sc.nextLong(); // x = sc.nextLong(); // ch = sc.next().toCharArray(); // ch1 = sc.next().toCharArray(); // s = sc.next(); // long x = sc.nextLong(); // k = sc.nextLong(); // dec = sc.nextDouble(); // n = sc.nextInt(); m = sc.nextLong(); x = sc.nextLong(); // arr = new Node[n]; // for(int i = 0; i < n ; i++){ // arr[i] = new Node(sc.nextInt(),i+1); // } // // set = new HashSet<>(); // for(int i = 0 ; i < n ; i++) // set.add(sc.next().charAt(0)); // n1 = sc.nextInt(); // darr = new long[n1]; // for(int i = 0; i < n1 ; i++){ // darr[i] = sc.nextLong(); // } // mat = new long[n][n1]; // for(int i = 0 ; i < n ; i++){ // for(int j = 0 ; j < n1 ; j++){ // mat[i][j] = sc.nextLong(); // } // } // System.out.println(solve()?"YES":"NO"); solve(); // System.out.println(solve()); // sb = new StringBuilder(); // sb.append(str); t -= 1; } } public static int log(long n){ if(n == 0 || n == 1) return 0; if(n == 2) return 1; double num = Math.log(n); double den = Math.log(2); if(den == 0) return 0; return (int)(num/den); } public static long gcd(long a,long b){ if(b%a == 0) return a; return gcd(b%a,a); } // public static void swap(int i,int j){ // long temp = arr[j]; // arr[j] = arr[i]; // arr[i] = temp; // } static final Random random=new Random(); static void ruffleSort(long[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n); long temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static class Node{ int first; int second; Node(int f,int s){ this.first = f; this.second = s; } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
89778207e271029742b3a8b7a32fec5b
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static Scanner scanner =new Scanner(System.in); public static void main (String [] args) { int q = scanner.nextInt(); for (int i = 0; i <q ; i++) { long c = scanner.nextInt(); long m = scanner.nextInt(); long x = scanner.nextInt(); long ans = Math.min(c , m); if (x + m-ans +c-ans >= ans) System.out.println(ans); else { c-=x; m-=x; ans=x+((c+m)/3); System.out.println(ans); } } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
9597363dcef07f0edf90ed29ca6561b5
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.util.Arrays; import java.util.InputMismatchException; import java.util.*; import java.io.*; import java.math.*; public class Main7{ static class Pair { int x; int y; public Pair(int x,int y) { this.x= x; this.y= y; } @Override public int hashCode() { final int temp = 14; int ans = 1; ans =x*31+y*13; return ans; } // Equal objects must produce the same // hash code as long as they are equal @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null) { return false; } if (this.getClass() != o.getClass()) { return false; } Pair other = (Pair)o; if (this.x != other.x || this.y!=other.y) { return false; } return true; } } static class Pair1 { String x; int y; int z; } static class Compare { /*static void compare(Pair arr[], int n) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { if(p1.start>p2.start) { return 1; } else if(p1.start==p2.start) { return 0; } else { return -1; } } }); } */ } public static long pow(long a, long b) { long result=1; while(b>0) { if (b % 2 != 0) { result=(result*a)%998244353; b--; } a=(a*a)%998244353; b /= 2; } return result; } public static long fact(long num) { long value=1; int i=0; for(i=2;i<num;i++) { value=((value%mod)*i%mod)%mod; } return value; } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } /* public static long lcm(long a,long b) { return a * (b / gcd(a, b)); } */ public static long sum(int h) { return (h*(h+1)/2); } public static void bfs(int num,int size) { boolean[] visited=new boolean[size+1]; Queue<Integer> q=new LinkedList<>(); q.add(num); visited[num]=true; while(!q.isEmpty()) { int x=q.poll(); ArrayList<Integer> al=graph.get(x); for(int i=0;i<al.size();i++) { int y=al.get(i); if(visited[y]==false) { q.add(y); visited[y]=true; } } } } public static void dfs(int parent,boolean[] visited) { ArrayList<Integer> arr=new ArrayList<Integer>(); arr=graph.get(parent); visited[parent]=true; ans++; for(int i=0;i<arr.size();i++) { int num=(int)arr.get(i); if(visited[num]==false) { dfs(num,visited); } } } static int ans=0; static int mod=1000000007; static ArrayList<ArrayList<Integer>> graph; static public void main(String args[])throws IOException { int q=i(); while(q-->0) { int c=i(); int m=i(); int x=i(); int ans=0; ans=Math.min((c+m+x)/3,Math.min(c,m)); pln(ans+""); } } /**/ static InputReader in=new InputReader(System.in); static OutputWriter out=new OutputWriter(System.out); public static long l() { String s=in.String(); return Long.parseLong(s); } public static void pln(String value) { System.out.println(value); } public static int i() { return in.Int(); } public static String s() { return in.String(); } } 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 Int() { 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 String() { 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 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 String(); } 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 printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } class IOUtils { public static int[] readIntArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = in.Int(); return array; } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
84f1448786f8dc8e8184c8abdb301d99
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class TaskC { private static final String filenameIn = "input.txt"; private static final String filenameOut = "output.txt"; // THIS IS SOLUTION!!!!!!! // LOOK HERE! // HACK ME PLEASE, if you can!!! void solve() { int n = nextInt(); for (int i = 0; i < n; i++) { int c = nextInt(); int m = nextInt(); int x = nextInt(); int answer = 0; if(min(c, m, x) == x) { answer += x; c -= x; m -= x; int max = Math.max(c, m); int min = Math.min(c, m); int countMax = max / 2; int countMin = min; if(countMax >= countMin) { answer += countMin; } else { answer += (min + max) / 3; } System.out.println(answer); } else { System.out.println(min(c, m, x)); } } } int max(int a, int b , int c) { return Math.max(a, Math.max(b,c )); } int min( int a, int b , int c) { return Math.min(a, Math.min(b,c )); } /** * ШАБЛОН */ public static void main(String[] args) { new TaskC().run(); } void init() { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } void run() { try { long timeStart = System.currentTimeMillis(); init(); solve(); out.close(); long timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeStart)); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } } private int ceilSearch(long arr[], int low, int high, long x) { int mid; if (x <= arr[low]) { return low; } if (x > arr[high]) { return -1; } mid = (low + high) / 2; /* low + (high - low)/2 */ if (arr[mid] == x) { return mid; } else if (arr[mid] < x) { if (mid + 1 <= high && x <= arr[mid + 1]) { return mid + 1; } else { return ceilSearch(arr, mid + 1, high, x); } } else { if (mid - 1 >= low && x > arr[mid - 1]) { return mid; } else { return ceilSearch(arr, low, mid - 1, x); } } } private int floorSearch(long arr[], int low, int high, long x) { if (low > high) { return -1; } if (x >= arr[high]) { return high; } int mid = (low + high) / 2; if (arr[mid] == x) { return mid; } if (mid > 0 && arr[mid - 1] <= x && x < arr[mid]) { return mid - 1; } if (x < arr[mid]) { return floorSearch(arr, low, mid - 1, x); } return floorSearch(arr, mid + 1, high, x); } /** * FAST_SCANNER */ static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; BufferedReader in; PrintWriter out; StringTokenizer st; String nextLine() { try { return in.readLine(); } catch (IOException e) { e.printStackTrace(); } return null; } private String delimiter = " "; String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(delimiter); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } int[][] nextIntMatrix(int n, int m) { int[][] a = new int[n][m]; for (int i = 0; i < n; i++) { a[i] = nextIntArray(m); } return a; } int getMaxArray(int[] a) { int max = Integer.MIN_VALUE; for (int x : a) { max = Math.max(max, x); } return max; } private void setDelimiter(String delimiter) { this.delimiter = delimiter; } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
3580c8afc7340c31a870c8a92a26a0eb
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class PerfectTeam { private static int min(int a, int b, int c) { if(a <= b) { if (a <= c) return 1; else return 3; } else if (b < c) return 2; else return 3; } public static void main(String[] args) { Scanner scanner = new Scanner(); int q = scanner.nextInt(); while(q > 0) { int c = scanner.nextInt(); int m = scanner.nextInt(); int x = scanner.nextInt(); int min3 = min(c, m, x); if(min3 == 1) { System.out.println(c); } else if(min3 == 2) { System.out.println(m); } else { int sum = x; c -= x; m -= x; int dist = Math.abs(c-m); if(m == c || (dist <= c && dist <= m)) { sum += dist; if(c > m) m -= dist; else if (m > c) m -= dist * 2; if(m % 3 == 2) sum += (m/3) * 2 + 1; else sum += (m/3) * 2; } else { if (c < m) sum += c; else sum += m; } System.out.println(sum); } q--; } } private static class Scanner { private BufferedReader br; private StringTokenizer st; Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { if(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
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
f24b7692411491a144c9535c586990e8
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); List<int[]> params = new ArrayList<>(); for (int i = 0; i < n; i++) { int[] p = new int[3]; p[0] = scanner.nextInt(); p[1] = scanner.nextInt(); p[2] = scanner.nextInt(); params.add(p); } params.stream() .mapToInt(p -> teamNumber(p[0], p[1], p[2])) .forEach(System.out::println); } static int teamNumber(int a, int b, int c) { int min = Math.min(a, b); c += a - min; c += b - min; if (c >= min) return min; return (min * 2 + c) / 3; } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
5fe50be2f4c1a229cbe7868f89af544d
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.io.*; import java.util.Scanner; public class Main { public static void main(String args[]) throws IOException { StreamTokenizer sc=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); sc.nextToken(); int T=(int) sc.nval; while(T--!=0) { int a,b,c; sc.nextToken(); a=(int) sc.nval; sc.nextToken(); b=(int) sc.nval; sc.nextToken(); c=(int) sc.nval; System.out.println(Math.min(a,Math.min(b,(a+b+c)/3))); } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
1d4daf384f28ab4e06f8e7d3f08568d0
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.util.*; import java.io.* ; /* NOTES: -more than 10 digits (10^10), use long -prefix sum of 1's and -1's to control flow of highlighting a region -log(a)/log(b) = log base b of a -create a position array if trying to see if elements show up next to each other sequentially i.e. elements 1,2,3 are within 3 spots of each other in an array arr[scannedInt - 1] = i; (position of i at p[i] in original) - use a freq array when counting instances of an element occurring - increment the counter first before simulating anything turn-based (two player game) */ public class Main { static long mod = (long)(Math.pow(10, 9) + 7); public static String alpha = "zabcdefghijklmnopqrstuvwxy"; public static void main(String[] args) throws IOException{ FastReader in = new FastReader(); long t= in.nextLong(); while (t-- > 0) { int a = in.nextInt(); int b =in.nextInt(); int c = in.nextInt(); int min = Math.min(a,b); int big = Math.max(a,b); c += big-min; int ans = Math.min(min, c); if(ans == min) System.out.println(ans); else{ ans += (min-c)*2/3; System.out.println(ans); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static ArrayList sieve(){ ArrayList<Integer> primes = new ArrayList<>(); int size = 1000001; int[] arr = new int[size+1]; for(int i = 2; i*i<=size; i++){ if(arr[i] == 0 && (long) (i*i)<=size) for(int pp = i*i; pp<=size; pp+=i) arr[pp]++; } for(int i = 2; i<=size; i++){ if(arr[i]==0) primes.add(i); } return primes; } static boolean isPalindrome(String s){ for(int i = 0; i<s.length()/2; i++){ if(s.charAt(i) != s.charAt(s.length()-i-1)) return false; } return true; } static ArrayList factors(long n ){ ArrayList<Long> facts = new ArrayList<>(); for(int i = 1; i<=(int)Math.sqrt(n); i++){ if(n%i == 0){ if( i == Math.sqrt(n)) facts.add((long)i); else{ facts.add((long)i); facts.add(n/i); } } } Collections.sort(facts); return facts; } static boolean isPrime (int n){ if(factors(n).size() ==2) return true; else return false; } static long GCD(long a, long b) { if (b==0) return a; return GCD(b,a%b); } static long LCM(long a, long b){ return (a*b)/(GCD(a,b)); } static String rev(String s){ char[] arr = s.toCharArray(); for(int i = 0; i<(s.length()+1)/2; i++){ char temp = arr[i]; arr[i] = arr[s.length()-i-1]; arr[s.length()-i-1] = temp; } String fin = new String(arr); return fin; } static long pow(long a, long N) { if (N == 0) return 1; else if (N == 1) return a; else { long R = pow(a,N/2); if (N % 2 == 0) { return R*R; } else { return R*R*a; } } } static long powMod(long a, long N) { if (N == 0) return 1; else if (N == 1) return a % mod; else { long R = powMod(a,N/2) % mod; R *= R; R %= mod; if (N % 2 == 1) { R *= a; R %= mod; } return R % mod; } } }
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
dfbd3c243d8cc58f4b3af45c6cc5f6e1
train_002.jsonl
1568903700
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.
256 megabytes
import java.util.Scanner; public class PerfectTeam { public static void main(String[] args) { Scanner in = new Scanner(System.in); long q = in.nextLong(); for (int i = 1; i <= q; i++) { long c = in.nextLong(), m = in.nextLong(), x = in.nextLong(); long s = (c + m + x); if (s <= 2 || c == 0 || m == 0) { System.out.println(0); continue; } long max = Math.min(c, m); long sum = (Math.max(c, m) - max) + x; if (sum >= max) { System.out.println(max); continue; } long end = max, beg = sum; long mid = 0, ans = 1; long sum_c_m = c + m; while (end > beg) { mid = (beg + end) / 2; long re = mid - beg; if (re == 0) { break; } if (mid <= c && mid <= m && mid <= (x + (c - mid) + (m - mid))){ beg = mid; }else { end = mid; } // end = ((Math.floorMod(re, 2) == 0)) ? end - (re / 2) : end - ((re / 2) + 1); // beg = mid; } if (end != beg){ if (end <= c && end <= m && end <= (x + (c - end) + (m - end))){ System.out.println(end); }else { System.out.println(beg); } }else { System.out.println(end); } } } } /* if (c != m) { int max = Math.min(c, m); int s = (Math.max(c, m) - max) + x ; if(s >= max){ System.out.println(max); }else { int reminder = max - s; } continue; } int maxTeam = 0, tempCoder = c, tempMath = m; if (x != 0) { if (x >= c) { System.out.println(c); } else { maxTeam += x; tempCoder -= x; tempMath -= x; if (Math.floorMod(tempCoder , 2) == 0){ System.out.println(maxTeam + (tempCoder / 2)); } else { System.out.println(maxTeam + ((tempCoder / 2) + 1)); } } } else { if (Math.floorMod(tempCoder , 2) == 0){ System.out.println(maxTeam + (tempCoder / 2)); } else { System.out.println(maxTeam + ((tempCoder / 2) + 1)); } } */
Java
["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"]
2 seconds
["1\n3\n0\n0\n1\n3"]
NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
Java 8
standard input
[ "binary search", "math" ]
b18dac401b655c06bee331e71eb3e4de
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.
1,200
Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
standard output
PASSED
db9e6b6d2005612a4d78aec96917ea98
train_002.jsonl
1359732600
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure: Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
256 megabytes
import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] s) { Scanner in = new Scanner(System.in); PrintWriter writer = new PrintWriter(System.out); TaskC solution = new TaskC(); solution.solve(in,writer); writer.close(); in.close(); } } class TaskC { public void solve(Scanner in, PrintWriter out) { int sizeCount = Integer.parseInt(in.nextLine()); // int[] sizes = new int[sizeCount]; // int[] boxCount = new int[sizeCount]; // // for (int i=0;i<sizeCount;i++) { // sizes[i] = in.nextInt(); // boxCount[i] = in.nextInt(); // } // start from minimum, find for each size, the max-size required to pack all boxes of this size. int maxsize = -1; int size, count, boxSize, boxCount; for (int i=0;i<sizeCount;i++) { count = 4; boxSize = in.nextInt(); boxCount = in.nextInt(); for (size=boxSize+1;count<boxCount;size++) { count *= 4; } maxsize = Math.max(maxsize, size); } out.println(maxsize); } }
Java
["2\n0 3\n1 5", "1\n0 4", "2\n1 10\n2 2"]
2 seconds
["3", "1", "3"]
NotePicture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.In the second test case, we can put all four small boxes into a box with side length 2.
Java 6
standard input
[ "greedy", "math", "implementation", "sortings", "binary search" ]
15aac7420160f156d5b73059af1fae3b
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
1,600
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
standard output
PASSED
44364284b8e4e812db7f3565a8d4ee8e
train_002.jsonl
1359732600
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure: Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
256 megabytes
import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] s) { Scanner in = new Scanner(System.in); PrintWriter writer = new PrintWriter(System.out); TaskC solution = new TaskC(); solution.solve(in,writer); writer.close(); in.close(); } } class TaskC { public void solve(Scanner in, PrintWriter out) { int sizeCount = Integer.parseInt(in.nextLine()); int[] sizes = new int[sizeCount]; int[] boxCount = new int[sizeCount]; for (int i=0;i<sizeCount;i++) { sizes[i] = in.nextInt(); boxCount[i] = in.nextInt(); } // start from minimum, find for each size, the max-size required to pack all of them int maxsize = -1; int size, count; for (int i=0;i<sizeCount;i++) { count = 4; for (size=sizes[i]+1;count<boxCount[i];size++) { count *= 4; } maxsize = Math.max(maxsize, size); } out.println(maxsize); } }
Java
["2\n0 3\n1 5", "1\n0 4", "2\n1 10\n2 2"]
2 seconds
["3", "1", "3"]
NotePicture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.In the second test case, we can put all four small boxes into a box with side length 2.
Java 6
standard input
[ "greedy", "math", "implementation", "sortings", "binary search" ]
15aac7420160f156d5b73059af1fae3b
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
1,600
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
standard output
PASSED
7d77ed5408098b136175fa79c7556cd6
train_002.jsonl
1359732600
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure: Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import static java.lang.Integer.*; import static java.lang.System.out; import static java.lang.Math.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = parseInt(in.readLine().trim()); int val = 0,max = MIN_VALUE; for (int i = 0; i < n; i++) { String[] inp = in.readLine().trim().split("\\s+"); int k = parseInt(inp[0]),a = parseInt(inp[1]); val =k+(a==1 ? 1 : (int)ceil(log(a)/log(4))); if (val>max) max = val; } out.println(max); } }
Java
["2\n0 3\n1 5", "1\n0 4", "2\n1 10\n2 2"]
2 seconds
["3", "1", "3"]
NotePicture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.In the second test case, we can put all four small boxes into a box with side length 2.
Java 6
standard input
[ "greedy", "math", "implementation", "sortings", "binary search" ]
15aac7420160f156d5b73059af1fae3b
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
1,600
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
standard output
PASSED
6a1a40b3d933a30859424954ace598db
train_002.jsonl
1359732600
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure: Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class C { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); StringTokenizer st; box[] boxes = new box[n]; for (int i = 0; i < n; i++) { st = new StringTokenizer(br.readLine()); long k = Long.parseLong(st.nextToken()); long a = Long.parseLong(st.nextToken()); boxes[i] = new box(k, a); } Arrays.sort(boxes); long begin = boxes[n - 1].k; for (int i = 0; i < n - 1; i++) { long k1 = boxes[i].k, k2 = boxes[i + 1].k; long a1 = boxes[i].a, a2 = boxes[i + 1].a; while (k1 != k2 && a1 != 1) { k1++; if (a1 % 4 == 0) a1 = a1 / 4; else a1 = a1 / 4 + 1; } if (k1 == k2) boxes[i + 1].a = Math.max(a1, a2); } long k = boxes[n - 1].k, a = boxes[n - 1].a; while (a != 1) { k++; if (a % 4 == 0) a = a / 4; else a = a / 4 + 1; } if (begin == k) System.out.println(k + 1); else System.out.println(k); } static class box implements Comparable<box> { long k, a; public box(long kk, long aa) { k = kk; a = aa; } @Override public int compareTo(box b) { return (int) (k - b.k); } } }
Java
["2\n0 3\n1 5", "1\n0 4", "2\n1 10\n2 2"]
2 seconds
["3", "1", "3"]
NotePicture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.In the second test case, we can put all four small boxes into a box with side length 2.
Java 6
standard input
[ "greedy", "math", "implementation", "sortings", "binary search" ]
15aac7420160f156d5b73059af1fae3b
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
1,600
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
standard output
PASSED
ab0b417422c24671713fb1d52b22bfa4
train_002.jsonl
1359732600
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure: Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class C { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); StringTokenizer st; box[] boxes = new box[n]; for (int i = 0; i < n; i++) { st = new StringTokenizer(br.readLine()); boxes[i] = new box(Long.parseLong(st.nextToken()), Long.parseLong(st.nextToken())); } Arrays.sort(boxes); long begin = boxes[n - 1].k; for (int i = 0; i < n - 1; i++) { long k1 = boxes[i].k, k2 = boxes[i + 1].k, a1 = boxes[i].a, a2 = boxes[i + 1].a; while (k1 != k2 && a1 != 1) { k1++; a1 = (a1 % 4 == 0 ? 0 : 1) + a1 / 4; } if (k1 == k2) boxes[i + 1].a = Math.max(a1, a2); } long k = boxes[n - 1].k, a = boxes[n - 1].a; while (a != 1) { k++; a = (a % 4 == 0 ? 0 : 1) + a / 4; } k = k == begin ? k + 1 : k; System.out.println(k); } static class box implements Comparable<box> { long k, a; public box(long kk, long aa) { k = kk; a = aa; } @Override public int compareTo(box b) { return (int) (k - b.k); } } }
Java
["2\n0 3\n1 5", "1\n0 4", "2\n1 10\n2 2"]
2 seconds
["3", "1", "3"]
NotePicture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.In the second test case, we can put all four small boxes into a box with side length 2.
Java 6
standard input
[ "greedy", "math", "implementation", "sortings", "binary search" ]
15aac7420160f156d5b73059af1fae3b
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
1,600
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
standard output
PASSED
b2ec05cb47670716a039b3768533c6a7
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.util.*; import java.io.*; /********************************************************* * * * **** *** ** ** ****** ** * * ** * * ** ** * ** * * *** ** * * ******* ******* ****** ** * * * ** * * ** ** ** ** * ******* * * **** *** ******* ******* ****** ******* * * * *********************************************************/ public class MargariteAndTheBestPresent { public static int sum(int x,int y) { int z=(y-x)+1; int sum=0; if(z%2==0) { sum=(x%2==0 ? (z/2)*-1:(z/2)); }else { sum=((x+1)%2==0 ? (--z)/2*-1:(--z)/2); sum+=(int)Math.pow(-1, x) *x; } return sum; } public static void main (String [] args) { Scanner scanner=new Scanner(System.in); PrintWriter pw =new PrintWriter(System.out); int k=scanner.nextInt(); for(int i=0;i<k;i++) { int x =scanner.nextInt(); int y=scanner.nextInt(); pw.println(x==y ? (x%2==0 ? x:-1*x): sum(x, y)); } pw.close(); } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
690bc530b50fd999f7dda898e99513fa
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
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.*; public class Main { public static void main(String[] argv) throws Exception { FastReader in = new FastReader(System.in); PrintWriter out = new PrintWriter(System.out); long n = in.nextLong(); for (int i = 0; i < n; i++) { long x = in.nextLong(); long y = in.nextLong(); if (x == y) { if (x % 2 == 0) { out.println(x); } else { out.println(-x); } } else { long sum = sumAll(x, y); long even = sum_even(x, y); sum -= even; out.println(even-sum); } } out.flush(); out.close(); } public static long sum_even(long a, long b) { if ((a & 1) == 1) { a = a + 1; } if ((b & 1) == 1) { b = b - 1; } return ((a + b) / 2) * (1 + ((b - a) / 2)); } public static long sumAll(long min, long max) { return ((max - min) + 1) * (min + max) / 2; } static class FastReader { StringTokenizer st; BufferedReader br; public FastReader(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public FastReader(FileReader fileReader) { br = new BufferedReader(fileReader); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public boolean ready() throws IOException { return br.ready(); } } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
c799d4f15b490992a6a756e920d1b122
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.io.IOException; import java.io.InputStreamReader; import java.io.BufferedReader; import java.util.*; import java.math.*; import java.io.*; import java.text.*; public class hacker { /*Fatt Gyi Bhai*/ //Dekh le mera code public static boolean[] sieve(long n) { boolean[] prime = new boolean[(int)n+1]; Arrays.fill(prime,true); prime[0] = false; prime[1] = false; long m = (long)Math.sqrt(n); for(int i=2;i<=m;i++) { if(prime[i]) { for(int k=i*i;k<=n;k+=i) { prime[k] = false; } } } return prime; } static long GCD(long a,long b) { if(a==0 || b==0) { return 0; } if(a==b) { return a; } if(a>b) { return GCD(a-b,b); } return GCD(a,b-a); } static long CountCoPrimes(long n) { long res = n; for(int i=2;i*i<=n;i++) { if(n%i==0) { while(n%i==0) { n/=i; } res-=res/i; } } if(n>1) { res-=res/n; } return res; } //fastest way to find x**n static long modularExponentiation(long x,long n,long m) { long res = 1; while(n>0) { if(n%2==1) { res = (res*x)%m; } x =(x*x)%m; n/=2; } return res; } static long lcm(long a,long b) { return (a*b)/GCD(a,b); } static int pow(int a,int b) { int res = 1; while(b>0) { if((b&1)==1) { res *= a; } b >>= 1; a *=a; } return res; } static long modInverse(long A,long M) { return modularExponentiation(A,M-2,M); } static void reverse(char[] a,int start,int end) { while(start<end) { char temp = a[start]; a[start] = a[end]; a[end] = temp; start++; end--; } } static boolean prime(int n) { for(int i=2;i*i<=n;i++) { if(i%2==0 ||i%3==0) { return false; } } return true; } public static void main(String[] args) throws IOException { // = new PrintWriter("explicit.out"); new hacker().run(); } static int rev(int n) { int x=0; int num = 0; while(n>0) { x = n%10; num = num*10+x; n/=10; } return num; } // Firse author ka solution // static long N; static Scanner in = new Scanner(System.in); static void run() throws IOException { int till = (int)1e9+1; int n = ni(); for(int i=0;i<n;i++) { int o = ni(); int p = ni(); o = f(o-1); p = f(p); System.out.println(p-o); } } static int f(int o) { if(o%2==0) { return o/2; } else { return f(o-1)-o; } } static void printL(long a) { System.out.println(a); } static void printS(String s) { System.out.println(s); } static void swap(char c,char p) { char t = c; c = p; p = t; } static long max(long n,long m) { return Math.max(n,m); } static long min(long n,long m) { return Math.min(n,m); } static double nd() throws IOException { return Double.parseDouble(in.next()); } static int ni() throws IOException { return Integer.parseInt(in.next()); } static long nl() throws IOException { return Long.parseLong(in.next()); } static String si() throws IOException { return in.next(); } static int abs(int n) { return Math.abs(n); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public boolean ready() throws IOException {return br.ready();} } } class Pair implements Comparable<Pair> { int value; int index; public Pair(int v,int i) { value = v; index = i; } public int compareTo(Pair a) { return this.value-a.value; } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
5b4f82a2352078abdae9e64bb77ac0f0
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.io.ByteArrayInputStream; import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // Scanner sc = testdata(); int n = sc.nextInt(); for (int i = 0; i < n; i++) { System.out.println(sum(sc.nextInt(), sc.nextInt())); } } static long sum(int a, int b) { long even = addEvenTo(b)-addEvenTo(a-1); long odd = addOddTo(b)-addOddTo(a-1); return (even-odd); } static long addEvenTo(int a) { if(a%2!=0) a--; if(a<2) return 0; long result = (long)(2+a)*(a/2)/2; return result; } static long addOddTo(int a) { if(a%2==0) a--; if(a<1) return 0; long result = (long)(1+a)*(a/2+1)/2; return result; } static Scanner testdata() { return new Scanner(new ByteArrayInputStream(("6\n" + "1 2\n" + "1 3\n" + "2 5\n" + "5 5\n" + "4 4\n" + "2 3").getBytes())); } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
3d06d90236b861602ee66b74fa27e315
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.io.*; import java.math.*; import java.util.*; // author @mdazmat9 public class CodeForces_CA { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n=sc.nextInt(); for(int i=0;i<n;i++) { long a = sc.nextLong(); long b = sc.nextLong(); if (a == b) { if(a%2==0) out.println(a); else out.println(-a); } else { long even=0,odd=0,num=0; num=(b-a+1); if(num%2==0) { even = num/2; odd=num-even; } else{ if(a%2==0){ even = num / 2 +1 ; odd=(b-a+1)-even; } else { odd = num / 2 +1 ; even=(b-a+1)-odd; } } long first_even = 0, last_even = 0, first_odd = 0, last_odd = 0; if (a % 2 == 0) { first_even = a; first_odd = a + 1; } else { first_even = a + 1; first_odd = a; } // out.println(first_even+" "+first_odd+" "+even+" "+odd); long sum_even=sumOfAP(first_even,2,even); long sum_odd=sumOfAP(first_odd,2,odd); if(even==1) sum_even=first_even; if(odd==1) sum_odd=first_odd; out.println(sum_even-sum_odd); } } out.flush(); } static long sumOfAP(long a, long d, long n) { long sum = (n * (2 * a + (n - 1) * d))/2; return sum; } static long gcd(long a , long b) { if(b == 0) return a; return gcd(b , a % b); } } class Scanner { public BufferedReader reader; public StringTokenizer st; public Scanner(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 int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } class OutputWriter { BufferedWriter writer; public OutputWriter(OutputStream stream) { writer = new BufferedWriter(new OutputStreamWriter(stream)); } public void print(int i) throws IOException { writer.write(i); } public void print(String s) throws IOException { writer.write(s); } public void print(char[] c) throws IOException { writer.write(c); } public void close() throws IOException { writer.close(); } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
99797f36d4dcb841d97bda04ac3856fc
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class a{ static int[] count,count1,count2; static long[] arr; static char[] ch,ch1; static long[] darr,farr; static Character[][] mat,mat1; static long x,h; static long maxl; static double dec; static String s; static long minl; static int mx = (int)1e6; static long mod = 998244353l; // static int minl = -1; static long n; // static int n,n1,n2; static long a,g; static long b; static long c; static long d; static long y,z; static int m; static long k; static int q; static String[] str,str1; static Set<Integer> set,set1; static List<Integer> list,list1,list2; static LinkedList<Character> ll; static Map<Integer,Integer> map; static StringBuilder sb,sb1,sb2; public static long solve(){ long l = a; long r = b; if(l == r){ if(r%2 == 0) return r; return -r; } long sum1 = 0; long sum2 = 0; if(r%2 == 0) sum1 = r/2; else sum1 = -(r+1)/2; l -= 1; if(l%2 == 0) sum2 = l/2; else sum2 = -(l+1)/2; return sum1 - sum2; } public static void main(String[] args) { FastScanner sc = new FastScanner(); // Scanner sc = new Scanner(System.in); int t = sc.nextInt(); // int t = 1; while(t > 0){ // x = sc.nextLong(); // y = sc.nextLong(); // z = sc.nextLong(); a = sc.nextLong(); b = sc.nextLong(); // c = sc.nextLong(); // d = sc.nextLong(); // n = sc.nextLong(); // n = sc.nextInt(); // m = sc.nextInt(); // x = sc.nextLong(); // y = sc.nextLong(); // x = sc.newxtLong(); // y = sc.nextLong(); // n1 = sc.nextInt(); // n = sc.nextLong(); // k = sc.nextLong(); // ch = sc.next().toCharArray(); // ch1 = sc.next().toCharArray(); // m = sc.nextLong(); // k = sc.nextLong(); // arr = new long[n]; // for(int i = 0; i < n ; i++){ // arr[i] = sc.nextLong(); // } // darr = new long[n]; // for(int i = 0; i < n ; i++){ // darr[i] = sc.nextLong(); // } // n1 = sc.nextInt(); // darr = new long[n1]; // for(int i = 0; i < n1 ; i++){ // darr[i] = sc.nextLong(); // } // mat = new Character[n][n]; // for(int i = 0 ; i < n ; i++){ // String s = sc.next(); // for(int j = 0 ; j < n ; j++){ // mat[i][j] = s.charAt(j); // } // } // str = new String[n]; // for(int i = 0 ; i < n ; i++) // str[i] = sc.next(); // System.out.println(solve()?"Yes":"No"); // solve(); System.out.println(solve()); t -= 1; } } public static int log(long n){ if(n == 0 || n == 1) return 0; if(n == 2) return 1; double num = Math.log(n); double den = Math.log(2); if(den == 0) return 0; return (int)(num/den); } public static long gcd(long a,long b){ if(b%a == 0) return a; return gcd(b%a,a); } // public static void swap(int i,int j){ // long temp = arr[j]; // arr[j] = arr[i]; // arr[i] = temp; // } static final Random random=new Random(); static void ruffleSort(long[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n); long temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static class Node{ int first; int second; Node(int f,int s){ this.first = f; this.second = s; } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
fdd3e8fe2dada9624e75711f684f8d71
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.util.Scanner; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int q = sc.nextInt(); for (int i = 1; i <= q; i++) { int l = sc.nextInt(); int r = sc.nextInt(); int ans = 0; if (l % 2 == 0) { ans = -1 * (r - l + 1) / 2; } else { ans = (r - l + 1) / 2; } if ((r - l + 1) % 2 == 1) { ans += r * (r % 2 == 0 ? 1 : -1); } System.out.println(ans); } } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
67db795efdf9881bcd52780e5a28a8ef
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Question { public static void main(String[] args) throws IOException { Reader.init(System.in); int q = Reader.nextInt(); for (int i = 0 ; i < q ; i++){ int l = Reader.nextInt(); int r = Reader.nextInt(); int rightNumber = 0; int leftNumber = 0; l = l - 1; if (r%2== 0){ rightNumber = r/2; } else{ rightNumber = -(r + 1)/2; } if (l%2== 0){ leftNumber = l/2; } else{ leftNumber = -(l+1)/2; } //System.out.println(rightNumber + " " + leftNumber); System.out.println(rightNumber - leftNumber); } } } 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 double nextDouble() throws IOException { return Double.parseDouble( next() ); } static long nextLong() throws IOException { return Long.parseLong( next() ); } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
3f642be2bfb7ff1ded526064037a7a58
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner s=new Scanner(System.in); int n = s.nextInt(); for(int i=0;i<n;i++) { long a=s.nextLong(); long b=s.nextLong(); long p=(b*(b+1))/2-((a-1)*(a))/2; a=a/2+a%2; b=b/2; long q=4*((b*(b+1))/2-((a-1)*(a))/2); System.out.println(q-p); } } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
96b7bdbd34dae93dc29d2ca9c9dfc3f1
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
/* || || ========= ||====== || . >> ** \\ // || || || (( || || . >> ** ** \\ // || || || (( || || . >> ** ** \\ // ||=======|| || (( ||===== || . >> ** ** || || || || (( || || . >> ** ** || || || || || || . >> ** ** || || || || ||====== || . >> ** || */ import java.util.Scanner; import java.util.StringTokenizer; import java.io.*; public class Margarite { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static < E > void print ( E[] inputarray){ for( E element:inputarray){ System.out.printf("%s \n",element); } System.out.println(); } public static void main(String[]args) throws IOException{ FastReader sc = new FastReader(); OutputStream outputStream = System.out; PrintWriter pw = new PrintWriter(outputStream); int n,sum=0; String s; n=sc.nextInt(); int l,r; for (int i = 0; i <n ; i++) { l=sc.nextInt(); r=sc.nextInt(); long evennumber,lowerev,h,p,evenval,upodd,lowerod,oddval,d,f,result; if (l==r ){ if (l%2==0) { pw.println(l); }else{ pw.println(-l); } }else { evennumber = (long) Math.floor(r * 1.0 / 2); h = (evennumber * evennumber) + evennumber; lowerev = (long) Math.floor((l-1) * 1.0 / 2); p = (lowerev * lowerev) + lowerev; evenval = h - p; upodd = (long) Math.ceil(r * 1.0 / 2); d = upodd * upodd; lowerod = ((long) Math.ceil((l-1) * 1.0 / 2)); f = lowerod * lowerod; oddval = d - f; result = evenval - oddval; pw.println(result); } } pw.close(); } } /* 7 1 1 2 2 3 3 1000000000 1000000000 500000000 500000000 1 1000000000 3923 1000000000 */
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
e2fa91f8d976cbcb072aa2324be20714
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.util.*; public class bestPresent { public static long cal(long a){ if(a%2==0){ return a/2; } else return -(a+1)/2; } public static void main(String[] args){ Scanner sc = new Scanner(System.in); int q = sc.nextInt(); for(int i =0;i<q;i++){ long l = sc.nextLong(); long r = sc.nextLong(); long sum = cal(r)-cal(l-1); System.out.println(sum); } } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
132c17eaf66fa36dfea5769114ad4bca
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class CFMargariteAndTheBestPresent { public static void main(String args[]) throws Exception { FastReader input = new FastReader(); int n = input.nextInt(); for(int i = 0 ;i<n;i++) { int l = input.nextInt(); int r = input.nextInt(); int a =l; if(a%2==1) { a*=-1; } int ans = 0; if(r%2==0) { r=r/2; } else { r= -(r/2)-1; } if(l %2==0) { l=l/2; } else { l=-(l/2)-1; } System.out.println(r-l+a); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
e04d034260c6bdeca6900a0aff58af2c
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int q = sc.nextInt(); int[] ans = new int[q]; int l; int r; for(int i = 0; i < q; i++){ l = sc.nextInt(); r = sc.nextInt(); if((l%2 == 0)&&(r%2 == 0)){ ans[i] = l +(r-l)/2; } if((l%2 != 0)&&(r%2 != 0)){ ans[i] = 0 - l -(r-l)/2; } if((l%2 == 0)&&(r%2 != 0)){ ans[i] = (r - l - ((int)Math.floor((r-l)/2)))*-1; } if((l%2 != 0)&&(r%2 == 0)){ ans[i] = (r - l) - ((int)Math.floor((r-l)/2)); } } for(int i = 0; i < q; i++){ System.out.print(ans[i] +"\n"); } } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
eecaaaa1b25f590fad705ad48e84e5f1
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; import java.security.AccessControlException; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Scanner; import java.util.TreeMap; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.LongStream; import java.util.stream.Stream; public class _p001080B { static public void main(final String[] args) throws IOException { p001080B._main(args); } //begin p001080B.java static private class p001080B extends Solver{public p001080B(){nameIn="in/900/p001080B.in" ;}@Override public void solve()throws IOException{int l;int r;l=sc.nextInt();r=sc .nextInt();if(sc.hasNextLine()){sc.nextLine();}long res=0;if(l % 2==0&&r % 2==0) {res=(r-l)/2*(-1)+r;}else if(l % 2==0&&r % 2==1){res=(r-l+1)/2*(-1);}else if(l % 2==1&&r % 2==0){res=(r-l+1)/2;}else if(l % 2==1&&r % 2==1){res=(r-l)/2-r;}pw.println (res);}static public void _main(String[]args)throws IOException{new p001080B().run ();}} //end p001080B.java //begin net/leksi/contest/Pair.java static private class Pair<K,V>{private K k;private V v;public Pair(final K t,final V u){this.k=t;this.v=u;}public K getKey(){return k;}public V getValue(){return v ;}} //end net/leksi/contest/Pair.java //begin net/leksi/contest/Solver.java static private abstract class Solver{protected String nameIn=null;protected String nameOut=null;protected boolean singleTest=false;protected boolean preprocessDebug =false;protected boolean doNotPreprocess=false;protected PrintStream debugPrintStream =null;protected Scanner sc=null;protected PrintWriter pw=null;final String SPACE =" ";final String SPACES="\\s+";private void process()throws IOException{if(!singleTest ){int t=lineToIntArray()[0];while(t-->0){solve();}}else{solve();}}abstract protected void solve()throws IOException;protected int[]lineToIntArray()throws IOException {return Arrays.stream(sc.nextLine().trim().split(SPACES)).mapToInt(Integer::valueOf ).toArray();}protected long[]lineToLongArray()throws IOException{return Arrays.stream (sc.nextLine().trim().split(SPACES)).mapToLong(Long::valueOf).toArray();}protected void run()throws IOException{boolean done=false;try{if(nameIn !=null&&new File(nameIn ).exists()){try(FileInputStream fis=new FileInputStream(nameIn);PrintWriter pw0= select_output();){done=true;sc=new Scanner(fis);pw=pw0;process();}}}catch(IOException ex){}catch(AccessControlException ex){}if(!done){try(PrintWriter pw0=select_output ();){sc=new Scanner(System.in);pw=pw0;process();}}}private PrintWriter select_output ()throws FileNotFoundException{if(nameOut !=null){return new PrintWriter(nameOut );}return new PrintWriter(System.out);}public static Map<Integer,List<Integer>>mapi (final int[]a){return IntStream.range(0,a.length).collect(()->new TreeMap<Integer ,List<Integer>>(),(res,i)->{if(!res.containsKey(a[i])){res.put(a[i],Stream.of(i) .collect(Collectors.toList()));}else{res.get(a[i]).add(i);}},Map::putAll);}public static Map<Long,List<Integer>>mapi(final long[]a){return IntStream.range(0,a.length ).collect(()->new TreeMap<Long,List<Integer>>(),(res,i)->{if(!res.containsKey(a[i ])){res.put(a[i],Stream.of(i).collect(Collectors.toList()));}else{res.get(a[i]).add (i);}},Map::putAll);}public static<T>Map<T,List<Integer>>mapi(final T[]a){return IntStream.range(0,a.length).collect(()->new TreeMap<T,List<Integer>>(),(res,i)-> {if(!res.containsKey(a[i])){res.put(a[i],Stream.of(i).collect(Collectors.toList( )));}else{res.get(a[i]).add(i);}},Map::putAll);}public static<T>Map<T,List<Integer>> mapi(final T[]a,Comparator<T>cmp){return IntStream.range(0,a.length).collect(()-> new TreeMap<T,List<Integer>>(cmp),(res,i)->{if(!res.containsKey(a[i])){res.put(a [i],Stream.of(i).collect(Collectors.toList()));}else{res.get(a[i]).add(i);}},Map::putAll );}public static Map<Integer,List<Integer>>mapi(final IntStream a){int[]i=new int []{0};return a.collect(()->new TreeMap<Integer,List<Integer>>(),(res,v)->{if(!res .containsKey(v)){res.put(v,Stream.of(i[0]).collect(Collectors.toList()));}else{res .get(v).add(i[0]);}i[0]++;},Map::putAll);}public static Map<Long,List<Integer>>mapi (final LongStream a){int[]i=new int[]{0};return a.collect(()->new TreeMap<Long,List<Integer>> (),(res,v)->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect(Collectors .toList()));}else{res.get(v).add(i[0]);}i[0]++;},Map::putAll);}public static<T>Map<T ,List<Integer>>mapi(final Stream<T>a,Comparator<T>cmp){int[]i=new int[]{0};return a.collect(()->new TreeMap<T,List<Integer>>(cmp),(res,v)->{if(!res.containsKey(v) ){res.put(v,Stream.of(i[0]).collect(Collectors.toList()));}else{res.get(v).add(i [0]);}},Map::putAll);}public static<T>Map<T,List<Integer>>mapi(final Stream<T>a) {int[]i=new int[]{0};return a.collect(()->new TreeMap<T,List<Integer>>(),(res,v) ->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect(Collectors.toList() ));}else{res.get(v).add(i[0]);}},Map::putAll);}public static List<int[]>listi(final int[]a){return IntStream.range(0,a.length).mapToObj(i->new int[]{a[i],i}).collect (Collectors.toList());}public static List<long[]>listi(final long[]a){return IntStream .range(0,a.length).mapToObj(i->new long[]{a[i],i}).collect(Collectors.toList()); }public static<T>List<Pair<T,Integer>>listi(final T[]a){return IntStream.range(0 ,a.length).mapToObj(i->new Pair<T,Integer>(a[i],i)).collect(Collectors.toList()) ;}public static List<int[]>listi(final IntStream a){int[]i=new int[]{0};return a .mapToObj(v->new int[]{v,i[0]++}).collect(Collectors.toList());}public static List<long []>listi(final LongStream a){int[]i=new int[]{0};return a.mapToObj(v->new long[] {v,i[0]++}).collect(Collectors.toList());}public static<T>List<Pair<T,Integer>>listi (final Stream<T>a){int[]i=new int[]{0};return a.map(v->new Pair<T,Integer>(v,i[0 ]++)).collect(Collectors.toList());}protected String join(final int[]a){return Arrays .stream(a).mapToObj(Integer::toString).collect(Collectors.joining(SPACE));}protected String join(final long[]a){return Arrays.stream(a).mapToObj(Long::toString).collect (Collectors.joining(SPACE));}protected<T>String join(final T[]a){return Arrays.stream (a).map(v->Objects.toString(v)).collect(Collectors.joining(SPACE));}protected<T> String join(final T[]a,final Function<T,String>toString){return Arrays.stream(a) .map(v->toString.apply(v)).collect(Collectors.joining(SPACE));}protected<T>String join(final Collection<T>a){return a.stream().map(v->Objects.toString(v)).collect (Collectors.joining(SPACE));}protected<T>String join(final Collection<T>a,final Function<T ,String>toString){return a.stream().map(v->toString.apply(v)).collect(Collectors .joining(SPACE));}protected<T>String join(final Stream<T>a){return a.map(v->Objects .toString(v)).collect(Collectors.joining(SPACE));}protected<T>String join(final Stream<T> a,final Function<T,String>toString){return a.map(v->toString.apply(v)).collect(Collectors .joining(SPACE));}protected<T>String join(final IntStream a){return a.mapToObj(Integer::toString ).collect(Collectors.joining(SPACE));}protected<T>String join(final LongStream a ){return a.mapToObj(Long::toString).collect(Collectors.joining(SPACE));}protected List<Integer>list(final int[]a){return Arrays.stream(a).mapToObj(Integer::valueOf ).collect(Collectors.toList());}protected List<Integer>list(final IntStream a){return a.mapToObj(Integer::valueOf).collect(Collectors.toList());}protected List<Long>list (final long[]a){return Arrays.stream(a).mapToObj(Long::valueOf).collect(Collectors .toList());}protected List<Long>list(final LongStream a){return a.mapToObj(Long::valueOf ).collect(Collectors.toList());}protected<T>List<T>list(final Stream<T>a){return a.collect(Collectors.toList());}protected<T>List<T>list(final T[]a){return Arrays .stream(a).collect(Collectors.toList());}} //end net/leksi/contest/Solver.java }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
a3ea55e14cecc204740a62dd4eb2361f
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int test = sc.nextInt(); while(test-- > 0) { long l = sc.nextLong(); long r = sc.nextLong(); long result = 0l; long s1s, s2s, s1e, s2e, n1, n2, r1, r2; if(l%2 == 0) { s2s = l; s1s = l+1; } else { s2s = l+1; s1s = l; } if(r%2 == 0) { s2e = r; s1e = r-1; } else { s2e = r-1; s1e = r; } n1 = (s1e-s1s)/2+1; n2 = (s2e-s2s)/2+1; r1 = (n1*(s1s + s1e))/2; r2 = (n2*(s2s + s2e))/2; result = r2 - r1; System.out.println(result); } } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
16776e91bc74b18a5b6a83dcd92a0d2a
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.util.Scanner; public class Scratch { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int q,l,r,sum; //q=new int(); //l=new int(); //r=new int(); //int sum=new int(); q=scr.nextInt(); for (int i=0;i<q;i++){ sum=0; l=scr.nextInt(); r=scr.nextInt(); sum=(r/2)-(l-1)/2; if(r%2!=0) sum-=r; if((l-1)%2!=0) sum+=l-1; System.out.println(sum); } } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
005c845e2c4a95919962c43adecd5be7
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
import java.util.Scanner; public class CF1080B{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for(int i = 0; i < q; i++){ int l = sc.nextInt(); int r = sc.nextInt(); if (l == r){ sb.append(l*(r%2==0?1:-1)).append('\n'); } else { if ((r - l)%2 != 0){ sb.append(((r-l)/2 + 1)*(l%2!=0?1:-1)).append('\n'); } else { sb.append(r*(r%2==0?1:-1) - (((r-l)/2 )*(l%2==0?1:-1))) .append('\n'); } } } sc.close(); System.out.println(sb); } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
9911c8869bbf67401b80a8f5af715fe4
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
//Where there is a will, there is a way! import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringTokenizer st; /* inputCopy 5 1 3 2 5 5 5 4 4 2 3 outputCopy -2 -2 -5 4 -1 */ st = new StringTokenizer(br.readLine()); int q = Integer.parseInt(st.nextToken()); for (int qi = 0; qi < q; ++qi) { st = new StringTokenizer(br.readLine()); int l = Integer.parseInt(st.nextToken()); int r = Integer.parseInt(st.nextToken()); double l1 = Math.pow(-1, l) * l; double l2 = Math.pow(-1, l + 1) * (l + 1); double sum = l1 + l2; double count = (r - l + 1) / 2; double ans = sum * count; if (((r - l + 1) % 2) == 0) { pw.println((long) ans); } else { pw.println((long) (ans + Math.pow(-1, r) * r)); } } pw.flush(); pw.close(); } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
99863c2fb3434b707a6b9a1a0c355b29
train_002.jsonl
1543044900
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!
256 megabytes
//Where there is a will, there is a way! import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringTokenizer st; /* inputCopy 5 1 3 2 5 5 5 4 4 2 3 outputCopy -2 -2 -5 4 -1 */ st = new StringTokenizer(br.readLine()); int q = Integer.parseInt(st.nextToken()); for (int qi = 0; qi < q; ++qi) { st = new StringTokenizer(br.readLine()); int l = Integer.parseInt(st.nextToken()); int r = Integer.parseInt(st.nextToken()); double l1 = Math.pow(-1, l) * l; double l2 = Math.pow(-1, l + 1) * (l + 1); double sum = l1 + l2; double count = (r - l + 1) / 2; double ans = sum * count; if (((r - l + 1) % 2) == 0) { pw.println((long) ans); } else { pw.println((long) (ans + Math.pow(-1, r) * r)); } } pw.flush(); pw.close(); } }
Java
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
1 second
["-2\n-2\n-5\n4\n-1"]
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Java 8
standard input
[ "math" ]
7eae40835f6e9580b985d636d5730e2d
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
900
Print $$$q$$$ lines, each containing one number — the answer to the query.
standard output
PASSED
51a111ce7971e8d213800a95cb08d786
train_002.jsonl
1590327300
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive.
256 megabytes
//Written by Shagoto import java.util.*; import java.io.*; public class Main { // -------- Generating Prime Numbers Using Bit-wise sieve -------- // static HashSet<Integer> primes = new HashSet<Integer>(); // static BitSet bs = new BitSet(10000001); // static void sieve() // { // primes.add(2); // for(int i = 4; i<=10000000; i+=2) // { // bs.set(i,true); // } // // for(int i = 3; i<=10000000; i+=2) // { // if(!bs.get(i)) // { // primes.add(i); // for(int j = 3; i*j<=10000000; j+=2) // { // bs.set(i*j,true); // } // } // } // } // -------- Lowerbound -------- // static int lowerBound(long [] arr, long x) // { // int low = 0; // int high = arr.length - 1; // int mid = 0; // while(low < high) // { // mid = (start + end) / 2; // int mid = (low + high) / 2; // // if(arr[mid] == x) // { // return mid; // } // else if(arr[mid] > x) // { // high = mid - 1; // } // else // { // low = mid + 1; // } // } // // if(arr[mid] > x) // { // if(mid - 1 >= 0 && arr[mid - 1] < x) // { // return mid - 1; // } // return -1; // } // return mid; // } // -------- Prefix Sum -------- // If zero indexed, add 1 // pref.add(0) // pref.get(r) - pref.get(l - 1) // xor(l, r) = pref[r]^pref[l - 1] // -------- Ceil -------- // static int ceil(int n, int x) // { // if(n / x * x != n) // { // return n / x + 1; // } // return n / x; // } // -------- Phi Function -------- // static int phi(int n) // { // int ret = n; // for(int i = 2; i*i <= n; i++) // { // if(n % i == 0) // { // while(n % i == 0) // { // n /= i; // } // ret -= ret / i; // } // } // // if(n > 1) // { // ret -= ret / n; // } // return ret; // } // -------- GCD of Two Numbers -------- // static int gcd(int a, int b) // { // if(b == 0) // { // return a; // } // return gcd(b, a % b); // } // -------- LCM of two Numbers -------- // static int lcm(int a, int b) // { // return (a * b) / gcd(a, b); // } // -------- Binary Search -------- // static int binarySearch(int [] arr, int x) // { // int low = 0; // int high = arr.length - 1; // // while(low <= high) // { // int mid = (low + high) / 2; // // if(arr[mid] == x) // { // return mid; // } // else if(arr[mid] > x) // { // high = mid - 1; // } // else // { // low = mid + 1; // } // } // return -1; // } public static void main(String[]args) throws IOException { /* InputStreamReader isr = new InputStreamReader(System.in); BufferedReader read = new BufferedReader(isr); */ Scanner read = new Scanner(System.in); int t = read.nextInt(); for(int x = 1; x<=t; x++) { long n = read.nextLong(); long k = read.nextLong(); if(n <= k) { System.out.println(1); } else { long ans = n; for(int i = 1; i<=(int)Math.sqrt(n); i++) { if(n % i == 0) { if(n / i <= k) { ans = Math.min(ans, i); } if(i <= k) { ans = Math.min(ans, n / i); } } } System.out.println(ans); } } } } // -------- Creating own Class -------- //class className //{ // int v1; // int v2; // public className(int x, int y) // { // v1 = x; // v2 = y; // } // // public String toString() // { // return v1+" "+v2; // } //} // -------- For Comparision or Sorting -------- // *Paste it in the main class* //Collections.sort(arr, new Comparator<className>(){ // public int compare(className a, className b) // { // if(a.v1 == b.v1) // { // return b.v2 - a.v2; // } // else // { // return a.v1 - b.v1; // } // } // });
Java
["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"]
2 seconds
["2\n8\n1\n999999733\n1"]
NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels.
Java 8
standard input
[ "number theory", "math" ]
f00eb0452f5933103f1f77ef06473c6a
The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages.
1,300
Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages.
standard output
PASSED
f05b80256a0994ed7b9f9525e5a788d4
train_002.jsonl
1590327300
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Map.Entry; import java.util.Scanner; import java.util.TreeMap; public class Gd { public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { long n=sc.nextLong(); long k=sc.nextLong(); if(k>=n) { System.out.println(1); } else if(new BigInteger(Long.toString(n)).isProbablePrime(1)==true||k==1) { System.out.println(n); } else { long max=0; outer:for(long i=1;i<=Math.sqrt(n);i++) { if(n%i==0) { if(n/i>max&&(n/i)<=k) { max=n/i; } if(i>max&&i<=k) { max=i; } } } System.out.println(n/max); } } } }
Java
["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"]
2 seconds
["2\n8\n1\n999999733\n1"]
NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels.
Java 8
standard input
[ "number theory", "math" ]
f00eb0452f5933103f1f77ef06473c6a
The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages.
1,300
Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages.
standard output
PASSED
2451200c921b1e78da613db301471bda
train_002.jsonl
1590327300
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive.
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ //package javaapplication1; import java.lang.Math; import java.util.*; import java.math.*; /** * * @author ujjwal abhishek */ public class Shovel { static boolean checkPrime(long n) { BigInteger b = new BigInteger(String.valueOf(n)); return b.isProbablePrime(1); } // static int gcd(int a, int b) // { // if (b == 0) // return a; // return gcd(b, a % b); // } public static void main(String []args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int k=sc.nextInt(); if (k>=n) System.out.println(1); else if(k==1 || checkPrime(n)==true) System.out.println(n); else { int temp=(int) Math.sqrt(n); int ans=n; for(int i=2;i<=temp;i++) { if (n%i==0) { if(i<=k) { ans=Math.min(ans,n/i); } if(n/i<=k) { ans=Math.min(i,ans); } } } System.out.println(ans); } } } }
Java
["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"]
2 seconds
["2\n8\n1\n999999733\n1"]
NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels.
Java 8
standard input
[ "number theory", "math" ]
f00eb0452f5933103f1f77ef06473c6a
The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages.
1,300
Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages.
standard output
PASSED
bc9c73290e809b8bbb09496bbe7674f6
train_002.jsonl
1590327300
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive.
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ //package javaapplication1; import java.lang.Math; import java.util.*; import java.math.*; /** * * @author ujjwal abhishek */ public class Shovel { public static void main(String []args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int k=sc.nextInt(); if (k==1) { System.out.println(n); continue; } int temp=(int) Math.sqrt(n); int ans=n; for(int i=1;i<=temp;i++) { if (n%i==0) { if(i<=k) { ans=Math.min(ans,n/i); } if(n/i<=k) { ans=Math.min(i,ans); } } } System.out.println(ans); } } }
Java
["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"]
2 seconds
["2\n8\n1\n999999733\n1"]
NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels.
Java 8
standard input
[ "number theory", "math" ]
f00eb0452f5933103f1f77ef06473c6a
The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages.
1,300
Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages.
standard output