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
|
d054b4e7dd5a6941c5bbdc499311183b
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
static {
try {
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
} catch (Exception e) {}
}
void solve() {
int n = in.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for (int i = 0; i < n; i++) {
x[i] = in.nextInt();
y[i] = in.nextInt();
}
if (n % 2 == 1) {
out.append("1\n");
return;
}
Arrays.sort(x);
Arrays.sort(y);
int half1 = (n - 1) / 2;
int half2 = n / 2;
int xlow = x[half1];
int xhigh = x[half2];
int ylow = y[half1];
int yhigh = y[half2];
long res = 1L * (xhigh - xlow + 1) * 1L * (yhigh - ylow + 1);
out.append(res + "\n");
}
public static void main (String[] args) {
// Its Not Over Untill I Win - Syed Mizbahuddin
Main sol = new Main();
int t = 1;
t = in.nextInt();
while (t-- != 0) {
sol.solve();
}
System.out.print(out);
}
<T> void println(T[] s) {
System.out.println(Arrays.toString(s));
}
<T> void println(T s) {
System.out.println(s);
}
void print(int s) {
System.out.print(s);
}
void println(int s) {
System.out.println(s);
}
void println(int[] a) {
println(Arrays.toString(a));
}
int[] array(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
return a;
}
int[] array1(int n) {
int[] a = new int[n + 1];
for (int i = 1; i <= n; i++) {
a[i] = in.nextInt();
}
return a;
}
static FastReader in;
static StringBuffer out;
final int MAX;
final int MIN;
int mod ;
Main() {
in = new FastReader();
out = new StringBuffer();
MAX = Integer.MAX_VALUE;
MIN = Integer.MIN_VALUE;
mod = (int)1e9 + 7;
}
}
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
563c3aff4440fdc596c2cab749a165d8
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.lang.Math.ceil;
import static java.util.Arrays.sort;
public class C {
static int mod = 1000000007;
public static void main(String[] args) throws Exception {
int test = ri();
while (test-- > 0) {
int n = ri();
int x[] = new int[n];
int y[] = new int[n];
for (int i = 0; i < n; i++) {
int xx = rni(), yy = ni();
x[i] = xx;
y[i] = yy;
}
Arrays.sort(x);
Arrays.sort(y);
if (n%2 == 1){
prln(1);
}else{
prln(((long) (x[n / 2] - x[n / 2 - 1] + 1) * ((y[n/2])-y[n/2-1]+1)));
}
}
close();
}
static class Nodes {
long a;
int b;
Nodes(long a, int b) {
this.a = a;
this.b = b;
}
}
static class DisjointSetUnion {
int p[];
int count[];
public DisjointSetUnion(int n) {
p = new int[n];
count = new int[n];
for (int i = 0; i < n; i++) {
count[i] = 1;
}
clear(n);
}
public void clear(int n) {
for (int i = 0; i < n; i++) {
p[i] = i;
}
}
public int get(int x) {
return x != p[x] ? p[x] = get(p[x]) : x;
}
public int getCount(int x) {
return count[x];
}
public boolean union(int a, int b) {
a = get(a);
b = get(b);
p[a] = b;
if (a != b) {
count[b] += count[a];
count[a] = 0;
}
return a != b;
}
}
static BufferedReader __i = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter __o = new PrintWriter(new OutputStreamWriter(System.out));
static StringTokenizer input;
static boolean[] isPrime;
static Random __r = new Random();
// references
// IBIG = 1e9 + 7
// IMAX ~= 2e9
// LMAX ~= 9e18
// constants
static final int IBIG = 1000000007;
static final int IMAX = 2147483647;
static final long LMAX = 9223372036854775807L;
// math util
static int minof(int a, int b, int c) {
return min(a, min(b, c));
}
static int minof(int... x) {
if (x.length == 1) return x[0];
if (x.length == 2) return min(x[0], x[1]);
if (x.length == 3) return min(x[0], min(x[1], x[2]));
int min = x[0];
for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i];
return min;
}
static long minof(long a, long b, long c) {
return min(a, min(b, c));
}
static long minof(long... x) {
if (x.length == 1) return x[0];
if (x.length == 2) return min(x[0], x[1]);
if (x.length == 3) return min(x[0], min(x[1], x[2]));
long min = x[0];
for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i];
return min;
}
static int maxof(int a, int b, int c) {
return max(a, max(b, c));
}
static int maxof(int... x) {
if (x.length == 1) return x[0];
if (x.length == 2) return max(x[0], x[1]);
if (x.length == 3) return max(x[0], max(x[1], x[2]));
int max = x[0];
for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i];
return max;
}
static long maxof(long a, long b, long c) {
return max(a, max(b, c));
}
static long maxof(long... x) {
if (x.length == 1) return x[0];
if (x.length == 2) return max(x[0], x[1]);
if (x.length == 3) return max(x[0], max(x[1], x[2]));
long max = x[0];
for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i];
return max;
}
static int powi(int a, int b) {
if (a == 0) return 0;
int ans = 1;
while (b > 0) {
if ((b & 1) > 0) ans *= a;
a *= a;
b >>= 1;
}
return ans;
}
static long powl(long a, int b) {
if (a == 0) return 0;
long ans = 1;
while (b > 0) {
if ((b & 1) > 0) ans *= a;
a *= a;
b >>= 1;
}
return ans;
}
static int fli(double d) {
return (int) d;
}
static int cei(double d) {
return (int) ceil(d);
}
static long fll(double d) {
return (long) d;
}
static long cel(double d) {
return (long) ceil(d);
}
static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
static int[] exgcd(int a, int b) {
if (b == 0) return new int[]{1, 0};
int[] y = exgcd(b, a % b);
return new int[]{y[1], y[0] - y[1] * (a / b)};
}
static long[] exgcd(long a, long b) {
if (b == 0) return new long[]{1, 0};
long[] y = exgcd(b, a % b);
return new long[]{y[1], y[0] - y[1] * (a / b)};
}
static int randInt(int min, int max) {
return __r.nextInt(max - min + 1) + min;
}
static long mix(long x) {
x += 0x9e3779b97f4a7c15L;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L;
x = (x ^ (x >> 27)) * 0x94d049bb133111ebL;
return x ^ (x >> 31);
}
static void setTrue(int n) {
for (int i = 0; i < n; i++) {
isPrime[i] = true;
}
}
static void prime(int n) {
for (int i = 2; i * i < n; i++) {
if (isPrime[i]) {
for (int j = i * i; j < n; j += i) isPrime[j] = false;
}
}
}
public static long lcm(long number1, long number2) {
if (number1 == 0 || number2 == 0) {
return 0;
}
long absNumber1 = Math.abs(number1);
long absNumber2 = Math.abs(number2);
long absHigherNumber = Math.max(absNumber1, absNumber2);
long absLowerNumber = Math.min(absNumber1, absNumber2);
long lcm = absHigherNumber;
while (lcm % absLowerNumber != 0) {
lcm += absHigherNumber;
}
return lcm;
}
// array util
static void reverse(int[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
int swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(long[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
long swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(double[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
double swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(char[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
char swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void shuffle(int[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
int swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void shuffle(long[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
long swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void shuffle(double[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
double swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void rsort(int[] a) {
shuffle(a);
sort(a);
}
static void rsort(long[] a) {
shuffle(a);
sort(a);
}
static void rsort(double[] a) {
shuffle(a);
sort(a);
}
static int[] copy(int[] a) {
int[] ans = new int[a.length];
for (int i = 0; i < a.length; ++i) ans[i] = a[i];
return ans;
}
static long[] copy(long[] a) {
long[] ans = new long[a.length];
for (int i = 0; i < a.length; ++i) ans[i] = a[i];
return ans;
}
static double[] copy(double[] a) {
double[] ans = new double[a.length];
for (int i = 0; i < a.length; ++i) ans[i] = a[i];
return ans;
}
static char[] copy(char[] a) {
char[] ans = new char[a.length];
for (int i = 0; i < a.length; ++i) ans[i] = a[i];
return ans;
}
static void resetBoolean(boolean[] vis, int n) {
for (int i = 0; i < n; i++) {
vis[i] = false;
}
}
static void setMinusOne(int[][] matrix) {
int row = matrix.length;
int col = matrix[0].length;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
matrix[i][j] = -1;
}
}
}
// input
static void r() throws IOException {
input = new StringTokenizer(rline());
}
static int ri() throws IOException {
return Integer.parseInt(rline().split(" ")[0]);
}
static long rl() throws IOException {
return Long.parseLong(rline());
}
static double rd() throws IOException {
return Double.parseDouble(rline());
}
static int[] ria(int n) throws IOException {
int[] a = new int[n];
r();
for (int i = 0; i < n; ++i) a[i] = ni();
return a;
}
static void ria(int[] a) throws IOException {
int n = a.length;
r();
for (int i = 0; i < n; ++i) a[i] = ni();
}
static int[] riam1(int n) throws IOException {
int[] a = new int[n];
r();
for (int i = 0; i < n; ++i) a[i] = ni() - 1;
return a;
}
static void riam1(int[] a) throws IOException {
int n = a.length;
r();
for (int i = 0; i < n; ++i) a[i] = ni() - 1;
}
static long[] rla(int n) throws IOException {
long[] a = new long[n];
r();
for (int i = 0; i < n; ++i) a[i] = nl();
return a;
}
static void rla(long[] a) throws IOException {
int n = a.length;
r();
for (int i = 0; i < n; ++i) a[i] = nl();
}
static double[] rda(int n) throws IOException {
double[] a = new double[n];
r();
for (int i = 0; i < n; ++i) a[i] = nd();
return a;
}
static void rda(double[] a) throws IOException {
int n = a.length;
r();
for (int i = 0; i < n; ++i) a[i] = nd();
}
static char[] rcha() throws IOException {
return rline().toCharArray();
}
static void rcha(char[] a) throws IOException {
int n = a.length, i = 0;
for (char c : rline().toCharArray()) a[i++] = c;
}
static String rline() throws IOException {
return __i.readLine();
}
static String n() {
return input.nextToken();
}
static int rni() throws IOException {
r();
return ni();
}
static int ni() {
return Integer.parseInt(n());
}
static long rnl() throws IOException {
r();
return nl();
}
static long nl() {
return Long.parseLong(n());
}
static double rnd() throws IOException {
r();
return nd();
}
static double nd() {
return Double.parseDouble(n());
}
// output
static void pr(int i) {
__o.print(i);
}
static void prln(int i) {
__o.println(i);
}
static void pr(long l) {
__o.print(l);
}
static void prln(long l) {
__o.println(l);
}
static void pr(double d) {
__o.print(d);
}
static void prln(double d) {
__o.println(d);
}
static void pr(char c) {
__o.print(c);
}
static void prln(char c) {
__o.println(c);
}
static void pr(char[] s) {
__o.print(new String(s));
}
static void prln(char[] s) {
__o.println(new String(s));
}
static void pr(String s) {
__o.print(s);
}
static void prln(String s) {
__o.println(s);
}
static void pr(Object o) {
__o.print(o);
}
static void prln(Object o) {
__o.println(o);
}
static void prln() {
__o.println();
}
static void pryes() {
prln("yes");
}
static void pry() {
prln("Yes");
}
static void prY() {
prln("YES");
}
static void prno() {
prln("no");
}
static void prn() {
prln("No");
}
static void prN() {
prln("NO");
}
static boolean pryesno(boolean b) {
prln(b ? "yes" : "no");
return b;
}
;
static boolean pryn(boolean b) {
prln(b ? "Yes" : "No");
return b;
}
static boolean prYN(boolean b) {
prln(b ? "YES" : "NO");
return b;
}
static void prln(int... a) {
for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;
if (a.length > 0) prln(a[a.length - 1]);
else prln();
}
static void prln(long... a) {
for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;
if (a.length > 0) prln(a[a.length - 1]);
else prln();
}
static void prln(double... a) {
for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;
if (a.length > 0) prln(a[a.length - 1]);
else prln();
}
static <T> void prln(Collection<T> c) {
int n = c.size() - 1;
Iterator<T> iter = c.iterator();
for (int i = 0; i < n; pr(iter.next()), pr(' '), ++i) ;
if (n >= 0) prln(iter.next());
else prln();
}
static void h() {
prln("hlfd");
flush();
}
static void flush() {
__o.flush();
}
static void close() {
__o.close();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
24c280a0e8b0f08e80fd7e442195bc28
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
//some updates in import stuff
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
static int mod = (int) (Math.pow(10, 9)+7);
static final int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
static final int[] dx8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy8 = { -1, 0, 1, -1, 1, -1, 0, 1 };
static final int[] dx9 = { -1, -1, -1, 0, 0, 0, 1, 1, 1 }, dy9 = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
static final double eps = 1e-10;
static List<Integer> primeNumbers = new ArrayList<>();
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
//code below
int test = sc.nextInt();
while(test -- > 0){
int n = sc.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for(int i = 0; i < n; i++){
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
sort(x);
sort(y);
long ans = 0;
if(n%2 == 1){
ans = 1;
}else{
int lx = n/2 -1;
int rx = n/2;
int left = x[rx] - x[lx] + 1;
int right = y[rx] - y[lx] + 1;
ans = (long)left * (long)right;
}
out.println(ans);
}
out.close();
}
//Updation Required
//Fenwick Tree (customisable)
//Segment Tree (customisable)
//-----CURRENTLY PRESENT-------//
//Graph
//DSU
//powerMODe
//power
//Segment Tree (work on this one)
//Prime Sieve
//Count Divisors
//Next Permutation
//Get NCR
//isVowel
//Sort (int)
//Sort (long)
//Binomial Coefficient
//Pair
//Triplet
//lcm (int & long)
//gcd (int & long)
//gcd (for binomial coefficient)
//swap (int & char)
//reverse
//Fast input and output
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//GRAPH (basic structure)
public static class Graph{
public int V;
public ArrayList<ArrayList<Integer>> edges;
//2 -> [0,1,2] (current)
Graph(int V){
this.V = V;
edges = new ArrayList<>(V+1);
for(int i= 0; i <= V; i++){
edges.add(new ArrayList<>());
}
}
public void addEdge(int from , int to){
edges.get(from).add(to);
}
}
//DSU (path and rank optimised)
public static class DisjointUnionSets {
int[] rank, parent;
int n;
public DisjointUnionSets(int n)
{
rank = new int[n];
parent = new int[n];
Arrays.fill(rank, 1);
Arrays.fill(parent,-1);
this.n = n;
}
public int find(int curr){
if(parent[curr] == -1)
return curr;
//path compression optimisation
return parent[curr] = find(parent[curr]);
}
public void union(int a, int b){
int s1 = find(a);
int s2 = find(b);
if(s1 != s2){
if(rank[s1] < rank[s2]){
parent[s1] = s2;
rank[s2] += rank[s1];
}else{
parent[s2] = s1;
rank[s1] += rank[s2];
}
}
}
}
//with mod
public static long powerMOD(long x, long y)
{
long res = 1L;
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0){
x %= mod;
res %= mod;
res = (res * x)%mod;
}
// y must be even now
y = y >> 1; // y = y/2
x%= mod;
x = (x * x)%mod; // Change x to x^2
}
return res%mod;
}
//without mod
public static long power(long x, long y)
{
long res = 1L;
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0){
res = (res * x);
}
// y must be even now
y = y >> 1; // y = y/
x = (x * x);
}
return res;
}
public static class segmentTree{
public long[] arr;
public long[] tree;
public long[] lazy;
segmentTree(long[] array){
int n = array.length;
arr = new long[n];
for(int i= 0; i < n; i++) arr[i] = array[i];
tree = new long[4*n + 1];
lazy = new long[4*n + 1];
}
public void build(int[]arr, int s, int e, int[] tree, int index){
if(s == e){
tree[index] = arr[s];
return;
}
//otherwise divide in two parts and fill both sides simply
int mid = (s+e)/2;
build(arr, s, mid, tree, 2*index);
build(arr, mid+1, e, tree, 2*index+1);
//who will build the current position dude
tree[index] = Math.min(tree[2*index], tree[2*index+1]);
}
public int query(int sr, int er, int sc, int ec, int index, int[] tree){
if(lazy[index] != 0){
tree[index] += lazy[index];
if(sc != ec){
lazy[2*index+1] += lazy[index];
lazy[2*index] += lazy[index];
}
lazy[index] = 0;
}
//no overlap
if(sr > ec || sc > er) return Integer.MAX_VALUE;
//found the index baby
if(sr <= sc && ec <= er) return tree[index];
//finding the index on both sides hehehehhe
int mid = (sc + ec)/2;
int left = query(sr, er, sc, mid, 2*index, tree);
int right = query(sr, er, mid+1, ec, 2*index + 1, tree);
return Integer.min(left, right);
}
//now we will do point update implementation
//it should be simple then we expected for sure
public void update(int index, int indexr, int increment, int[] tree, int s, int e){
if(lazy[index] != 0){
tree[index] += lazy[index];
if(s != e){
lazy[2*index+1] = lazy[index];
lazy[2*index] = lazy[index];
}
lazy[index] = 0;
}
//no overlap
if(indexr < s || indexr > e) return;
//found the required index
if(s == e){
tree[index] += increment;
return;
}
//search for the index on both sides
int mid = (s+e)/2;
update(2*index, indexr, increment, tree, s, mid);
update(2*index+1, indexr, increment, tree, mid+1, e);
//now update the current range simply
tree[index] = Math.min(tree[2*index+1], tree[2*index]);
}
public void rangeUpdate(int[] tree , int index, int s, int e, int sr, int er, int increment){
//if not at all in the same range
if(e < sr || er < s) return;
//complete then also move forward
if(s == e){
tree[index] += increment;
return;
}
//otherwise move in both subparts
int mid = (s+e)/2;
rangeUpdate(tree, 2*index, s, mid, sr, er, increment);
rangeUpdate(tree, 2*index + 1, mid+1, e, sr, er, increment);
//update current range too na
//i always forget this step for some reasons hehehe, idiot
tree[index] = Math.min(tree[2*index], tree[2*index + 1]);
}
public void rangeUpdateLazy(int[] tree, int index, int s, int e, int sr, int er, int increment){
//update lazy values
//resolve lazy value before going down
if(lazy[index] != 0){
tree[index] += lazy[index];
if(s != e){
lazy[2*index+1] += lazy[index];
lazy[2*index] += lazy[index];
}
lazy[index] = 0;
}
//no overlap case
if(sr > e || s > er) return;
//complete overlap
if(sr <= s && er >= e){
tree[index] += increment;
if(s != e){
lazy[2*index+1] += increment;
lazy[2*index] += increment;
}
return;
}
//otherwise go on both left and right side and do your shit
int mid = (s + e)/2;
rangeUpdateLazy(tree, 2*index, s, mid, sr, er, increment);
rangeUpdateLazy(tree, 2*index + 1, mid+1, e, sr, er, increment);
tree[index] = Math.min(tree[2*index+1], tree[2*index]);
return;
}
}
//prime sieve
public static void primeSieve(int n){
BitSet bitset = new BitSet(n+1);
for(long i = 0; i < n ; i++){
if (i == 0 || i == 1) {
bitset.set((int) i);
continue;
}
if(bitset.get((int) i)) continue;
primeNumbers.add((int)i);
for(long j = i; j <= n ; j+= i)
bitset.set((int)j);
}
}
//number of divisors
public static int countDivisors(long number){
if(number == 1) return 1;
List<Integer> primeFactors = new ArrayList<>();
int index = 0;
long curr = primeNumbers.get(index);
while(curr * curr <= number){
while(number % curr == 0){
number = number/curr;
primeFactors.add((int) curr);
}
index++;
curr = primeNumbers.get(index);
}
if(number != 1) primeFactors.add((int) number);
int current = primeFactors.get(0);
int totalDivisors = 1;
int currentCount = 2;
for (int i = 1; i < primeFactors.size(); i++) {
if (primeFactors.get(i) == current) {
currentCount++;
} else {
totalDivisors *= currentCount;
currentCount = 2;
current = primeFactors.get(i);
}
}
totalDivisors *= currentCount;
return totalDivisors;
}
//now adding next permutation function to java hehe
public static boolean next_permutation(int[] p) {
for (int a = p.length - 2; a >= 0; --a)
if (p[a] < p[a + 1])
for (int b = p.length - 1;; --b)
if (p[b] > p[a]) {
int t = p[a];
p[a] = p[b];
p[b] = t;
for (++a, b = p.length - 1; a < b; ++a, --b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
return true;
}
return false;
}
//finding the value of NCR in O(RlogN) time and O(1) space
public static long getNcR(int n, int r)
{
long p = 1, k = 1;
if (n - r < r) r = n - r;
if (r != 0) {
while (r > 0) {
p *= n;
k *= r;
long m = __gcd(p, k);
p /= m;
k /= m;
n--;
r--;
}
}
else {
p = 1;
}
return p;
}
//is vowel function
public static boolean isVowel(char c)
{
return (c=='a' || c=='A' || c=='e' || c=='E' || c=='i' || c=='I' || c=='o' || c=='O' || c=='u' || c=='U');
}
//to sort the array with better method
public static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
//sort long
public static void sort(long[] a) {
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
//for calculating binomialCoeff
public static int binomialCoeff(int n, int k)
{
int C[] = new int[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] + C[j - 1];
}
return C[k];
}
//Pair with int int
public static class Pair{
public int a;
public int b;
Pair(int a , int b){
this.a = a;
this.b = b;
}
@Override
public String toString(){
return a + " -> " + b;
}
}
//Triplet with int int int
public static class Triplet{
public int a;
public int b;
public int c;
Triplet(int a , int b, int c){
this.a = a;
this.b = b;
this.c = c;
}
@Override
public String toString(){
return a + " -> " + b;
}
}
//Shortcut function
public static long lcm(long a , long b){
return a * (b/gcd(a,b));
}
//let's make one for calculating lcm basically
public static int lcm(int a , int b){
return (a * b)/gcd(a,b);
}
//int version for gcd
public static int gcd(int a, int b){
if(b == 0)
return a;
return gcd(b , a%b);
}
//long version for gcd
public static long gcd(long a, long b){
if(b == 0)
return a;
return gcd(b , a%b);
}
//for ncr calculator(ignore this code)
public static long __gcd(long n1, long n2)
{
long gcd = 1;
for (int i = 1; i <= n1 && i <= n2; ++i) {
// Checks if i is factor of both integers
if (n1 % i == 0 && n2 % i == 0) {
gcd = i;
}
}
return gcd;
}
//swapping two elements in an array
public static void swap(int[] arr, int left , int right){
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
}
//for char array
public static void swap(char[] arr, int left , int right){
char temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
}
//reversing an array
public static void reverse(int[] arr){
int left = 0;
int right = arr.length-1;
while(left <= right){
swap(arr, left,right);
left++;
right--;
}
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
2afbc0bca1bfc280e4b5b130721191e7
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class CodeForces {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int tt = fs.nextInt();
while(tt-- > 0) {
int n = fs.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for(int i = 0; i < n; i++) {
x[i] = fs.nextInt();
y[i] = fs.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
if(n % 2 != 0) {
System.out.println(1);
}else {
System.out.println( (long)(x[n / 2] - x[n / 2 - 1] + 1) * (long)(y[n / 2] - y[n / 2 - 1] + 1));
}
}
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
7edb2dfccefdab644487258759741938
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Solution {
// // static int ans=0;
// static int[] nodeColors;
// static boolean[] visited;
// static String[][] neighborstring;
//
// static List<Integer>[] startIndices;
// static int[] edgesToPrint;
// static int mod = 998244353;
// static int[] parents;
// static HashSet<Integer> cycleSet;
// static PriorityQueue<Integer>[] neighborPriority;
// static int[] minPointsToEnterRoom;
// static int[] maxPointsToEnterRoom;
// static int[] pointOfEachRoom;
// static List<Integer>[] neighbors;
// static int[][] memo;
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in) );
// BufferedReader bufferedReader = new BufferedReader(new FileReader("./input.txt"));
int tests = Integer.parseInt(bufferedReader.readLine());
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < tests; i++) {
int no = Integer.parseInt(bufferedReader.readLine());
int [] xarr= new int[no];
int [] yarr= new int[no];
for (int j = 0; j < no; j++) {
String[] input = bufferedReader.readLine().split(" ");
int x = Integer.parseInt(input[0]);
int y= Integer.parseInt(input[1]);
xarr[j]= x;
yarr[j]=y;
}
Arrays.sort(xarr);
Arrays.sort(yarr);
long ans = xarr[xarr.length/2] -xarr[(xarr.length-1)/2 ] +1;
ans *=yarr[yarr.length/2] -yarr[(yarr.length-1)/2 ] +1;
stringBuilder.append(ans).append("\n");
}
System.out.println(stringBuilder);
// String[] input = bufferedReader.readLine().split(" ");
// int n = Integer.parseInt(input[0]);
// int x= Integer.parseInt(input[1]);
// int y= Integer.parseInt(input[2]);
// double radius = n/2.0;
// int ydiv = y/n;
// int ymod = y %n;
// if (ymod == 0 ){
// System.out.println(-1);
// return;
// }
// if(x == 0 && ((y >= 2 * n && y <= 3 * n) || (y >= 4 * n && y <= 5 * n) )){
// System.out.println(-1);
// return;
// }
// int absx= Math.abs(x);
//
// int ans =-1;
// if(y < 5 * n && absx < radius ){
// int rowpos = y/n;
// if( rowpos == 0 || rowpos == 1 ){
// ans= rowpos +1;
// }else if(rowpos == 3){
// ans = rowpos +2;
// }else {
// if (y < 3* n && y > 2 *n){
// if (x> 0 ){
// ans=4;
// }else {
// ans=3;
// }
//
//
// }else if(y < 5 * n && y > 4 * n){
// if (x> 0 ){
// ans=7;
// }else {
// ans=6;
// }
// }
// }
// }else if(absx< n){
// if (y < 3* n && y > 2 *n){
// if (x> 0 ){
// ans=4;
// }else {
// ans=3;
// }
//
//
// }else if(y < 5 * n && y > 4 * n){
// if (x> 0 ){
// ans=7;
// }else {
// ans=6;
// }
// }
//
// }
// System.out.println(ans);
// int test = Integer.parseInt(bufferedReader.readLine());
// StringBuilder stringBuilder = new StringBuilder();
// for (int t = 0; t < test; t++) {
// String[] input = bufferedReader.readLine().split(" ");
// int n = Integer.parseInt(input[0]);
// int k= Integer.parseInt(input[1]);
// String[] inp = bufferedReader.readLine().split(" ");
// int [] cache = new int[10];
// for (int i = 0; i < inp.length; i++) {
// cache[Integer.parseInt(inp[i])] = 1;
// }
// long ans =0;
// int rem =k+1;
// int previous =0;
// for (int i = 1; i < cache.length; i++) {
// if(cache[i] ==1){
// int pow = i-previous;
// previous = i;
// long number = (long)Math.pow(10,pow)-1;
// if(number >= rem){
// ans =Long.parseLong(String.valueOf(rem) + ans);
// break;
// }else {
// ans=Long.parseLong(String.valueOf(number) +ans);
// if(ans%10 ==0)ans= ans/10;
// rem-=number;
// }
// }
// }
// stringBuilder.append(ans).append("\n");
//
// }
// System.out.println(stringBuilder);
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
881f0ccf86947f8c3edb7ef996634064
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Anubhav
*/
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);
BEasternExhibition solver = new BEasternExhibition();
solver.solve(1, in, out);
out.close();
}
static class BEasternExhibition {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
long x[] = new long[n];
long y[] = new long[n];
for (int i = 0; i < n; i++) {
x[i] = in.nextLong();
y[i] = in.nextLong();
}
Arrays.sort(x);
Arrays.sort(y);
HashMap<Long, Integer> map1 = new HashMap<>();
HashMap<Long, Integer> map2 = new HashMap<>();
List<Long> li1 = new ArrayList<>();
List<Long> li2 = new ArrayList<>();
for (int i = 0; i < n; i++) {
long a = x[i];
long b = y[i];
if (!map1.containsKey(a)) {
li1.add(a);
map1.put(a, 0);
}
if (!map2.containsKey(b)) {
li2.add(b);
map2.put(b, 0);
}
map1.put(a, map1.get(a) + 1);
map2.put(b, map2.get(b) + 1);
}
int done = 0;
long xx = 1;
for (int i = 0; i < li1.size(); i++) {
long val = li1.get(i);
int c = map1.get(val);
done += c;
long left = n - done;
if (left == done) {
xx = li1.get(i + 1);
xx -= val;
xx += 1;
break;
}
if (done == left + c) {
xx = 1;
break;
}
}
done = 0;
long yy = 1;
for (int i = 0; i < li2.size(); i++) {
long val = li2.get(i);
int c = map2.get(val);
done += c;
long left = n - done;
if (left == done) {
yy = li2.get(i + 1);
yy -= val;
yy += 1;
break;
}
if (done == left + c) {
yy = 1;
break;
}
}
long ans = xx * yy;
out.println(ans);
}
}
}
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();
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
d076a89be308e24af0ac09bd916eb85c
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;
public class EasternExhibition {
public static void main(String[] args) throws IOException {
try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
int ts = Integer.parseInt(in.readLine());
for (int t = 0; t < ts; ++t) {
int n = Integer.parseInt(in.readLine());
long[] x = new long[n];
long[] y = new long[n];
for (int i = 0; i < n; ++i) {
StringTokenizer tok = new StringTokenizer(in.readLine());
x[i] = Long.parseLong(tok.nextToken());
y[i] = Long.parseLong(tok.nextToken());
}
Arrays.sort(x);
Arrays.sort(y);
int l = (n - 1) / 2;
int r = n / 2;
long res = (x[r] - x[l] + 1) * (y[r] - y[l] + 1);
System.out.println(res);
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
3150592a4dc30b8e77fa711d2463ae69
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
/*
_oo0oo_
o8888888o
88" . "88
(| -_- |)
0\ = /0
___/`---'\___
.' \\| |// '.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' |_/ |
\ .-\__ '-' ___/-. /
___'. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' >' "".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `_. \_ __\ /__ _/ .-` / /
=====`-.____`.___ \_____/___.-`___.-'=====
`=---='
*/
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.Math.*;
public class KickStart2020 {
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());
}
float nextFloat() {
return Float.parseFloat(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
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 / gcd(a, b) * b;
}
public static class Pair implements Comparable<Pair> {
public long index;
public long value;
public Pair(long index, long value) {
this.index = index;
this.value = value;
}
@Override
public int compareTo(Pair other) {
// multiplied to -1 as the author need descending sort order
if(other.index < this.index) return 1;
if(other.index > this.index) return -1;
if(other.value < this.value) return -1;
if(other.value > this.value) return 1;
else return 0;
}
@Override
public String toString() {
return this.index + " " + this.value;
}
}
static boolean isPrime(long d) {
if (d == 1)
return false;
for (int i = 2; i <= (long) Math.sqrt(d); i++) {
if (d % i == 0)
return false;
}
return true;
}
static void decimalTob(int n, int k, Stack<Integer> ss) {
int x = n % k;
int y = n / k;
ss.push(x);
if(y > 0) {
decimalTob(y, k, ss);
}
}
static long powermod(long x, long y, long mod) {
long ans = 1;
x = x % mod;
if (x == 0)
return 0;
int i = 1;
while (y > 0) {
if ((y & 1) != 0)
ans = (ans * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return ans;
}
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
outerloop:
while(t-- > 0) {
int n = sc.nextInt();
ArrayList<Integer> ss = new ArrayList<>();
ArrayList<Integer> ssd = new ArrayList<>();
for(int i = 0; i < n; i++) {
ss.add(sc.nextInt());
ssd.add(sc.nextInt());
}
Collections.sort(ss);
Collections.sort(ssd);
long ans = (long)(ss.get(n / 2) - ss.get((n - 1) / 2) + 1) * (ssd.get(n / 2) - ssd.get((n - 1) / 2) + 1);
out.println(ans);
}
out.close();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
a344cf7f5775152f8de7e878a9107382
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
static long mod = 1000000007;
static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static void main(String[] args) throws IOException {
FastReader sc = new FastReader();
int t = sc.nextInt();
while( t-- > 0) {
int n = sc.nextInt();
ArrayList<Integer> x = new ArrayList<>();
ArrayList<Integer> y = new ArrayList<>();
HashMap<Integer, Integer> X = new HashMap<>();
HashMap<Integer,Integer> Y = new HashMap<>();
for( int i =0 ; i< n; i++) {
int fst = sc.nextInt();
x.add(fst);
if( X.containsKey(fst)) {
X.put(fst, X.get(fst)+1);
}
else {
X.put(fst, 1);
}
fst = sc.nextInt();
y.add(fst);
if( Y.containsKey(fst)) {
Y.put(fst, Y.get(fst)+1);
}
else {
Y.put(fst, 1);
}
}
// out.println(x);
// out.println(y);
long a = solve( X , x );
long b = solve( Y , y);
// out.println(a + " " +b);
out.println(a*b);
}
out.flush();
}
private static long solve(HashMap<Integer, Integer> X, ArrayList<Integer> x) {
int size = x.size();
Collections.sort(x);
long rtrn = 0;
if( size %2 == 0) {
rtrn = 1;
int fst = (size-1)/2;
int scnd = fst+1;
int temp = x.get(fst);
int loc = x.get(scnd);
// if( fst != 0 ) {
// rtrn+=Math.max(0, temp - x.get(fst-1)-1);
// }
if( 2 < 3) {
if( loc != temp) {
rtrn++;
}
rtrn+=Math.max(0, loc - temp - 1);
}
// if( scnd != size-1 ) {
// rtrn+=Math.max(0, x.get(scnd+1)-loc-1);
// }
}
else {
rtrn = 1;
int fst = (size-1)/2;
int temp = x.get(fst);
//out.println("mid " + temp);
// if( fst != 0 ) {
// rtrn+=Math.max(0, temp - x.get(fst-1)-1);
// }
// if( fst != size-1 ) {
// rtrn+=Math.max(0, x.get(fst+1)-temp-1);
// }
}
return rtrn;
}
public static int[] nextLargerElement(int[] arr, int n) {
Stack<Integer> stack = new Stack<>();
int rtrn[] = new int[n];
rtrn[n-1] = -1;
stack.push( n-1);
for( int i = n-2 ;i >= 0 ; i--){
int temp = arr[i];
int lol = -1;
while( !stack.isEmpty() && arr[stack.peek()] <= temp){
if(arr[stack.peek()] == temp ) {
lol = stack.peek();
}
stack.pop();
}
if( stack.isEmpty()){
if( lol != -1) {
rtrn[i] = lol;
}
else {
rtrn[i] = -1;
}
}
else{
rtrn[i] = stack.peek();
}
stack.push( i);
}
return rtrn;
}
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
static HashMap<Long,Long> primefactor( long n){
HashMap<Long ,Long> hm = new HashMap<>();
long temp = 0;
while( n%2 == 0) {
temp++;
n/=2;
}
if( temp!= 0) {
hm.put( 2L, temp);
}
long c = (long)Math.sqrt(n);
for( long i = 3 ; i <= c ; i+=2) {
temp = 0;
while( n% i == 0) {
temp++;
n/=i;
}
if( temp!= 0) {
hm.put( i, temp);
}
}
if( n!= 1) {
hm.put( n , 1L);
}
return hm;
}
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
eb8c3de7b05f30641be43d9624e4c5b9
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class File{
static Scanner sc=new Scanner(System.in);
static long find(ArrayList<Integer> x){
Collections.sort(x);
return (long)(x.get(x.size()/2) - x.get((x.size()-1)/2) + 1);
}
static void solve(){
int n=sc.nextInt();
ArrayList<Integer> x=new ArrayList<Integer>();
ArrayList<Integer> y=new ArrayList<Integer>();
for(int i=0;i<n;i++){
int xval=sc.nextInt();
int yval=sc.nextInt();
x.add(xval);
y.add(yval);
}
System.out.println(find(x)*find(y));
}
public static void main(String[] args){
int t=sc.nextInt();
while(t-- > 0){
solve();
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
e58c6a31754f5744a322204bb663320f
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main{
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());
}
String nextLine(){
String sr = "";
try{
sr = br.readLine();
}
catch(IOException e){
e.printStackTrace();
}
return sr;
}
}
public static void main (String[] args) throws java.lang.Exception
{
FastReader ft = new FastReader();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int t = ft.nextInt();
while(t-->0){
int n = ft.nextInt();
ArrayList<Integer> a = new ArrayList<>();
ArrayList<Integer> b = new ArrayList<>();
for(int i = 0;i < n;i++){
a.add(ft.nextInt());
b.add(ft.nextInt());
}
Collections.sort(a);
Collections.sort(b);
if((n&1)!=0)
out.write("1\n");
else
{
long ans = (long)(a.get(n/2)-a.get(n/2-1)+1)*(long)(b.get(n/2)-b.get(n/2-1)+1);
out.write(ans+"\n");
}
}
out.flush();
}}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
6076562ef1d349d0ba3ea9f825f6007f
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class easternExhibition {
public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
FastReader sc = new FastReader();
int t = sc.nextInt();
for(int o = 0 ; o<t;o++) {
int n = sc.nextInt();
int [] x = new int[n];
int [] y = new int[n];
for(int i = 0 ; i<n;i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
if(n%2==1) {
System.out.println(1);
continue;
}
Arrays.sort(x);
Arrays.sort(y);
long a = (long)x[n/2] - (long)x[(n/2) -1]+1;
long b = (long)y[n/2] - (long)y[(n/2) -1]+1;
System.out.println(a * b);
}
}
}
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
343339ff3e1ec868e055d8355294bf74
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
// \(≧▽≦)/
import java.io.*;
import java.util.*;
public class tank {
static final FastScanner fs = new FastScanner();
//static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
int t = fs.nextInt();
while(t-- > 0) {
run_case();
}
//out.close();
}
static void run_case() {
int n = fs.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for (int i = 0; i < n; i++) {
x[i] = fs.nextInt();
y[i] = fs.nextInt();
}
ruffleSort(x);
ruffleSort(y);
System.out.println(fn(x, n) * fn(y, n));
//System.out.println(fn(x, n));
//System.out.println(fn(y, n));
}
static long fn(int[] x, int n) {
long dis = 0, cnt = 0, cur;
for (int i = 0; i < n; i++) {
dis += x[i] - x[0];
}
for (int i = 0; i < n; i++) {
cur = 0;
for (int j = 0; j < n; j++) {
cur += Math.abs(x[i] - x[j]);
}
if(cur < dis) {
cnt = 1;
if(n % 2 == 0 && i == n / 2 - 1) {
if(x[i + 1] > x[i])
cnt += Math.abs(x[i + 1] - x[i]) - 1;
}
dis = cur;
}else if(cur == dis) {
if(i > 0 && x[i] == x[i - 1]) {
if(n % 2 == 0 && i == n / 2 - 1) {
if(x[i + 1] > x[i])
cnt += Math.abs(x[i + 1] - x[i]) - 1;
}
continue;
}
cnt++;
if(n % 2 == 0 && i == n / 2 - 1) {
if(x[i + 1] > x[i])
cnt += Math.abs(x[i + 1] - x[i]) - 1;
}
}
}
return cnt;
}
static void ruffleSort(int[] a) {
int n=a.length;
Random r=new Random();
for (int i=0; i<a.length; i++) {
int oi=r.nextInt(n), temp=a[i];
a[i]=a[oi];
a[oi]=temp;
}
Arrays.sort(a);
}
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();
}
String nextLine(){
try {
return br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
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());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
154d7bb8cafc7337a4fc6752395e2fcd
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class EasternExhibiton {
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));//new FileReader("cowdance.in")
PrintWriter out = new PrintWriter(System.out);//new FileWriter("cowdance.out")
StringTokenizer st = new StringTokenizer(read.readLine());
int t = Integer.parseInt(st.nextToken());
for (int ie = 0; ie < t; ie++) {
st = new StringTokenizer(read.readLine());
int n = Integer.parseInt(st.nextToken());//Long.parseLong(st.nextToken());
long [] x = new long [n];
long [] y = new long [n];
for (int i = 0; i < n; i++) {
st = new StringTokenizer(read.readLine());
x[i] = Long.parseLong(st.nextToken());//Integer.parseInt(st.nextToken());
y[i] = Long.parseLong(st.nextToken());
}
Arrays.sort(x);
long X = x[n/2]-x[(n-1)/2]+1;
Arrays.sort(y);
long Y = y[n/2]-y[(n-1)/2]+1;
out.println(X*Y);
}
out.close();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
f2f67c10c652e07ffaea879f5f238e5a
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class B1486 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
int n = Integer.parseInt(br.readLine());
Integer[] x = new Integer[n];
Integer[] y = new Integer[n];
for (int i = 0; i < n; i++) {
String[] s = br.readLine().trim().split(" ");
x[i] = Integer.parseInt(s[0]);
y[i] = Integer.parseInt(s[1]);
}
Arrays.sort(x);
Arrays.sort(y);
sb.append(equalDist(x) * equalDist(y) + "\n");
}
System.out.println(sb);
}
public static long equalDist(Integer[] a) {
long count = 1;
int n = a.length;
if (n % 2 == 0)
count += a[(n + 1) / 2] - a[(n - 1) / 2];
// System.out.println(a[(n + 2) / 2] + " " + a[n / 2]);
return count;
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
59e936cc2773cb205df2914ea9120563
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.Random;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
BEasternExhibition solver = new BEasternExhibition();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
static class BEasternExhibition {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
long[] x = new long[n];
long[] y = new long[n];
for (int i = 0; i < n; i++) {
x[i] = in.nextInt();
y[i] = in.nextInt();
}
sort(x);
sort(y);
long xdiff = 0, ydiff = 0;
if (n % 2 == 1) {
xdiff = 1;
ydiff = 1;
} else {
int m1 = n / 2, m2 = n / 2 - 1;
xdiff = x[m1] - x[m2] + 1;
ydiff = y[m1] - y[m2] + 1;
}
out.println(xdiff * ydiff);
}
static void sort(long[] a) {
int n = a.length;
Random r = new Random();
for (int i = 0; i < a.length; i++) {
int oi = r.nextInt(n);
long temp = a[i];
a[i] = a[oi];
a[oi] = temp;
}
Arrays.sort(a);
}
}
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 close() {
writer.close();
}
public void println(long i) {
writer.println(i);
}
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
aa58b19a424a81a02f67de7df14a326a
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.List;
import java.util.Arrays;
import java.math.BigInteger;
public class Solution {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int numRounds = Integer.parseInt(scan.nextLine());
for (int round = 0; round < numRounds; round++)
{
int numHouse = Integer.parseInt(scan.nextLine());
BigInteger[] xVars = new BigInteger[numHouse];
BigInteger[] yVars = new BigInteger[numHouse];
for (int i = 0; i < numHouse; i++)
{
String[] temp = scan.nextLine().split(" ");
xVars[i] = new BigInteger(temp[0]);
yVars[i] = new BigInteger(temp[1]);
}
if (numHouse % 2 == 1)
{
System.out.println(1);
continue;
}
Arrays.sort(xVars);
Arrays.sort(yVars);
System.out.println( (xVars[numHouse/2].subtract(xVars[numHouse/2-1]).add(BigInteger.ONE))
.multiply(yVars[numHouse/2].subtract(yVars[numHouse/2-1]).add(BigInteger.ONE)) );
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
2ab3a7ac42b92c79d9a1534c0f2f4873
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
/* package codechef; // don't place package name! */
import java.math.*;
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class B_Eastern_Exhibition
{
FastReader s;
public static void main (String[] args) throws java.lang.Exception
{
new B_Eastern_Exhibition().run();
}
void run()
{
s = new FastReader();
solve();
}
void solve()
{
for(int T = s.nextInt();T > 0;T--)
start();
}
void start()
{
int n =s.nextInt();
long A[]=new long[n];
long B[]=new long[n];
for(int i=0;i<n;i++) {
A[i]=s.nextLong();
B[i]=s.nextLong();
}
if(n%2!=0) {
System.out.println("1");
return;
}
Arrays.sort(A);
Arrays.sort(B);
long a=A[n/2]-A[n/2-1]+1;
long b=B[n/2]-B[n/2-1]+1;
System.out.println(a*b);
}
// print Int arr
public void printIntarr(int [] arr)
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < arr.length;i++)
sb.append(arr[i] + " ");
System.out.println(sb);
}
// print long arr
public void printLongarr(long [] arr)
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < arr.length;i++)
sb.append(arr[i] + " ");
System.out.println(sb);
}
//long array input
public long [] longArr(int len)
{
// long arr input
long [] arr = new long[len];
String [] strs = s.nextLine().trim().split("\\s+");
for(int i =0; i<len; i++)
{
arr[i] = Long.parseLong(strs[i]);
}
return arr;
}
// int arr input
public int [] intArr(int len)
{
// long arr input
int [] arr = new int[len];
String [] strs = s.nextLine().trim().split("\\s+");
for(int i =0; i<len; i++)
{
arr[i] = Integer.parseInt(strs[i]);
}
return arr;
}
// FastReader
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
c9a125b3b3f321a6ee7638e9c768a93f
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.PrintWriter;
import java.util.*;
public class Practice {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-->0){
int n = sc.nextInt();
long[] x = new long[n];
long[] y = new long[n];
for(int i=0;i<n;i++){
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
Arrays.sort(x); Arrays.sort(y);
System.out.println((x[n/2] - x[(n-1)/2] +1) * (y[n/2] - y[(n-1)/2] +1));
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
9224078db28591f19bd9dee36975c176
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
//package easternexhibition;
import java.util.*;
import java.io.*;
public class easternexhibition {
public static void main(String[] args) throws IOException {
BufferedReader fin = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(fin.readLine());
StringBuilder fout = new StringBuilder();
while(t-- > 0) {
int n = Integer.parseInt(fin.readLine());
int[] x = new int[n];
int[] y = new int[n];
for(int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(fin.readLine());
x[i] = Integer.parseInt(st.nextToken());
y[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(x);
Arrays.sort(y);
if(n % 2 == 1) {
fout.append("1\n");
}
else {
long xLow = x[n / 2 - 1];
long xHigh = x[n / 2] + 1;
long yLow = y[n / 2 - 1];
long yHigh = y[n / 2] + 1;
//System.out.println((xHigh - xLow) + " " + (yHigh - yLow));
fout.append((xHigh - xLow) * (yHigh - yLow)).append("\n");
}
}
System.out.print(fout);
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
a6f2cf6d768036d4d7c649ba0b152eb2
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class B {
public static void main(String args[])throws IOException{
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int x[] = new int[n];
int y[] = new int[n];
for(int i = 0; i < n; i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
int ans_x = x[((n)/2)] - x[((n-1)/2)] + 1;
int ans_y = y[((n)/2)] - y[((n-1)/2)] + 1;
out.println(ans_x*(long)ans_y);
}
out.flush();
}
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
ad9da14e2ed6a56f5b37bd5473d5480d
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
static BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
static StringTokenizer tok;
public static void main(String[] args) throws Exception {
solution();
}
public static void solution() throws Exception {
int TestCase = Integer.parseInt(rd.readLine());
for(int TT=0;TT<TestCase;TT++) {
int n = Integer.parseInt(rd.readLine());
long[] arrx = new long[n];
long[] arry = new long[n];
for(int i=0;i<n;i++) {
tok = new StringTokenizer(rd.readLine());
arrx[i] = Long.parseLong(tok.nextToken());
arry[i] = Long.parseLong(tok.nextToken());
}
// System.out.println(Arrays.toString(arrx));
// System.out.println(Arrays.toString(arry));
Arrays.sort(arrx);
Arrays.sort(arry);
if(n%2==0) {
long sizex = Math.abs((arrx[(n/2)-1]) - (arrx[n/2])) + 1;
long sizey = Math.abs((arry[(n/2)-1]) - (arry[n/2])) + 1;
System.out.println(sizex * sizey);
} else {
System.out.println(1);
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
cc2d972e6b1e1f96ec9bcdf01d43c86b
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
public class Training {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; i++) {
int n = in.nextInt();
long [] x = new long [n];
long [] y = new long [n];
for (int j = 0; j < n; j++) {
x[j]=in.nextLong();
y[j]=in.nextLong();
}
if(n%2==1)System.out.println(1);
else {
Arrays.sort(x);
Arrays.sort(y);
long ans = (x[n/2]-x[n/2-1]+1)*(y[n/2]-y[n/2-1]+1);
System.out.println(ans);
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
2df5eb70b92e317b3199a4b8b665de9e
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
public class EasternExhibition {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0)
{
int n = sc.nextInt();
long arr[] = new long[n];
long brr[] = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextLong();
brr[i] = sc.nextLong();
}
Arrays.sort(arr);
Arrays.sort(brr);
if(n%2!=0) System.out.println(1);
else
{
long ans=(arr[n/2]-arr[n/2-1]+1)*(brr[n/2]-brr[n/2-1]+1);
System.out.println(ans);
}
}
}
}
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 (Exception 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 (Exception e) {
e.printStackTrace();
}
return str;
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
59038227a3b8f8c1823f2c9a72d118b1
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
/*
Codeforces
Problem 1486B
*/
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
public class EasternExhibition {
public static void main(String[] args) throws IOException {
FastIO in = new FastIO(System.in);
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
long[] x = new long[n];
long[] y = new long[n];
for (int i = 0; i < n; i++) {
x[i] = in.nextLong();
y[i] = in.nextLong();
}
Arrays.sort(x);
Arrays.sort(y);
if (n % 2 == 0) {
System.out.println((x[n/2] - x[n/2-1]+1) * (y[n/2] - y[n/2-1]+1));
} else {
System.out.println(1);
}
}
in.close();
}
public static class FastIO {
private InputStream dis;
private byte[] buffer = new byte[1 << 17];
private int pointer = 0;
public FastIO(String fileName) throws IOException {
dis = new FileInputStream(fileName);
}
public FastIO(InputStream is) throws IOException {
dis = is;
}
public int nextInt() throws IOException {
int ret = 0;
byte b;
do {
b = nextByte();
} while (b <= ' ');
boolean negative = false;
if (b == '-') {
negative = true;
b = nextByte();
}
while (b >= '0' && b <= '9') {
ret = 10 * ret + b - '0';
b = nextByte();
}
return (negative) ? -ret : ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte b;
do {
b = nextByte();
} while (b <= ' ');
boolean negative = false;
if (b == '-') {
negative = true;
b = nextByte();
}
while (b >= '0' && b <= '9') {
ret = 10 * ret + b - '0';
b = nextByte();
}
return (negative) ? -ret : ret;
}
public byte nextByte() throws IOException {
if (pointer == buffer.length) {
dis.read(buffer, 0, buffer.length);
pointer = 0;
}
return buffer[pointer++];
}
public String next() throws IOException {
StringBuffer ret = new StringBuffer();
byte b;
do {
b = nextByte();
} while (b <= ' ');
while (b > ' ') {
ret.appendCodePoint(b);
b = nextByte();
}
return ret.toString();
}
public void close() throws IOException {
dis.close();
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
aa720868d93adbfd7dc4dd309cad0ead
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
public class Round_2{
static Scanner sc = new Scanner(System.in);
static void solve() {
int n = sc.nextInt();
ArrayList<Long> x = new ArrayList<>();
ArrayList<Long> y = new ArrayList<>();
for(int i=0;i<n;i++) {
x.add(sc.nextLong());
y.add(sc.nextLong());
}
// System.out.println(x);
// System.out.println(y);
if(n%2!=0)
{
System.out.println(1);
}
else {
Collections.sort(x);
Collections.sort(y);
// System.out.println(x);
// System.out.println(y);
int m = n/2;
long xM = x.get(m) - x.get(m-1)+1;
long yM = y.get(m) - y.get(m-1)+1;
System.out.println(xM*yM);
}
}
public static void main(String args[]) {
int t = sc.nextInt();
for(int i=0;i<t;i++)
solve();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
fdae124a8467a7f01e45631c420a5be6
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Locale;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
try (BufferedInputStream in = new BufferedInputStream(System.in);
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {
Scanner sc = new Scanner(in).useLocale(Locale.US);
int T = sc.nextInt();
for (int t = 0; t < T; t++) {
int n = sc.nextInt();
int[] xs = new int[n];
int[] ys = new int[n];
for (int i = 0; i < n; i++) {
xs[i] = sc.nextInt();
ys[i] = sc.nextInt();
}
Arrays.sort(xs);
Arrays.sort(ys);
if (n % 2 == 0) {
long a = xs[n / 2 - 1];
long b = xs[n / 2];
long c = ys[n / 2 - 1];
long d = ys[n / 2];
out.println((b - a + 1) * (d - c + 1));
} else {
out.println(1);
}
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
74a6eede0756d5f2ca155c89ea1caf38
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.lang.*;
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
public class Main {
static FastScanner in = new FastScanner();
static void solve() {
int n = in.nextInt();
long[] x = new long[n], y = new long[n];
for (int i = 0; i < n; ++i) {
x[i] = in.nextLong();
y[i] = in.nextLong();
}
Arrays.sort(x); Arrays.sort(y);
long a = x[n / 2] - x[(n - 1) / 2] + 1;
long b = y[n / 2] - y[(n - 1) / 2] + 1;
System.out.println(a * b);
}
public static void main(String[] args) {
int T = in.nextInt();
while (T-- > 0)
solve();
}
static class Pair<X, Y> {
X x;
Y y;
public Pair(X x, Y y) {
this.x = x;
this.y = y;
}
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
2aa49ea8b6e52863a7ca89a5a27e9e3b
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
static final int M = 1000000007;
static FastReader in = new FastReader();
// static PrintWriter out = new PrintWriter(System.out);
// static Scanner in = new Scanner(System.in);
// File file = new File("input.txt");
// Scanner in = new Scanner(file);
// PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
// Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); // use as int[n][2];
// static boolean[] prime = new boolean[1100001];
public static void main(String[] args) {
int t = in.nextInt();
while(t-- > 0) {
int n = in.nextInt();
long[] x = new long[n]; long[] y = new long[n];
for(int i = 0; i<n; i++) {
x[i] = in.nextLong();
y[i] = in.nextLong();
}
if(n%2==0) {
Arrays.sort(x);
Arrays.sort(y);
System.out.println((x[n/2] - x[n/2 - 1]+1)*(y[n/2] - y[n/2 - 1]+1));
}else {
System.out.println(1);
}
}
}
static void sieve(int n, boolean[] prime)
{
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
}
static int gcd(int a, int b) {
if(b==0) return a;
return gcd(b, a%b);
}
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
dafb8793eb5be22c50a3b15a2b2f357e
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class solve{
public static Reader sc = new Reader();
//public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException{
//BufferedReader br = new BufferedReader(new FileReader("input.in"));
int t = sc.nextInt();
while (t-->0){
int n = sc.nextInt();
long[] x = new long[n];
long[] y = new long[n];
for (int i= 0; i <n; i++) {
x[i] = sc.nextLong();
y[i] = sc.nextLong();
}
//System.out.println(tsx + " " + tsy);
Arrays.sort(x);
Arrays.sort(y);
// Every point in between the median can be the median.
long xp = 0;
long yp = 0;
if (x.length % 2 == 1) {
xp = 1;
}
else {
xp = x[x.length/2] - x[x.length/2-1]+1;
}
if (y.length % 2 == 1) {
yp = 1;
}
else {
yp = y[y.length/2] - y[y.length/2-1]+1;
}
out.println(xp*yp);
}
out.close();
}
static long ceil(long a, long b) {
return (a+b-1)/b;
}
static long powMod(long base, long exp, long mod) {
if (base == 0 || base == 1) return base;
if (exp == 0) return 1;
if (exp == 1) return base % mod;
long R = powMod(base, exp/2, mod) % mod;
R *= R;
R %= mod;
if ((exp & 1) == 1) {
return base * R % mod;
}
else return R % mod;
}
static long pow(long base, long exp) {
if (base == 0 || base == 1) return base;
if (exp == 0) return 1;
if (exp == 1) return base;
long R = pow(base, exp/2);
if ((exp & 1) == 1) {
return R * R * base;
}
else return R * R;
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
{
break;
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, Integer.max(cnt-1, 0));
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
229fd05a2633e35a146592a72e3b1480
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.Scanner;
import java.util.Arrays;
//Thanks be to Lord and Mary
public class sol {
static Scanner in = new Scanner(System.in);
static void solve() {
int a= in.nextInt();
long[] x = new long[a];
long[] y = new long[a];
for(int i = 0;i< a;i++ ) {
x[i] = in.nextInt();
y[i] = in.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
long g = x[a/2] - x[(a-1)/2] + 1;
long h = y[a/2] - y[(a-1)/2] + 1;
System.out.println(g*h);
}
public static void main(String[] args) {
int t = in.nextInt();
for(int i = 0;i< t;i++ ) {
solve();
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
bd3cc0c812b23521a9b010af0c67114f
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class two {
public static void main(String[] args) throws IOException, FileNotFoundException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("two"));
int t = Integer.parseInt(in.readLine());
while (t-- > 0) {
int n = Integer.parseInt(in.readLine());
long[][] arrx =new long[n][2];
long[][] arry =new long[n][2];
for (int i=0; i<n; i++) {
StringTokenizer st = new StringTokenizer(in.readLine());
arrx[i][0] = Integer.parseInt(st.nextToken());
arrx[i][1] = Integer.parseInt(st.nextToken());
arry[i][0] = arrx[i][0];
arry[i][1] = arrx[i][1];
}
Arrays.parallelSort(arrx, new Comparator<long[]>() {
public int compare(long[] a, long[] b) {
return Long.compare(a[0], b[0]);
}
});
Arrays.parallelSort(arry, new Comparator<long[]>() {
public int compare(long[] a, long[] b) {
return Long.compare(a[1], b[1]);
}
});
int needed = (n-1)/2;
if (n%2==0) {
if (n == 2) {
System.out.println((arrx[1][0] - arrx[0][0] + 1) * (arry[1][1] - arry[0][1] + 1));
}
else {
// if (arrx[needed+2][0] != arrx[needed+1][0] || arrx[needed-1][0] != arrx[needed][0] ||
// arry[needed+2][1] != arry[needed+1][1] || arry[needed-1][1] != arry[needed][1]) {
// System.out.println((arrx[needed+2][0]-1 - (arrx[needed-1][0] + 1) + 1) * (arry[needed+2][1]-1 - (arry[needed-1][1]+1) + 1) );
// }
// else {
// System.out.println((arrx[needed+1][0] - (arrx[needed-1][0] ) + 1) * (arry[needed+2][1] - (arry[needed-1][1]) + 1) );
// }
System.out.println((arrx[needed+1][0] - (arrx[needed][0] ) + 1) * (arry[needed+1][1] - (arry[needed][1]) + 1) );
}
}
else {
// if (n == 1) {
// System.out.println(1);
// }
// else {
// if (arrx[needed+1][0] != arrx[needed][0] || arrx[needed-1][0] != arrx[needed][0] ||
// arry[needed+1][1] != arry[needed][1] || arry[needed-1][1] != arry[needed][1]) {
// System.out.println((arrx[needed+1][0]-1 - (arrx[needed-1][0] + 1) + 1) * (arry[needed+1][1]-1 - (arry[needed-1][1]+1) + 1));
// }
// else {
// System.out.println((arrx[needed+1][0] - (arrx[needed-1][0] ) + 1) * (arry[needed+1][1] - (arry[needed-1][1]) + 1));
// }
//
// }
System.out.println(1);
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
bcabec93f80d32d19005ac634e43ccf7
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.util.Collections;
public class div2_703_B implements Runnable
{
public void run()
{
InputReader sc = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-- > 0)
{
int n = sc.nextInt();
long x[] = new long[n];
long y[] = new long[n];
for(int i=0;i<n;i++)
{
x[i]=sc.nextLong();
y[i]=sc.nextLong();
}
sortintarray.sort(x);
sortintarray.sort(y);
if((n&1)==0)
{
System.out.println((x[n/2]-x[n/2-1]+1)*(y[n/2]-y[n/2-1]+1));
}
else
{
System.out.println("1");
}
}
}
static class sortintarray {
public static void sort(long[] arr) {
int n = arr.length, mid, h, s, l, i, j, k;
long[] res = new long[n];
n--;
for (s = 1; s <= n; s <<= 1) {
for (l = 0; l < n; l += (s << 1)) {
h = Math.min(l + (s << 1) - 1, n);
mid = Math.min(l + s - 1, n);
i = l;
j = mid + 1;
k = l;
while (i <= mid && j <= h) res[k++] = (arr[i] <= arr[j] ? arr[i++] : arr[j++]);
while (i <= mid) res[k++] = arr[i++];
while (j <= h) res[k++] = arr[j++];
for (k = l; k <= h; k++) arr[k] = res[k];
}
}
}
}
static class sortchararray {
public static void sort(char[] arr) {
int n = arr.length, mid, h, s, l, i, j, k;
char[] res = new char[n];
n--;
for (s = 1; s <= n; s <<= 1) {
for (l = 0; l < n; l += (s << 1)) {
h = Math.min(l + (s << 1) - 1, n);
mid = Math.min(l + s - 1, n);
i = l;
j = mid + 1;
k = l;
while (i <= mid && j <= h) res[k++] = (arr[i] <= arr[j] ? arr[i++] : arr[j++]);
while (i <= mid) res[k++] = arr[i++];
while (j <= h) res[k++] = arr[j++];
for (k = l; k <= h; k++) arr[k] = res[k];
}
}
}
}
long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
long factorial(long n){
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
boolean isPrime(int n)
{
if (n <= 1){
return false;
}
for (int i = 2; i < n; i++){
if (n % i == 0){
return false;
}
}
return true;
}
long ceil(long a,long b)
{
if(a%b==0)
{
return a/b;
}
else
{
return (a/b)+1;
}
}
int ceil(int a,int b)
{
if(a%b==0)
{
return a/b;
}
else
{
return (a/b)+1;
}
}
public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
public U x;
public V y;
public Pair(U x, V y) {
this.x = x;
this.y = y;
}
public int hashCode() {
return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
}
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Pair<U, V> p = (Pair<U, V>) o;
return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
}
public int compareTo(Pair<U, V> b) {
int cmpU = x.compareTo(b.x);
return cmpU != 0 ? cmpU : y.compareTo(b.y);
}
public String toString() {
return String.format("(%s, %s)", x.toString(), y.toString());
}
}
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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 String nextLine() {
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);
}
}
public static void main(String args[]) throws Exception {
new Thread(null, new div2_703_B(),"Main",1<<27).start();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
1491d1b746ac19afed9a83febda62e52
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Solution {
public static int countMedian(int n, int[] arr) {
if (n % 2 == 1) {
return 1;
} else {
int ceil = n / 2;
return arr[ceil] - arr[ceil - 1] + 1;
}
}
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int T = fs.nextInt();
while (T-- > 0) {
int n = fs.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for (int i = 0; i < n; i++) {
x[i] = fs.nextInt();
y[i] = fs.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
long med1 = countMedian(n, x);
long med2 = countMedian(n, y);
System.out.println(med1 * med2);
}
}
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
b1ed5775f745c175748ae08d4c71657d
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static class DisjointUnionSets {
int[] rank, parent;
int n;
// Constructor
public DisjointUnionSets(int n)
{
rank = new int[n];
parent = new int[n];
this.n = n;
makeSet();
}
// Creates n sets with single item in each
void makeSet()
{
for (int i = 0; i < n; i++) {
// Initially, all elements are in
// their own set.
parent[i] = i;
}
}
// Returns representative of x's set
int find(int x)
{
// Finds the representative of the set
// that x is an element of
if (parent[x] != x) {
// if x is not the parent of itself
// Then x is not the representative of
// his set,
parent[x] = find(parent[x]);
// so we recursively call Find on its parent
// and move i's node directly under the
// representative of this set
}
return parent[x];
}
// Unites the set that includes x and the set
// that includes x
void union(int x, int y)
{
// Find representatives of two sets
int xRoot = find(x), yRoot = find(y);
// Elements are in the same set, no need
// to unite anything.
if (xRoot == yRoot)
return;
// If x's rank is less than y's rank
if (rank[xRoot] < rank[yRoot])
// Then move x under y so that depth
// of tree remains less
parent[xRoot] = yRoot;
// Else if y's rank is less than x's rank
else if (rank[yRoot] < rank[xRoot])
// Then move y under x so that depth of
// tree remains less
parent[yRoot] = xRoot;
else // if ranks are the same
{
// Then move y under x (doesn't matter
// which one goes where)
parent[yRoot] = xRoot;
// And increment the result tree's
// rank by 1
rank[xRoot] = rank[xRoot] + 1;
}
}
}
static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static class HashMultiSet<T> implements Iterable<T>
{ private final HashMap<T,Integer> map;
private int size;
public HashMultiSet(){map=new HashMap<>(); size=0;}
public void clear(){map.clear(); size=0;}
public int size(){return size;}
public int setSize(){return map.size();}
public boolean contains(T a){return map.containsKey(a);}
public boolean isEmpty(){return size==0;}
public Integer get(T a){return map.getOrDefault(a,0);}
public void add(T a, int count)
{
int cur=get(a);map.put(a,cur+count); size+=count;
if(cur+count==0) map.remove(a);
}
public void addOne(T a){add(a,1);}
public void remove(T a, int count){add(a,Math.max(-get(a),-count));}
public void removeOne(T a){remove(a,1);}
public void removeAll(T a){remove(a,Integer.MAX_VALUE-10);}
public Iterator<T> iterator()
{
return new Iterator<>()
{
private final Iterator<T> iter = map.keySet().iterator();
private int count = 0; private T curElement;
public boolean hasNext(){return iter.hasNext()||count>0;}
public T next()
{
if(count==0)
{
curElement=iter.next();
count=get(curElement);
}
count--; return curElement;
}
};
}
}
private static long abs(long x){ if(x < 0) x*=-1l;return x; }
private static int abs(int x){ if(x < 0) x*=-1;return x; }
// public static int get(HashMap<Integer, Deque<Integer> > a, int key ){
// return a.get(key).getLast();
// }
// public static void removeLast (HashMap<Integer,Deque<Integer> > a, int key){
// if(a.containsKey(key)){
// a.get(key).removeLast();
// if(a.get(key).size() == 0) a.remove(key);
// }
// }
// public static void add(HashMap<Integer,Deque<Integer>> a, int key, int val){
// if(a.containsKey(key)){
// a.get(key).addLast(val);
// }else{
// Deque<Integer> b = new LinkedList<>();
// b.addLast(val);
// a.put(key,b);
// }
// }
private static int solve(int a[]){
int n = a.length;
Arrays.sort(a);
return a[n/2] - a[(n-1) /2] +1;
}
public static void main(String[] args) {
MyScanner sc = new MyScanner();
int t = sc.nextInt();
while (t-- != 0){
int n = sc.nextInt();
int ax[] = new int[n];
int ay[] = new int[n];
for(int i =0;i<n;i++){
ax[i] = sc.nextInt();
ay[i] = sc.nextInt();
}
int ansx = solve(ax);
int ans = solve(ay);
System.out.println((long)ansx * (long)ans);
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
c580ab60dad1569b233862d850e60312
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
private static final boolean N_CASE = true;
private void solve() {
int n = sc.nextInt();
List<Integer> x = new ArrayList<>();
List<Integer> y = new ArrayList<>();
for (int i = 0; i < n; i++) {
x.add(sc.nextInt());
y.add(sc.nextInt());
}
Collections.sort(x);
Collections.sort(y);
int nx = x.size();
int ny = y.size();
long dx = x.get(nx / 2) - x.get((nx - 1) / 2) + 1;
long dy = y.get(ny / 2) - y.get((ny - 1) / 2) + 1;
out.println(dx * dy);
}
private void run() {
int T = N_CASE ? sc.nextInt() : 1;
for (int t = 0; t < T; ++t) {
solve();
}
}
private static MyWriter out;
private static MyScanner sc;
private static CommonUtils cu;
public static void main(String[] args) {
out = new MyWriter(new BufferedOutputStream(System.out));
sc = new MyScanner();
new Main().run();
out.close();
}
}
class CommonUtils {
private <T> List<List<T>> createGraph(int n) {
List<List<T>> g = new ArrayList<>();
for (int i = 0; i < n; ++i) {
g.add(new ArrayList<>());
}
return g;
}
private void fill(int[][] a, int value) {
for (int[] row : a) {
fill(row, value);
}
}
private void fill(int[] a, int value) {
Arrays.fill(a, value);
}
}
class MyScanner {
private BufferedReader br;
private StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public int[][] nextIntArray(int n, int m) {
int[][] a = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = nextInt();
}
}
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
public long[][] nextLongArray(int n, int m) {
long[][] a = new long[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = nextLong();
}
}
return a;
}
public List<Integer> nextList(int n) {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
list.add(nextInt());
}
return list;
}
public List<Long> nextLongList(int n) {
List<Long> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
list.add(nextLong());
}
return list;
}
public char[] nextCharArray(int n) {
return next().toCharArray();
}
public char[][] nextCharArray(int n, int m) {
char[][] c = new char[n][m];
for (int i = 0; i < n; i++) {
String s = next();
for (int j = 0; j < m; j++) {
c[i][j] = s.charAt(j);
}
}
return c;
}
}
class MyWriter extends PrintWriter {
public MyWriter(OutputStream outputStream) {
super(outputStream);
}
public void printArray(int[] a) {
for (int i = 0; i < a.length; ++i) {
print(a[i]);
print(i == a.length - 1 ? '\n' : ' ');
}
}
public void printArray(long[] a) {
for (int i = 0; i < a.length; ++i) {
print(a[i]);
print(i == a.length - 1 ? '\n' : ' ');
}
}
public void println(int[] a) {
for (int v : a) {
println(v);
}
}
public void print(List<Integer> list) {
for (int i = 0; i < list.size(); ++i) {
print(list.get(i));
print(i == list.size() - 1 ? '\n' : ' ');
}
}
public void println(List<Integer> list) {
list.forEach(this::println);
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
6d2f4df8840ffbe12fc49b7c80335c4e
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
private static final boolean N_CASE = true;
private void solve() {
int n = sc.nextInt();
int[] x = new int[n];
int[] y = new int[n];
Map<Integer, Integer> cx = new HashMap<>();
Map<Integer, Integer> cy = new HashMap<>();
TreeSet<Integer> sx = new TreeSet<>();
TreeSet<Integer> sy = new TreeSet<>();
for (int i = 0; i < n; i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
sx.add(x[i]);
sy.add(y[i]);
cx.put(x[i], cx.getOrDefault(x[i], 0) + 1);
cy.put(y[i], cy.getOrDefault(y[i], 0) + 1);
}
List<Integer> xl = new ArrayList<>(sx);
List<Integer> yl = new ArrayList<>(sy);
List<Long> dx = new ArrayList<>();
long cnt = 0;
long cur = 0;
for (int i = 0; i < xl.size(); ++i) {
cnt += i == 0 ? 0 : cx.get(xl.get(i-1));
cur += i == 0 ? 0 : (long)(xl.get(i) - xl.get(i-1)) * cnt;
dx.add(cur);
}
cnt = 0;
cur = 0;
for (int i = xl.size() - 1; i >= 0; --i) {
cnt += i == xl.size() - 1 ? 0 : cx.get(xl.get(i+1));
cur += i == xl.size() - 1 ? 0 : (long)(xl.get(i+1) - xl.get(i)) * cnt;
dx.set(i, dx.get(i) + cur);
}
List<Long> dy = new ArrayList<>();
cnt = 0;
cur = 0;
for (int i = 0; i < yl.size(); ++i) {
cnt += i == 0 ? 0 : cy.get(yl.get(i-1));
cur += i == 0 ? 0 : (long)(yl.get(i) - yl.get(i-1)) * cnt;
dy.add(cur);
}
cnt = 0;
cur = 0;
for (int i = yl.size() - 1; i >= 0; --i) {
cnt += i == yl.size() - 1 ? 0 : cy.get(yl.get(i+1));
cur += i == yl.size() - 1 ? 0 : (long)(yl.get(i+1) - yl.get(i)) * cnt;
dy.set(i, dy.get(i) + cur);
}
long minDist = Long.MAX_VALUE;
for (int i = 0; i < dx.size(); ++i) {
for (int j = 0; j < dy.size(); ++j) {
long dist = dx.get(i) + dy.get(j);
if (dist < minDist) {
minDist = dist;
}
}
}
List<int[]> p = new ArrayList<>();
for (int i = 0; i < dx.size(); ++i) {
for (int j = 0; j < dy.size(); j++) {
long dist = dx.get(i) + dy.get(j);
if (dist == minDist) {
p.add(new int[]{xl.get(i), yl.get(j)});
}
}
}
if (p.size() == 1) {
out.println(1);
} else {
long nx = p.get(p.size() - 1)[0] - p.get(0)[0] + 1;
long ny = p.get(p.size() - 1)[1] - p.get(0)[1] + 1;
out.println(nx * ny);
}
}
private void run() {
int T = N_CASE ? sc.nextInt() : 1;
for (int t = 0; t < T; ++t) {
solve();
}
}
private static MyWriter out;
private static MyScanner sc;
private static CommonUtils cu;
public static void main(String[] args) {
out = new MyWriter(new BufferedOutputStream(System.out));
sc = new MyScanner();
new Main().run();
out.close();
}
}
class CommonUtils {
private <T> List<List<T>> createGraph(int n) {
List<List<T>> g = new ArrayList<>();
for (int i = 0; i < n; ++i) {
g.add(new ArrayList<>());
}
return g;
}
private void fill(int[][] a, int value) {
for (int[] row : a) {
fill(row, value);
}
}
private void fill(int[] a, int value) {
Arrays.fill(a, value);
}
}
class MyScanner {
private BufferedReader br;
private StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public int[][] nextIntArray(int n, int m) {
int[][] a = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = nextInt();
}
}
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
public long[][] nextLongArray(int n, int m) {
long[][] a = new long[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = nextLong();
}
}
return a;
}
public List<Integer> nextList(int n) {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
list.add(nextInt());
}
return list;
}
public List<Long> nextLongList(int n) {
List<Long> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
list.add(nextLong());
}
return list;
}
public char[] nextCharArray(int n) {
return next().toCharArray();
}
public char[][] nextCharArray(int n, int m) {
char[][] c = new char[n][m];
for (int i = 0; i < n; i++) {
String s = next();
for (int j = 0; j < m; j++) {
c[i][j] = s.charAt(j);
}
}
return c;
}
}
class MyWriter extends PrintWriter {
public MyWriter(OutputStream outputStream) {
super(outputStream);
}
public void printArray(int[] a) {
for (int i = 0; i < a.length; ++i) {
print(a[i]);
print(i == a.length - 1 ? '\n' : ' ');
}
}
public void printArray(long[] a) {
for (int i = 0; i < a.length; ++i) {
print(a[i]);
print(i == a.length - 1 ? '\n' : ' ');
}
}
public void println(int[] a) {
for (int v : a) {
println(v);
}
}
public void print(List<Integer> list) {
for (int i = 0; i < list.size(); ++i) {
print(list.get(i));
print(i == list.size() - 1 ? '\n' : ' ');
}
}
public void println(List<Integer> list) {
list.forEach(this::println);
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
7e5c1aa28d9a564a3d02e7b9ae40c190
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
public class Cf {
public static void main(String [] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int j=1;j<=t;j++){
int n=sc.nextInt();
ArrayList<Integer> a=new ArrayList<Integer>();
ArrayList<Integer> b=new ArrayList<Integer>();
for(int i=0;i<n;i++){
int c1=sc.nextInt();
int c2=sc.nextInt();
a.add(c1);b.add(c2);
}
Collections.sort(a);
Collections.sort(b);
int x=a.size();int y=b.size();
long ans=1; if(x%2==0){ans*=(a.get(x/2)-a.get(x/2-1)+1);}
if(y%2==0){ans*=(b.get(y/2)-b.get(y/2-1)+1);}
System.out.println(ans);
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
830f46827c406f12c0873944acfeab71
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
@SuppressWarnings("unchecked")
public class EasternExhibition implements Runnable {
void solve() throws IOException {
int t = read.intNext();
while( t--> 0){
int n = read.intNext();
int[] x = iArr(n);
int[] y = iArr(n);
for(int i =0; i < n; i++ ){
x[i] = read.intNext();
y[i] = read.intNext();
}
shuffle(x);shuffle(y);
Arrays.sort(x);
Arrays.sort(y);
if( (n & 1) == 1){
//If it is odd
println("1");
}else{
int mid = (n - 1)/2;
long ans = (long)( x[mid + 1] - x[mid] + 1L) * (long)( y[mid + 1] - y[mid] + 1L);
println(ans);
}
}
}
/************************************************************************************************************************************************/
public static void main(String[] args) throws IOException {
new Thread(null, new EasternExhibition(), "1").start();
}
static PrintWriter out = new PrintWriter(System.out);
static Reader read = new Reader();
static StringBuilder sbr = new StringBuilder();
static int mod = (int) 1e9 + 7;
static int dmax = Integer.MAX_VALUE;
static long lmax = Long.MAX_VALUE;
static int dmin = Integer.MIN_VALUE;
static long lmin = Long.MIN_VALUE;
@Override
public void run() {
try {
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
static class Reader {
private byte[] buf = new byte[1024];
private int index;
private InputStream in;
private int total;
public Reader() {
in = System.in;
}
public int scan() throws IOException {
if (total < 0)
throw new InputMismatchException();
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0)
return -1;
}
return buf[index++];
}
public int intNext() throws IOException {
int integer = 0;
int n = scan();
while (isWhiteSpace(n))
n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = scan();
} else throw new InputMismatchException();
}
return neg * integer;
}
public double doubleNext() throws IOException {
double doub = 0;
int n = scan();
while (isWhiteSpace(n))
n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n) && n != '.') {
if (n >= '0' && n <= '9') {
doub *= 10;
doub += n - '0';
n = scan();
} else throw new InputMismatchException();
}
if (n == '.') {
n = scan();
double temp = 1;
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
temp /= 10;
doub += (n - '0') * temp;
n = scan();
} else throw new InputMismatchException();
}
}
return doub * neg;
}
public String read() throws IOException {
StringBuilder sb = new StringBuilder();
int n = scan();
while (isWhiteSpace(n))
n = scan();
while (!isWhiteSpace(n)) {
sb.append((char) n);
n = scan();
}
return sb.toString();
}
private boolean isWhiteSpace(int n) {
if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
return true;
return false;
}
}
static void shuffle(int[] aa) {
int n = aa.length;
Random rand = new Random();
for (int i = 1; i < n; i++) {
int j = rand.nextInt(i + 1);
int tmp = aa[i];
aa[i] = aa[j];
aa[j] = tmp;
}
}
static void shuffle(int[][] aa) {
int n = aa.length;
Random rand = new Random();
for (int i = 1; i < n; i++) {
int j = rand.nextInt(i + 1);
int first = aa[i][0];
int second = aa[i][1];
aa[i][0] = aa[j][0];
aa[i][1] = aa[j][1];
aa[j][0] = first;
aa[j][1] = second;
}
}
static final class Comparators {
public static final Comparator<int[]> pairIntArr =
(x, y) -> x[0] == y[0] ? compare(x[1], y[1]) : compare(x[0], y[0]);
private static final int compare(final int x, final int y) {
return Integer.compare(x, y);
}
}
static void print(Object object) {
out.print(object);
}
static void println(Object object) {
out.println(object);
}
static int[] iArr(int len) {
return new int[len];
}
static long[] lArr(int len) {
return new long[len];
}
static long min(long a, long b) {
return Math.min(a, b);
}
static int min(int a, int b) {
return Math.min(a, b);
}
static long max(Long a, Long b) {
return Math.max(a, b);
}
static int max(int a, int b) {
return Math.max(a, b);
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
f73d916af748c3a285045ffa6cfcf272
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;
/* ******************** _/\_Siya pati Ram Chandra ki Jai_/\_ ****************** */
public class JaiShreeRam{
static Scanner in=new Scanner();
public static void main(String[] args) throws Exception{
int t=in.readInt();
while(t-->0) {
int n=in.readInt();
long a[]=new long[n];
long b[]=new long[n];
for(int i=0;i<n;i++) {
a[i]=in.readLong();
b[i]=in.readLong();
}
Arrays.sort(a);
Arrays.sort(b);
if(n%2==1) {
System.out.println(1);
}
else {
System.out.println((a[n/2]-a[n/2-1]+1)*(b[n/2]-b[n/2-1]+1));
}
}
}
static int[] nextIntArray(int n){
int[] arr= new int[n];
int i=0;
while(i<n){
arr[i++]=in.readInt();
}
return arr;
}
static int[] nextIntArray1(int n){
int[] arr= new int[n+1];
int i=1;
while(i<=n){
arr[i++]=in.readInt();
}
return arr;
}
static long gcd(long a, long b) {
if (b==0) return a;
return gcd(b, a%b);
}
static void ruffleSort(long[] a) {
int n=a.length;
Random r=new Random();
for (int i=0; i<a.length; i++) {
int oi=r.nextInt(n); long temp=a[i];
a[i]=a[oi];
a[oi]=temp;
}
Arrays.sort(a);
}
static class Scanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String readString() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
double readDouble() {
return Double.parseDouble(readString());
}
int readInt() {
return Integer.parseInt(readString());
}
long readLong() {
return Long.parseLong(readString());
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
130ac1773eaca1a109b39577739610bb
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class abc
{
public static long solve(ArrayList<Integer>ar)
{
Collections.sort(ar);
return ar.get((ar.size()+2)/2-1)-ar.get((ar.size()+1)/2-1)+1;
}
public static void main(String ard[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
StringBuilder sb=new StringBuilder();
while(t-->0)
{
int n=Integer.parseInt(br.readLine());
ArrayList<Integer>ar=new ArrayList<Integer>();
ArrayList<Integer>br1=new ArrayList<Integer>();
for(int i=0;i<n;i++)
{
String s[]=br.readLine().split(" ");
ar.add(Integer.parseInt(s[0]));
br1.add(Integer.parseInt(s[1]));
}
System.out.println(solve(ar)*solve(br1));
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
3781a73105f948878b40de1d728853aa
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Solver {
public static void main(String[] args) {
FastReader in = new FastReader();
int t = in.nextInt();
while (t-- > 0) {
solve(in);
}
}
public static void solve(FastReader in) {
int n = in.nextInt();
long[] x = new long[n], y = new long[n];
for (int i = 0; i < n; i++) {
x[i] = in.nextLong();
y[i] = in.nextLong();
}
Arrays.sort(x);
Arrays.sort(y);
System.out.println((n & 1) == 0 ? (x[n / 2] - x[n / 2 - 1] + 1) * (y[n / 2] - y[n / 2 - 1] + 1) : 1);
}
public static class Pair implements Comparable {
int x;
int y;
public Pair() {
x = 0;
y = 0;
}
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Object obj) {
if (obj instanceof Pair) {
Pair p = (Pair) obj;
int c1 = Integer.compare(this.x, p.x);
if (c1 == 0) {
int c2 = Integer.compare(this.y, p.y);
return c2;
}
return c1;
}
return -1;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Pair) {
Pair p = (Pair) obj;
return p.x == x && p.y == y;
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
@Override
public String toString() {
return ("(" + x + "," + y + ")");
}
}
public static class FastReader {
BufferedReader br;
StringTokenizer st;
private 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 class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE)
innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000)
return 10;
if (l >= 100000000)
return 9;
if (l >= 10000000)
return 8;
if (l >= 1000000)
return 7;
if (l >= 100000)
return 6;
if (l >= 10000)
return 5;
if (l >= 1000)
return 4;
if (l >= 100)
return 3;
if (l >= 10)
return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L)
return 19;
if (l >= 100000000000000000L)
return 18;
if (l >= 10000000000000000L)
return 17;
if (l >= 1000000000000000L)
return 16;
if (l >= 100000000000000L)
return 15;
if (l >= 10000000000000L)
return 14;
if (l >= 1000000000000L)
return 13;
if (l >= 100000000000L)
return 12;
if (l >= 10000000000L)
return 11;
if (l >= 1000000000L)
return 10;
if (l >= 100000000L)
return 9;
if (l >= 10000000L)
return 8;
if (l >= 1000000L)
return 7;
if (l >= 100000L)
return 6;
if (l >= 10000L)
return 5;
if (l >= 1000L)
return 4;
if (l >= 100L)
return 3;
if (l >= 10L)
return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
// if(x < 0){ x = 0; }
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map)
write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
8888731ed2002dd2698a784b381d8e1b
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import static java.lang.System.in;
import static java.lang.System.out;
public class Main {
public static void main(String[] args){
FastReader fr=new FastReader();
int tc=fr.nextInt();
while(tc-->0){
int n=fr.nextInt();
long x[]=new long[n];
long y[]=new long[n];
for(int i=0;i<n;i++){
x[i]=fr.nextLong();
y[i]=fr.nextLong();
}
Arrays.sort(x);
Arrays.sort(y);
if(n%2==0){
long a=x[n/2]-x[(n/2)-1]+1;
long b=y[n/2]-y[(n/2)-1]+1;
out.println(a*b);
}else{
out.println(1);
}
}
}
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(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());
}
byte nextByte(){
return Byte.parseByte(next());
}
Float nextFloat(){
return Float.parseFloat(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
short nextShort(){
return Short.parseShort(next());
}
Boolean nextbol(){
return Boolean.parseBoolean(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch (IOException e){
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
3ff53564fa88141a7635169eb965e4d8
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.Arrays;
public class codeforces {
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t--!=0) {
int n=Integer.parseInt(br.readLine());
if(n%2==1) {
for(int i=0;i<n;i++) {
String s[]=br.readLine().split(" ");
}
System.out.println("1");
}
else {
long x[]=new long[n];
long y[]=new long[n];
for(int i=0;i<n;i++) {
String s[]=br.readLine().split(" ");
x[i]=Long.parseLong(s[0]);
y[i]=Long.parseLong(s[1]);
}
Arrays.sort(x);
Arrays.sort(y);
long ans=(x[n/2]-x[(n/2)-1]+1)*(y[n/2]-y[(n/2)-1]+1);
System.out.println(Math.abs(ans));
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
293333d91546a0f952b1df49dff065c9
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
//Implemented By Aman Kotiyal Date:-17-Feb-2021 Time:-5:50:00 pm
import java.io.*;
import java.util.*;
public class ques3
{
public static void main(String[] args)throws Exception{ new ques3().run();}
long mod=1000000000+7;
void solve() throws Exception
{
for(int ii=ni();ii>0;ii--)
{
int n=ni();
int a[][]=new int[n][2];
for (int i = 0; i < n; i++) {
a[i][0]=ni();
a[i][1]=ni();
}
Arrays.sort(a,new Comparator<int []>() {
@Override
public int compare(int[] o1, int[] o2) {
return o1[0]-o2[0];
}
});
long ans=0;
if(n%2==0)
{
long m1x=a[(n/2)-1][0];
long m2x=a[(n/2)][0];
Arrays.sort(a,new Comparator<int []>() {
@Override
public int compare(int[] o1, int[] o2) {
return o1[1]-o2[1];
}
});
long m1y=a[(n/2)-1][1];
long m2y=a[(n/2)][1];
ans+=(m2x-m1x+1l)*(m2y-m1y+1);
}
else
{
long mx=a[(n/2)][0];
Arrays.sort(a,new Comparator<int []>() {
@Override
public int compare(int[] o1, int[] o2) {
return o1[1]-o2[1];
}
});
long my=a[(n/2)][1];
ans=1;
}
out.println(ans);
}
}
/*FAST INPUT OUTPUT & METHODS BELOW*/
private byte[] buf=new byte[1024];
private int index;
private InputStream in;
private int total;
private SpaceCharFilter filter;
PrintWriter out;
int min(int... ar){int min=Integer.MAX_VALUE;for(int i:ar)min=Math.min(min, i);return min;}
long min(long... ar){long min=Long.MAX_VALUE;for(long i:ar)min=Math.min(min, i);return min;}
int max(int... ar) {int max=Integer.MIN_VALUE;for(int i:ar)max=Math.max(max, i);return max;}
long max(long... ar) {long max=Long.MIN_VALUE;for(long i:ar)max=Math.max(max, i);return max;}
void reverse(int a[]){for(int i=0;i<a.length>>1;i++){int tem=a[i];a[i]=a[a.length-1-i];a[a.length-1-i]=tem;}}
void reverse(long a[]){for(int i=0;i<a.length>>1;i++){long tem=a[i];a[i]=a[a.length-1-i];a[a.length-1-i]=tem;}}
String reverse(String s){StringBuilder sb=new StringBuilder(s);sb.reverse();return sb.toString();}
void shuffle(int a[]) {
ArrayList<Integer> al = new ArrayList<>();
for(int i=0;i<a.length;i++)
al.add(a[i]);
Collections.sort(al);
for(int i=0;i<a.length;i++)
a[i]=al.get(i);
}
long lcm(long a,long b)
{
return (a*b)/(gcd(a,b));
}
int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}
long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}
/* for (1/a)%mod = ( a^(mod-2) )%mod ----> use expo to calc -->(a^(mod-2)) */
long expo(long p,long q) /* (p^q)%mod */
{
long z = 1;
while (q>0) {
if (q%2 == 1) {
z = (z * p)%mod;
}
p = (p*p)%mod;
q >>= 1;
}
return z;
}
void run()throws Exception
{
in=System.in; out = new PrintWriter(System.out);
solve();
out.flush();
}
private int scan()throws IOException
{
if(total<0)
throw new InputMismatchException();
if(index>=total)
{
index=0;
total=in.read(buf);
if(total<=0)
return -1;
}
return buf[index++];
}
private int ni() throws IOException
{
int c = scan();
while (isSpaceChar(c))
c = scan();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = scan();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = scan();
} while (!isSpaceChar(c));
return res * sgn;
}
private long nl() throws IOException
{
long num = 0;
int b;
boolean minus = false;
while ((b = scan()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = scan();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = scan();
}
}
private double nd() throws IOException{
return Double.parseDouble(ns());
}
private String ns() throws IOException {
int c = scan();
while (isSpaceChar(c))
c = scan();
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c))
res.appendCodePoint(c);
c = scan();
} while (!isSpaceChar(c));
return res.toString();
}
private String nss() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
return br.readLine();
}
private char nc() throws IOException
{
int c = scan();
while (isSpaceChar(c))
c = scan();
return (char) c;
}
private boolean isWhiteSpace(int n)
{
if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
return true;
return false;
}
private boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhiteSpace(c);
}
private interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
3d07a771e54daf069054d9d2d2ccf6bd
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main implements Runnable {
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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 String nextLine() {
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);
}
}
public static void main(String args[]) throws Exception {
new Thread(null, new Main(), "Main", 1 << 27).start();
}
static class Pair {
int f;
int s;
int p;
PrintWriter w;
// int t;
Pair(int f, int s) {
// Pair(int f,int s, PrintWriter w){
this.f = f;
this.s = s;
// this.p = p;
// this.w = w;
// this.t = t;
}
public static Comparator<Pair> wc = new Comparator<Pair>() {
public int compare(Pair e1, Pair e2) {
// 1 for swap
if (Math.abs(e1.f) - Math.abs(e2.f) != 0) {
// e1.w.println("**"+e1.f+" "+e2.f);
return (Math.abs(e1.f) - Math.abs(e2.f));
} else {
// e1.w.println("##"+e1.f+" "+e2.f);
return (Math.abs(e1.s) - Math.abs(e2.s));
}
}
};
}
public static ArrayList<Integer> sieve(int N) {
int i, j, flag;
ArrayList<Integer> p = new ArrayList<Integer>();
for (i = 1; i < N; i++) {
if (i == 1 || i == 0)
continue;
flag = 1;
for (j = 2; j <= i / 2; ++j) {
if (i % j == 0) {
flag = 0;
break;
}
}
if (flag == 1) {
p.add(i);
}
}
return p;
}
public static long gcd(long a, long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
//// recursive dfs
public static int dfs(int s, ArrayList<Integer>[] g, long[] dist, boolean[] v, PrintWriter w, int p) {
v[s] = true;
int ans = 1;
// int n = dist.length - 1;
int t = g[s].size();
// int max = 1;
for (int i = 0; i < t; i++) {
int x = g[s].get(i);
if (!v[x]) {
// dist[x] = dist[s] + 1;
ans = Math.min(ans, dfs(x, g, dist, v, w, s));
} else if (x != p) {
// w.println("* " + s + " " + x + " " + p);
ans = 0;
}
}
// max = Math.max(max,(n-p));
return ans;
}
//// iterative BFS
public static int bfs(int s, ArrayList<Integer>[] g, long[] dist, boolean[] b, PrintWriter w, int p) {
b[s] = true;
int siz = 1;
// dist--;
Queue<Integer> q = new LinkedList<>();
q.add(s);
while (q.size() != 0) {
int i = q.poll();
Iterator<Integer> it = g[i].listIterator();
int z = 0;
while (it.hasNext()) {
z = it.next();
if (!b[z]) {
b[z] = true;
// dist--;
dist[z] = dist[i] + 1;
// siz++;
q.add(z);
} else if (z != p) {
siz = 0;
}
}
}
return siz;
}
public static int lower(int key, int[] a) {
int l = 0;
int r = a.length - 1;
int res = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (a[mid] <= key) {
l = mid + 1;
res = mid + 1;
} else {
r = mid - 1;
}
}
return res;
}
public 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;
if (y % 2 == 0)
return p;
else
return (x * p) % m;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// code here
int[] parent;
int[] dist;
int[] height;
boolean[] vis;
ArrayList<Integer>[] g;
int[] c;
public void run() {
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int defaultValue = 0;
int mod = 1000000007;
int oo = (int) 1e9;
int test = 1;
test = sc.nextInt();
while (test-- > 0) {
int n = sc.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for (int i = 0; i < n; i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
if (n % 2 == 0) {
long xx = x[n / 2] - x[n / 2 - 1] + 1;
long yy = y[n / 2] - y[n / 2 - 1] + 1;
w.println(xx * yy);
} else {
w.println(1);
}
}
w.flush();
w.close();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
8acc16dc9e75c3361ea4d7ff2ef856ec
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class B{
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(in, out);
out.close();
}
// main solver
static class Task{
static int MOD= 1000000007;
int n;
public void solve(InputReader in, PrintWriter out) {
int t= in.nextInt();
while(t-->0){
n=in.nextInt();
List<Integer> x= new ArrayList<>();
List<Integer> y= new ArrayList<>();
for(int i=0;i<n;i++){
x.add(in.nextInt()); y.add(in.nextInt());
}
Collections.sort(x);
Collections.sort(y);
out.println((long)check1D(x)*check1D(y));
}
}
public int check1D(List<Integer> x){
return x.get(n/2)-x.get((n-1)/2)+1;
}
}
static class Pair implements Comparable<Pair>{
public long val;
public int idx;
public Pair(long val, int idx){
this.val=val;
this.idx=idx;
}
@Override
public int compareTo(Pair o) {
if(this.val!=o.val) return (int)(this.val-o.val);
else return this.idx-o.idx;
}
}
// fast input reader class;
static class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
if (line == null) {
return null;
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public double nextDouble(){
return Double.parseDouble(nextToken());
}
public long nextLong(){
return Long.parseLong(nextToken());
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
3ebb024d0f559060469d7ccca3cc3e1b
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.Arrays;
import java.util.Scanner;
public class EasternExibition {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for (int i = 0; i < n; i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
if (n % 2 == 1) System.out.println(1);
else System.out.println((long)(x[n/2]-x[n/2-1]+1)*(long)(y[n/2]-y[n/2-1]+1));
}
sc.close();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
5667f30d3f0d484b731cb5aa6378e195
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class sol{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
long t=scan.nextLong();
while(t-->0){
int n=scan.nextInt();
long[] x=new long[n];
long[] y=new long[n];
for(int i=0;i<n;i++){
x[i]=scan.nextInt();
y[i]=scan.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
long xm=x[n/2]-x[(n-1)/2]+1;
long ym=y[n/2]-y[(n-1)/2]+1;
System.out.println(xm*ym);
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
5548713c1280072faa8bba86735b8b55
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
// package eround101;
import java.util.*;
import java.io.*;
import java.lang.*;
import java.util.StringTokenizer;
public class C101 {
static HritikScanner sc = new HritikScanner();
static PrintWriter pw = new PrintWriter(System.out, true);
final static int MOD = (int) (1e9 + 7);
static int[] count = new int[1000001];
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) {
int t = sc.nextInt();
while (t-- > 0) {
solve();
}
}
static void solve() {
int n = ni();
int[] x = new int[n];
int[] y = new int[n];
for(int i = 0; i < n; i++)
{
x[i] = ni();
y[i] = ni();
}
Arrays.sort(x);
Arrays.sort(y);
int l = (n-1)/2;
int r = n/2;
int xmin= x[l],xmax = x[r], ymin = y[l], ymax = y[r];
pl((long)(xmax - xmin +1)*(ymax - ymin + 1));
}
/////////////////////////////////////////////////////////////////////////////////
static int[] nextIntArray(int n) {
int[] arr = new int[n];
int i = 0;
while (i < n) {
arr[i++] = ni();
}
return arr;
}
static int[] nextIntArray1(int n) {
int[] arr = new int[n + 1];
int i = 1;
while (i <= n) {
arr[i++] = ni();
}
return arr;
}
/////////////////////////////////////////////////////////////////////////////////
static int ni() {
return sc.nextInt();
}
static long nl() {
return sc.nextLong();
}
static double nd() {
return sc.nextDouble();
}
/////////////////////////////////////////////////////////////////////////////////
static void pl() {
pw.println();
}
static void p(Object o) {
pw.print(o + " ");
}
static void pl(Object o) {
pw.println(o);
}
static void psb(StringBuilder sb) {
pw.print(sb);
}
static void pa(Object arr[]) {
for (Object o : arr) {
p(o);
}
pl();
}
static void pa(int arr[]) {
for (int o : arr) {
p(o);
}
pl();
}
static void pa(long arr[]) {
for (long o : arr) {
p(o);
}
pl();
}
static void pa(double arr[]) {
for (double o : arr) {
p(o);
}
pl();
}
static void pa(char arr[]) {
for (char o : arr) {
p(o);
}
pl();
}
static void pa(List list) {
for (Object o : list) {
p(o);
}
pl();
}
static void pa(Object[][] arr) {
for (int i = 0; i < arr.length; ++i) {
for (Object o : arr[i]) {
p(o);
}
pl();
}
}
static void pa(int[][] arr) {
for (int i = 0; i < arr.length; ++i) {
for (int o : arr[i]) {
p(o);
}
pl();
}
}
static void pa(long[][] arr) {
for (int i = 0; i < arr.length; ++i) {
for (long o : arr[i]) {
p(o);
}
pl();
}
}
static void pa(char[][] arr) {
for (int i = 0; i < arr.length; ++i) {
for (char o : arr[i]) {
p(o);
}
pl();
}
}
static void pa(double[][] arr) {
for (int i = 0; i < arr.length; ++i) {
for (double o : arr[i]) {
p(o);
}
pl();
}
}
/////////////////////////////////////////////////////////////////////////////////
static void print(Object s) {
System.out.println(s);
}
/////////////////////////////////////////////////////////////////////////////////
//-----------HritikScanner class for faster input----------//
static class HritikScanner {
BufferedReader br;
StringTokenizer st;
public HritikScanner() {
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 class Pair implements Comparable<Pair> {
int x, y;
Pair(int index, int token) {
this.x = index;
this.y = token;
}
public int get1() {
return x;
}
public int get2() {
return y;
}
public int compareTo(Pair A) {
return this.y - A.y;
}
}
//////////////////////////////////////////////////////////////////
// Function to return gcd of a and b time complexity O(log(a+b))
static int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
//////////////////////////////////////////////////////////////////
static boolean isPrime(long n) {
// Corner cases
if (n <= 1) {
return false;
}
if (n <= 3) {
return true;
}
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0) {
return false;
}
for (long i = 5; i * i <= n; i = i + 6) {
if (n % i == 0 || n % (i + 2) == 0) {
return false;
}
}
return true;
}
//////////////////////////////////////////////////////////////////
static boolean isPowerOfTwo(long n) {
if (n == 0) {
return false;
}
return (long) (Math.ceil((Math.log(n) / Math.log(2))))
== (long) (Math.floor(((Math.log(n) / Math.log(2)))));
}
public static long getFact(int n) {
long ans = 1;
while (n > 0) {
ans *= n;
ans %= MOD;
n--;
}
return ans;
}
public static long pow(long n, int pow) {
if (pow == 0) {
return 1;
}
long temp = pow(n, pow / 2) % MOD;
temp *= temp;
temp %= MOD;
if (pow % 2 == 1) {
temp *= n;
}
temp %= MOD;
return temp;
}
public static long nCr(int n, int r) {
long ans = 1;
int temp = n - r;
while (n > temp) {
ans *= n;
ans %= MOD;
n--;
}
ans *= pow(getFact(r) % MOD, MOD - 2) % MOD;
ans %= MOD;
return ans;
}
//////////////////////////////////////////////////////////////////
// method returns Nth power of A
static double nthRoot(int A, int N) {
// intially guessing a random number between
// 0 and 9
double xPre = Math.random() % 10;
// smaller eps, denotes more accuracy
double eps = 0.001;
// initializing difference between two
// roots by INT_MAX
double delX = 2147483647;
// xK denotes current value of x
double xK = 0.0;
// loop untill we reach desired accuracy
while (delX > eps) {
// calculating current value from previous
// value by newton's method
xK = ((N - 1.0) * xPre
+ (double) A / Math.pow(xPre, N - 1)) / (double) N;
delX = Math.abs(xK - xPre);
xPre = xK;
}
return xK;
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
7fd9f69f741c6c495ca2d153379a0bf0
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
//package credit;
import java.io.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main{
static boolean v[];
static int ans[];
int size[];
static int count=0;
static int dsu=0;
static int c=0;
static int e9=1000000007;
int min=Integer.MAX_VALUE;
int max=Integer.MIN_VALUE;
long max1=Long.MIN_VALUE;
long min1=Long.MAX_VALUE;
boolean aBoolean=true;
boolean y=false;
long m=0;
static boolean t1=false;
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;
}
}
int parent[];
int rank[];
int n=0;
ArrayList<ArrayList<Integer>> arrayLists;
boolean v1[];
static boolean t2=false;
boolean r=false;
int fib[];
int fib1[];
int ind[];
int min3=Integer.MAX_VALUE;
public static void main(String[] args) throws IOException {
Main g = new Main();
g.go();
}
public void go() throws IOException {
FastReader scanner = new FastReader();
// Scanner scanner = new Scanner(System.in);
// BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
// String s;
PrintWriter printWriter = new PrintWriter(System.out);
int t =scanner.nextInt();
for (int i = 0; i < t; i++) {
int n=scanner.nextInt();
long x[]=new long[n];
long y[]=new long[n];
for (int j = 0; j < n; j++) {
x[j]=scanner.nextInt();
y[j]=scanner.nextInt();
}
//0 1 2 3 4 5 6 7
//0 1 2 3 6 8 9 10
if(n%2!=0){
printWriter.println(1);
}else{
Arrays.sort(x);
Arrays.sort(y);
printWriter.println(((x[n/2]-x[n/2-1])+1)*((y[n/2]-y[n/2-1])+1));
}
}
printWriter.flush();
}
static final int mod=1_000_000_007;
public long mul(long a, long b) {
return a*b;
}
public long fact(int x) {
long ans=1;
for (int i=2; i<=x; i++) ans=mul(ans, i);
return ans;
}
public long fastPow(long base, long exp) {
if (exp==0) return 1;
long half=fastPow(base, exp/2);
if (exp%2==0) return mul(half, half);
return mul(half, mul(half, base));
}
public long modInv(long x) {
return fastPow(x, mod-2);
}
public long nCk(int n, int k) {
return mul(fact(n), mul(modInv(fact(k)), modInv(fact(n-k))));
}
// public void sieve(int n){
// fib=new int[n+1];
// fib[1]=-1;
// fib[0]=-1;
// for (int i =2; i*i<=n; i++) {
// if(fib[i]==0)
// for (int j =i*i; j <=n; j+=i){
// fib[j]=-1;
//// System.out.println("l");
// }
// }
// }
public void parent(int n){
for (int i = 0; i < n; i++) {
parent[i]=i;
rank[i]=1;
size[i]=1;
}
}
public void union(int i,int j){
int root1=find(i);
int root2=find(j);
// if(root1 != root2) {
// parent[root2] = root1;
//// sz[a] += sz[b];
// }
if(root1==root2){
return;
}
if(rank[root1]>rank[root2]){
parent[root2]=root1;
size[root1]+=size[root2];
}
else if(rank[root1]<rank[root2]){
parent[root1]=root2;
size[root2]+=size[root1];
}
else{
parent[root2]=root1;
rank[root1]+=1;
size[root1]+=size[root2];
}
}
public int find(int p){
if(parent[p]!=p){
parent[p]=find(parent[p]);
}
return parent[p];
// if(parent[p]==-1){
// return -1;
// }
// else if(parent[p]==p){
// return p;
// }
// else {
// parent[p]=find(parent[p]);
// return parent[p];
// }
}
public double dist(double x1,double y1,double x2,double y2){
double e=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
double e1=Math.sqrt(e);
return e1;
}
public void make(int p){
parent[p]=p;
rank[p]=1;
}
Random rand = new Random();
public void sort(int[] a, int n) {
for (int i = 0; i < n; i++) {
int j = rand.nextInt(i + 1);
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
Arrays.sort(a, 0, n);
}
public long gcd(long a,long b){
if(b==0){
return a;
}
return gcd(b,a%b);
}
public void dfs(ArrayList<Integer> arrayLists1){
for (int i = 0; i < arrayLists1.size(); i++) {
if(v1[arrayLists1.get(i)]==false){
System.out.println(arrayLists1.get(i));
v1[arrayLists1.get(i)]=true;
count++;
dfs(arrayLists.get(arrayLists1.get(i)));
}
}
}
private void dfs2(ArrayList<Integer>[]arrayList,int j,int count){
ans[j]=count;
for(int i:arrayList[j]){
if(ans[i]==-1){
dfs2(arrayList,i,count);
}
}
}
private void dfs3(ArrayList<Integer>[] arrayList, int j) {
v[j]=true;
count++;
for(int i:arrayList[j]){
if(v[i]==false) {
dfs3(arrayList, i);
}
}
}
public double fact(double h){
double sum=1;
while(h>=1){
sum=(sum%e9)*(h%e9);
h--;
}
return sum%e9;
}
public long primef(double r){
long c=0;
long ans=1;
while(r%2==0){
c++;
r=r/2;
}
if(c>0){
ans*=2;
}
c=0;
// System.out.println(ans+" "+r);
for (int i = 3; i <=Math.sqrt(r) ;i+=2) {
while(r%i==0){
// System.out.println(i);
c++;
r=r/i;
}
if(c>0){
ans*=i;
}
c=0;
}
if(r>2){
ans*=r;
}
return ans;
}
public long divisor(double r){
long c=0;
for (int i = 1; i <=Math.sqrt(r); i++) {
if(r%i==0){
if(r/i==i){
c++;
}
else{
c+=2;
}
}
}
return c;
}
}
class Pair{
int x;
int y;
double z;
public Pair(int x,int y){
this.x=x;
this.y=y;
}
@Override
public int hashCode() {
int hash =37;
return this.x * hash + this.y;
}
@Override
public boolean equals(Object o1){
if(o1==null||o1.getClass()!=this.getClass()){
return false;
}
Pair o=(Pair)o1;
if(o.x==this.x&&o.y==this.y){
return true;
}
return false;
}
}
class Sorting implements Comparator<Pair> {
public int compare(Pair p1,Pair p2){
// if(p1.x==p2.x){
// return -1*Double.compare(p1.y,p2.y);
// }
// else {
return Double.compare(p1.x, p2.x);
// }
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
e8aa82029e592c8e8d6437585e0ec4ec
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class main {
static FastScanner sc;
static PrintWriter pw;
static void pn(Object o){pw.println(o);}
static void p(Object o){pw.print(o);}
public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
sc = new FastScanner();
pw = new PrintWriter(System.out);
int t = sc.ni();
while(t-->0)
{
int n = sc.ni(),x[] = new int[n],y[] = new int[n];
for(int i=0;i<n;i++)
{
x[i]=sc.ni();y[i]=sc.ni();
}
Arrays.sort(x);
Arrays.sort(y);
if(n%2==0)
{
long X=x[n/2]-x[n/2-1]+1,Y=y[n/2]-y[n/2-1]+1;
pn(X*Y);
}
else pn(1);
}
pw.close();
}
static int[] reverse(int a[]){
for(int i=0;i<a.length/2;i++)
{
int temp = a[i];
a[i] = a[a.length-i-1];
a[a.length-i-1] = temp;
}
return a;
}
// static int solution(int n,int k)
// {
// for(int i=n;i>=1;i--)a.add(i);
// for(int i=1;i<=n;i++)
// {
// x=i;
// if(a.get(i-1)!=x)
// {
// if(x==n+1)
// { x=1;
// b.add(x);
// }
// }
// else
// {
// if(x==n+1)
// { x=1;
// b.add(x++);
// }
// }
// }
// return b.get(k-1);
static int gcd(int a,int b)
{
if(b!=0)return gcd(b,a%b);
else return a;
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in), 32768);
st = null;
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
int[] intArray(int N) {
int[] ret = new int[N];
for (int i = 0; i < N; i++)
ret[i] = ni();
return ret;
}
long nl() {
return Long.parseLong(next());
}
long[] longArray(int N) {
long[] ret = new long[N];
for (int i = 0; i < N; i++)
ret[i] = nl();
return ret;
}
double nd() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
51250cfa9752ba9f18092afd10c020b1
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class EasternExhibition {
static class FastScanner
{
BufferedReader br;
StringTokenizer st;
public FastScanner()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastScanner f=new FastScanner();
int t=f.nextInt();
while(t-->0) {
int n=f.nextInt();
long x[]=new long[n];
long y[]=new long[n];
for(int i=0;i<n;i++) {
x[i]=f.nextLong();
y[i]=f.nextLong();
}
Arrays.sort(x);
Arrays.sort(y);
if(n%2!=0) {
System.out.println(1);
}else {
int xl=(n/2)-1;
int xr=(n/2);
int yl=(n/2)-1;
int yr=(n/2);
long nx=x[xr]-x[xl]+1;
long ny=y[yr]-y[yl]+1;
System.out.println(nx*ny);
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
c07fb37738307497741fa51f1c9b029e
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class EasternExhibition {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int testCase = fs.nextInt();
for (int tc = 0; tc < testCase; tc++) {
int n = fs.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for (int i = 0; i < n; i++) {
x[i] = fs.nextInt();
y[i] = fs.nextInt();
}
ruffleSort(x);
ruffleSort(y);
long xs = (x[n / 2] - x[(n - 1) / 2]) + 1;
long ys = (y[n / 2] - y[(n - 1) / 2]) + 1;
System.out.println(xs * ys);
}
}
static void ruffleSort(int[] a) {
int n = a.length;
Random r = new Random();
for(int i = 0; i < a.length; ++i) {
int oi = r.nextInt(n), t = a[i];
a[i] = a[oi];
a[oi] = t;
}
Arrays.sort(a);
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for(int i : a) l.add(i);
Collections.sort(l);
for(int i = 0; i < a.length; ++i) a[i] = l.get(i);
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while(!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for(int i = 0; i < n; ++i)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
b7d84fc378936484ab75a330435757ef
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = fs.nextInt();
// Scanner sc = new Scanner(System.in);
for (int tt = 1; tt <= t; tt++) {
int n = fs.nextInt();
int count = 0;
long X[] = new long[n];
long Y[] = new long[n];
for (int i = 0; i < n; i++) {
long x = fs.nextLong();
long y = fs.nextLong();
X[i] = x;
Y[i] = y;
}
Arrays.sort(X);
Arrays.sort(Y);
System.out.println(((X[(n) / 2] - X[(n - 1) / 2]) + 1) * ((Y[(n) / 2] - Y[(n - 1) / 2]) + 1));
}
out.close();
}
public static boolean check(int j) {
String s = j + "";
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != '4' && s.charAt(i) != '7') {
return false;
}
}
return true;
}
public static boolean fermit_check(int n) {
if (n < 4) {
return n == 2 || n == 3 ? true : false;
}
for (int i = 0; i < 5; i++) {
long random = (long) (Math.random() * (n));
long a = 2L + random % ((long) n - 3L);
if ((long) Math.pow(a, n - 1) % n != 1)
return false;
}
return true;
}
public static boolean solve(int n, int arr[][]) {
return true;
}
public static void prime_seive(int n, int[] b) {
Arrays.fill(b, 1);
for (int i = 2; i < n; i++) {
if (b[i] == 1) {
for (long j = i * (long) i; j < n; j = j + i)
b[(int) j] = 0;
// p.add((long)i);
}
}
b[0] = b[1] = 0;
}
public static int binarySearch(int arr[], int num) {
if (num < arr[0]) {
return 0;
}
int low = 0;
int high = arr.length - 1;
int index = -1;
while (low <= high) {
int mid = low + (high - low) / 2;
if (arr[mid] <= num) {
if (arr[mid] == num) {
// System.out.println(arr[mid]+" "+mid+" "+index);
index = Math.max(index, mid + 1);
}
low = mid + 1;
}
else {
high = mid - 1;
}
}
if (index == -1) {
index = low;
}
return index;
}
public static int noOfonesBinary(int a) {
int count = 0;
int orig = a;
while (a > 0) {
a = a >> 1 << 1;
if (orig - a == 1)
count++;
orig = a >> 1;
a = orig;
}
return count;
}
public void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static long nCr(int n, int r) {
long result = 1L;
for (int i = 0; i < r; i++) {
result *= (long) (n - i); // n * n-1 * n-2 * .... * n-(r-1)
result /= (long) (i + 1); // r * r-1 * ... * 1
}
return result;
}
int pow(int x, int y) {
// Initialize diff
int res = 1;
while (y > 0) {
// If y is odd,
// multiply
// x with diff
if ((y & 1) == 1)
res = res * x;
// n must be even now
y = y >> 1; // y = y/2
x = x * x; // Change x to x^2
}
return res;
}
public static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
static int gcdCoeff(int a, int b, int arr[])// euclidean gcd + extended euclidean
{
if (b == 0)
return a;
int tmp[] = { 1, 1 };// must be 1,1, because at base step b=0, a=anything, 1.0+ 1.a=a
int diff = gcdCoeff(b, a % b, tmp);
arr[0] = tmp[1];// x=y1
arr[1] = (tmp[0] - (a / b) * tmp[1]);// y=(x1-(a/b)*y1)
return diff;
}
static class Pair {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
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[] readIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
Long[] readLongArray(int n) {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
e8299db5fbb9fb89ad8fc24fbae6859f
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
// Working program with FastReader
import java.io.BufferedReader;
import java.io.CharArrayReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader s = new FastReader();
int t = s.nextInt();
while(t-->0)
{
int n = s.nextInt();
long x[] = new long[n];
long y[] = new long[n];
for(int i=0;i<n;i++)
{
x[i] = s.nextLong();
y[i] = s.nextLong();
}
long res = 0;
Arrays.sort(x);
Arrays.sort(y);
if((n&1)==1)
System.out.println(1);
else
{
res = (x[n/2]-x[n/2-1]+1) * (y[n/2]-y[n/2-1]+1);
System.out.println(res);
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
43beda098540487a0c7516f6f312ab9b
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import javax.swing.event.ListDataEvent;
import javax.swing.plaf.FontUIResource;
import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef {
public static void main(String[] args) throws java.lang.Exception {
out = new PrintWriter(new BufferedOutputStream(System.out));
sc = new FastReader();
int test = sc.nextInt();
for (int t = 0; t < test; t++) {
int n = sc.nextInt();
List<Integer> listA = new ArrayList<>();
List<Integer> listB = new ArrayList<>();
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
listA.add(x);
listB.add(y);
}
out.println(solve(listA) * solve(listB));
}
out.close();
}
private static long solve(List<Integer> list) {
Collections.sort(list);
int n = list.size();
return list.get(n / 2) - list.get((n - 1) / 2) + 1;
}
public static FastReader sc;
public static PrintWriter out;
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
672ec1f92b04d4d74d1abef30e0b98a4
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) throws IOException
{
FastScanner f = new FastScanner();
int t=1;
t=f.nextInt();
PrintWriter out=new PrintWriter(System.out);
int mod=1000000007;
while(t>0) {
t--;
int n=f.nextInt();
int[] x=new int[n];
int[] y=new int[n];
for(int i=0;i<n;i++) {
x[i]=f.nextInt();
y[i]=f.nextInt();
}
sort(x);
sort(y);
if(n==1) {
System.out.println(1);
}
else if(n%2==1) {
System.out.println(1);
}
else {
// System.out.println(x.length+" "+t);
System.out.println((long)(x[(n)/2]-x[(n/2)-1]+1)*(y[(n)/2]-y[(n/2)-1]+1));
}
}
out.close();
}
static void sort(int [] a) {
ArrayList<Integer> q = new ArrayList<>();
for (int i: a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long[] readLongArray(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
b558a3cd3c3735192a50391990d9ce61
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
public class B_Eastern_Exhibition {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int T = fs.nextInt();
outer: while (T-- > 0) {
int n = fs.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for (int i = 0; i < n; i++) {
x[i] = fs.nextInt();
y[i] = fs.nextInt();
}
if (n % 2 != 0) {
System.out.println(1);
continue outer;
}
Arrays.sort(x);
Arrays.sort(y);
n--;
long inX = x[n / 2 + 1] - x[n / 2] + 1;
long inY = y[n / 2 + 1] - y[n / 2] + 1;
System.out.println(inX * inY);
}
}
static final int mod = 1_000_000_007;
static long mul(long a, long b) {
return a * b % mod;
}
static long fact(int x) {
long ans = 1;
for (int i = 2; i <= x; i++)
ans = mul(ans, i);
return ans;
}
static long fastPow(long base, long exp) {
if (exp == 0)
return 1;
long half = fastPow(base, exp / 2);
if (exp % 2 == 0)
return mul(half, half);
return mul(half, mul(half, base));
}
static long modInv(long x) {
return fastPow(x, mod - 2);
}
static long nCk(int n, int k) {
return mul(fact(n), mul(modInv(fact(k)), modInv(fact(n - k))));
}
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
3da3442812420f4bfa97a8b01225f172
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
/**
* Created on: Feb 18, 2021
* Questions: https://codeforces.com/contest/1486/problem/B
*/
public class EasternExhibition {
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int test = sc.nextInt();
while (test-- > 0) {
int n = sc.nextInt();
int[] x = new int[n], y = new int[n];
for (int i = 0; i < n; i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
// Sort all the indexes, based on x and y axis.
Arrays.sort(x);
Arrays.sort(y);
// If there are odd number of inputs then you will only have one shortest possibility, that will be center point after sorting.
// If there are even number of inputs then you can place the point between the mid-1 and mid point (Including those points).
if (n % 2 == 0) {
int mid = n / 2;
long xAxis = x[mid] - x[mid - 1] + 1;
long yAxis = y[mid] - y[mid - 1] + 1;
System.out.println(xAxis * yAxis);
} else {
System.out.println(1);
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
529ec7a14a789d8a9de90b20c7b3f94c
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
import static java.util.Collections.*;
import static java.util.Arrays.*;
public class B<Array, Target> {
public static int swap(int... args) {
return args[0];
} static ArrayList<Integer> primes = new ArrayList<>();
//static Scanner sc = new Scanner(System.in);
static FastReader sc = new FastReader();
public static void main(String[] args) throws IOException {
do {
startTime = currentTimeMillis();
//setOut(new PrintStream("output"));
//setIn(new FileInputStream("input"));
int T = sc.nextInt();while (T-- != 0)
{
solve();
}
endTime = currentTimeMillis();
long duration = endTime - startTime;
//out.println(duration);
if (false) {
out.println(max(3, 2));
Integer[] ARRAY = new Integer[2];
ArrayList<Integer> LIST = new ArrayList<>();
LIST.add(2);
// sort(LIST, reverseOrder());
LIST.sort(reverseOrder());
sort(ARRAY, reverseOrder());
out.println(LIST + " " + Arrays.toString(ARRAY));
}
} while (LOCAL);
}
public static boolean isPal(String s)
{
StringBuilder stringBuilder = new StringBuilder(s);
return s.equals(stringBuilder.reverse().toString());
}
public static void solve() throws IOException {
B main = new B<>();
/////////////////////////////////////////////////////////////////////
int n =sc.nextInt();
int []x = new int[n];
int []y = new int[n];
for (int i = 0; i < n; i++) {
x[i]=sc.nextInt();
y[i]=sc.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
if(n%2==1){
out.println(1);
}
else {
out.println((x[n/2]-x[n/2-1]+1L)*(y[n/2]-y[n/2-1]+1L));
}
///////////////////////////////////////////////////////////////////////
}
public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE")==null;
// public static final boolean LOCAL = System.getProperty("LOCAL")!=null;
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_RESET = "\u001B[0m";
static long startTime;
static long endTime;
static boolean[] prime;
static final int M = (int) 1e9 + 7;
static final long MM = (long) M * M;
static final int MAX = Integer.MAX_VALUE;
static final int MIN = Integer.MIN_VALUE;
static final int SIZE = (int) 1e9 * 2;
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 Pair implements Comparable<Pair> {
private int key;
private int value;
public Pair(int key, int value) {
this.key = key;
this.value = value;
}
public int second() {
return value;
}
@Override
public int compareTo(Pair o) {
return -Integer.compare(key, o.key);
}
@Override
public String toString() {
return "Pair{" + "x=" + key + ", y=" + value + '}';
}
}
int count(Array[] array, Target target){
int cn=0;
for (Array value : array) {
if (value.equals(target)) cn++;
}
return cn;
}
static int count (String string , char target){
int cn=0;
for (int i = 0; i < string.length(); i++) {
if(string.charAt(i)==target)cn++;
}
return cn;
}
void revArray(Array [] arr) {
int n = arr.length;
for (int i = 0; i < n / 2; i++) {
Array temp = arr[i];
arr[i] = arr[n - i - 1];
arr[n - i - 1] = temp;
}
}
void printArray(Array [] arr) {
int n = arr.length;
for (Array array : arr)out.print(array + " ");
out.println();
}
static void yes() {out.println("YES");}
static void no() {out.println("NO");}
public static int lowerBound(Integer[] array, int length, int value) {
int low = -1;
int hi = length;
while (low + 1 < hi) {
int mid = (low + hi) / 2;
if (array[mid] <= value) {
low = mid;
} else {
hi = mid;
}
}
return low;
}
public static int upperBound(Integer[] array, int length, int value) {
int low = -1;
int hi = length;
while (low + 1 < hi) {
int mid = (low + hi) >> 1;
if (array[mid] >= value) {
hi = mid;
} else low = mid;
}
return hi;
}
public static int binarySearch(Integer[] arr, int length, int value) {
int low = 0;
int hi = length - 1;
int ans = -1;
while (low <= hi) {
int mid = (low + hi) >> 1;
if (arr[mid] > value) {
hi = mid - 1;
} else if (arr[mid] < value) {
low = mid + 1;
} else {
ans = mid;
break;
}
}
return ans;
}
public static int gcd(int a, int b) {
return b==0?a:gcd(b, a % b);
}
public static int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
public static int countDivs(int n) {
int cn = 0;
int sqr = (int) Math.sqrt(n);
for (int i = 1; i <= sqr; ++i) {
if (n % i == 0) {
++cn;
}
}
cn *= 2;
if (sqr * sqr == n) cn--;
return cn;
}
static void prime(int x) {
//sieve algorithm. nlog(log(n)).
prime = new boolean[(x + 1)];
Arrays.fill(prime, true);
prime[0] = prime[1] = false;
for (int i = 2; i * i <= x; i++)
if (prime[i])
for (int j = i * i; j <= x; j += i)
prime[j] = false;
}
static boolean isEven(long x) {
return x % 2 == 0;
}
static boolean isPrime(long x) {
boolean flag = true;
int sqr = (int) Math.sqrt(x);
if (x < 2) return false;
for (int i = 2; i <= sqr; i++) {
if (x % i == 0) {
flag = false;
break;
}
}
return flag;
}
static long factorial(long x) {
long total = 1;
for (int i = 2; i <= x; i++)
total = (total * i) % M;
return total;
}
static long power(long x, long n) {
if (n == 0) {
return 1;
}
long pow = power(x, n / 2L);
if ((n & 1) == 1) {
return (x * (pow) * (pow));
}
return (pow * pow);
}
private static <T> String ts(T t) {
if(t==null) {
return "null";
}
try {
return ts((Iterable) t);
}catch(ClassCastException e) {
if(t instanceof int[]) {
String s = Arrays.toString((int[]) t);
return "{"+s.substring(1, s.length()-1)+"}";
}else if(t instanceof long[]) {
String s = Arrays.toString((long[]) t);
return "{"+s.substring(1, s.length()-1)+"}";
}else if(t instanceof char[]) {
String s = Arrays.toString((char[]) t);
return "{"+s.substring(1, s.length()-1)+"}";
}else if(t instanceof double[]) {
String s = Arrays.toString((double[]) t);
return "{"+s.substring(1, s.length()-1)+"}";
}else if(t instanceof boolean[]) {
String s = Arrays.toString((boolean[]) t);
return "{"+s.substring(1, s.length()-1)+"}";
}
try {
return ts((Object[]) t);
}catch(ClassCastException e1) {
return t.toString();
}
}
}
private static <T> String ts(T[] arr) {
StringBuilder ret = new StringBuilder();
ret.append("{");
boolean first = true;
for(T t: arr) {
if(!first) {
ret.append(", ");
}
first = false;
ret.append(ts(t));
}
ret.append("}");
return ret.toString();
}
private static <T> String ts(Iterable<T> iter) {
StringBuilder ret = new StringBuilder();
ret.append("{");
boolean first = true;
for(T t: iter) {
if(!first) {
ret.append(", ");
}
first = false;
ret.append(ts(t));
}
ret.append("}");
return ret.toString();
}
public static void dbg(Object... o) {
if(LOCAL) {
System.err.print("Line #"+Thread.currentThread().getStackTrace()[2].getLineNumber()+": [");
for(int i = 0; i<o.length; i++) {
if(i!=0) {
System.err.print(", ");
}
System.err.print(ts(o[i]));
}
System.err.println("]");
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
1ad796358e362d30d02e7c9fad742493
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
/*input
6
3
0 0
2 0
1 2
4
1 0
0 2
2 3
3 1
4
0 0
0 1
1 0
1 1
2
0 0
1 1
2
0 0
2 0
2
0 0
0 0
*/
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static PrintWriter out;
static int MOD = 1000000007;
static FastReader scan;
/*-------- I/O using short named function ---------*/
public static String ns(){return scan.next();}
public static int ni(){return scan.nextInt();}
public static long nl(){return scan.nextLong();}
public static double nd(){return scan.nextDouble();}
public static String nln(){return scan.nextLine();}
public static void p(Object o){out.print(o);}
public static void ps(Object o){out.print(o + " ");}
public static void pn(Object o){out.println(o);}
/*-------- for output of an array ---------------------*/
static void iPA(int arr []){
StringBuilder output = new StringBuilder();
for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
}
static void lPA(long arr []){
StringBuilder output = new StringBuilder();
for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
}
static void sPA(String arr []){
StringBuilder output = new StringBuilder();
for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
}
static void dPA(double arr []){
StringBuilder output = new StringBuilder();
for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
}
/*-------------- for input in an array ---------------------*/
static void iIA(int arr[]){
for(int i=0; i<arr.length; i++)arr[i] = ni();
}
static void lIA(long arr[]){
for(int i=0; i<arr.length; i++)arr[i] = nl();
}
static void sIA(String arr[]){
for(int i=0; i<arr.length; i++)arr[i] = ns();
}
static void dIA(double arr[]){
for(int i=0; i<arr.length; i++)arr[i] = nd();
}
/*------------ for taking input faster ----------------*/
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;
}
}
// Method to check if x is power of 2
static boolean isPowerOfTwo (int x) { return x!=0 && ((x&(x-1)) == 0);}
//Method to return lcm of two numbers
static int gcd(int a, int b){return a==0?b:gcd(b % a, a); }
//Method to count digit of a number
static int countDigit(long n){return (int)Math.floor(Math.log10(n) + 1);}
//Method for sorting
static void ruffle_sort(int[] a) {
//shandom_ruffle
Random r=new Random();
int n=a.length;
for (int i=0; i<n; i++) {
int oi=r.nextInt(n);
int temp=a[i];
a[i]=a[oi];
a[oi]=temp;
}
//sort
Arrays.sort(a);
}
//Method for checking if a number is prime or not
static boolean isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
public static void main (String[] args) throws java.lang.Exception
{
OutputStream outputStream =System.out;
out =new PrintWriter(outputStream);
scan =new FastReader();
//for fast output sometimes
StringBuilder sb = new StringBuilder();
int t = ni();
while(t-->0){
int n = ni();
int[] x = new int[n], y = new int[n];
for(int i=0; i<n; i++){
x[i] = ni(); y[i] = ni();
}
ruffle_sort(x);
ruffle_sort(y);
if(n%2!=0)
pn(1);
else{
int mid1 = x[n/2] - x[(n-1)/2] + 1;
int mid2 = y[n/2] - y[(n-1)/2] + 1;
long ans = (long)mid1 * (long)mid2;
pn(ans);
}
}
out.flush();
out.close();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
f7736537500a20573365bcdc85a1fd91
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
//@author->.....future_me......//
//..............Learning.........//
/*Compete against yourself*/
import java.util.*;
import java.io.*;
import java.lang.*;
public class B {
static FastReader sc = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws Exception {
// try {
// sieve();
//Arrays.fill(dp, -1);
int t = sc.nextInt();
while (t-- > 0)
B.go();
out.flush();
// } catch (Exception e) {
// return;}
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //
static int mod=998244353;
static void go() {
int n=sc.nextInt();
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++) {
int xx=sc.nextInt(),yy=sc.nextInt();
x[i]=xx;
y[i]=yy;
}
if(n%2==1) {
out.println(1);
return;
}
sort(x);sort(y);
out.println((x[n/2]-x[n/2-1]+1)*1l*(y[n/2]-y[n/2-1]+1));
}
public static void findAllNumbers(int N)
{
// find cube root of N
double cb = Math.pow(N, 1.0 / 3);
// create an empty set
Set<Integer> s = new HashSet<>();
for (int i = 1; i < cb - 1; i++)
{
for (int j = i + 1; j < cb; j++)
{
// (i, j) forms a pair
int sum = (i * i * i) + (j * j * j);
// sum is seen before
if (s.contains(sum)) {
System.out.println(sum);
} else {
// sum is not seen before
s.add(sum);
}
}
}
}
static long bs(long x,long y) {
long l=0;long r=(long)(1e9);
long res=0;
while(l<=r) {
long mid=(l+r)/2;
if((mid*(mid-1)+mid-1)>x) {
r=mid-1;
}else {
res=mid;
l=mid+1;
}
}
return res;
}
static long gcd(long a,long b){
if(b==0){
return a;
}
return gcd(b,a%b);
}
static long fact[];
static long invfact[];
static long ncr(int n,int k) {
if(k<0||k>n) {
return 0;
}
long x=fact[n]%mod;
long y=invfact[k]%mod;
long yy=invfact[n-k]%mod;
long ans=(x*y)%mod;
ans=(ans*yy)%mod;
return ans;
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //
static int prime[]=new int[1000006];
static void sieve() {
Arrays.fill(prime, 1);
prime[0]=0;
prime[1]=0;
for(int i=2;i*i<=1000005;i++) {
if(prime[i]==1)
for(int j=i*i;j<=1000005;j+=i) {
prime[j]=0;
}
}
for(int i=1;i<1000005;i++) {prime[i]=prime[i]+prime[i-1];}
}
static void sort(long [] a) {
ArrayList<Long> aa = new ArrayList<>();
for (long i : a) {
aa.add(i);
}Collections.sort(aa); for (int i = 0; i < a.length; i++)
a[i] = aa.get(i); }
static void sort(int [] a) {
ArrayList<Integer> aa = new ArrayList<>();
for (int i : a) {
aa.add(i);
} Collections.sort(aa); for (int i = 0; i < a.length; i++)
a[i] = aa.get(i); }
static long pow(long x, long y) {
long res = 1l;
while (y != 0) {
if (y % 2 == 1) {
res = (x%mod * res%mod)%mod; } y /= 2; x = (x%mod * x%mod)%mod;
} return res%mod; }
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //
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;
}}
}
class point{
int x,y;
point(int x,int y){
this.x=x;
this.y=y;
}
}
/*
* imp log method using math function is somewhat inaccurate to check power of
* two
*
*/
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 11
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
760643b51acd4cc6c5e354fe458475b2
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
static FastScanner sc = new FastScanner(System.in);
static PrintWriter pw = new PrintWriter(System.out);
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws Exception {
//solveA();
solveB();
//solveC();
//solveD();
//solveE();
//solveF();
pw.flush();
}
public static void solveA(){
pw.println();
}
public static void solveB(){
int T = sc.nextInt();
while(T > 0){
int n = sc.nextInt();
long[] a = new long[n];
long[] b = new long[n];
for(int i = 0; i < n; i++){
a[i] = sc.nextInt();
b[i] = sc.nextInt();
}
GeekInteger.save_sort(a);
GeekInteger.save_sort(b);
if(n % 2 == 0){
pw.println((a[n/2] - a[n/2-1]+1) * (b[n/2] - b[n/2-1]+1));
}else{
pw.println(1);
}
T--;
}
}
public static void solveC(){
pw.println();
}
public static void solveD(){
pw.println();
}
public static void solveE(){
pw.println();
}
public static void solveF(){
pw.println();
}
static class GeekInteger {
public static void save_sort(int[] array) {
shuffle(array);
Arrays.sort(array);
}
public static int[] shuffle(int[] array) {
int n = array.length;
Random random = new Random();
for (int i = 0, j; i < n; i++) {
j = i + random.nextInt(n - i);
int randomElement = array[j];
array[j] = array[i];
array[i] = randomElement;
}
return array;
}
public static void save_sort(long[] array) {
shuffle(array);
Arrays.sort(array);
}
public static long[] shuffle(long[] array) {
int n = array.length;
Random random = new Random();
for (int i = 0, j; i < n; i++) {
j = i + random.nextInt(n - i);
long randomElement = array[j];
array[j] = array[i];
array[i] = randomElement;
}
return array;
}
}
}
class FastScanner {
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public FastScanner(InputStream in) {
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
public String next() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String nextLine() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken("\n");
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String[] nextArray(int n) {
String[] a = new String[n];
for (int i = 0; i < n; i++)
a[i] = next();
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 long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
9e6143bf1cff7c2d6dfa5e7107583170
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class cf2{
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 int count=0;
public static Map<Integer,Integer>map;
public static List<Integer>list=new ArrayList<>();
public static void main(String args[]){
FastReader sc=new FastReader();
StringBuilder sb=new StringBuilder();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int x[]=new int[n];
int y[]=new int[n];
int ax=Integer.MAX_VALUE;
int ay=Integer.MAX_VALUE;
int bx=0;
int by=0;
for(int i=0;i<n;i++){x[i]=sc.nextInt();y[i]=sc.nextInt();}
Arrays.sort(x);
Arrays.sort(y);
int countx= x[n / 2] - x[(n - 1) / 2] + 1;
int county=y[n / 2] - y[(n - 1) / 2] + 1;
System.out.println((long)countx*(long)county);
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
c2cf865d0c130366e129a38047b0e135
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class Main implements Runnable {
int n, m;
static boolean use_n_tests = true;
int N = -1;
long mod = 1000000007;
void solve(FastScanner in, PrintWriter out, int testNumber) {
n = in.nextInt();
Integer[] x = new Integer[n];
Integer[] y = new Integer[n];
for (int i = 0; i < n; i++) {
x[i] = in.nextInt();
y[i] = in.nextInt();
}
if (n % 2 == 1) {
out.println(1);
} else {
Arrays.sort(x);
Arrays.sort(y);
out.println((x[n / 2] - x[n / 2 - 1] + 1) * 1L * (y[n / 2] - y[n / 2 - 1] + 1));
}
}
// ****************************** template code ***********
static int stack_size = 1 << 27;
class Mod {
long mod;
Mod(long mod) {
this.mod = mod;
}
long add(long a, long b) {
a = mod(a);
b = mod(b);
return (a + b) % mod;
}
long sub(long a, long b) {
a = mod(a);
b = mod(b);
return (a - b + mod) % mod;
}
long mul(long a, long b) {
a = mod(a);
b = mod(b);
return a * b % mod;
}
long div(long a, long b) {
a = mod(a);
b = mod(b);
return (a * inv(b)) % mod;
}
public long inv(long r) {
if (r == 1)
return 1;
return ((mod - mod / r) * inv(mod % r)) % mod;
}
private long mod(long a) {
return a % mod;
}
}
class Coeff {
long mod;
long[][] C;
long[] fact;
boolean cycleWay = false;
Coeff(int n, long mod) {
this.mod = mod;
fact = new long[n + 1];
fact[0] = 1;
for (int i = 1; i <= n; i++) {
fact[i] = i;
fact[i] %= mod;
fact[i] *= fact[i - 1];
fact[i] %= mod;
}
}
Coeff(int n, int m, long mod) {
// n > m
cycleWay = true;
this.mod = mod;
C = new long[n + 1][m + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= Math.min(i, m); j++) {
if (j == 0 || j == i) {
C[i][j] = 1;
} else {
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
C[i][j] %= mod;
}
}
}
}
public long C(int n, int m) {
if (cycleWay) {
return C[n][m];
}
return fC(n, m);
}
private long fC(int n, int m) {
return (fact[n] * inv(fact[n - m] * fact[m] % mod)) % mod;
}
private long inv(long r) {
if (r == 1)
return 1;
return ((mod - mod / r) * inv(mod % r)) % mod;
}
}
class Pair {
int first;
int second;
public int getFirst() {
return first;
}
public int getSecond() {
return second;
}
}
class MultisetTree<T> {
int size = 0;
TreeMap<T, Integer> mp = new TreeMap<>();
void add(T x) {
mp.merge(x, 1, Integer::sum);
size++;
}
void remove(T x) {
if (mp.containsKey(x)) {
mp.merge(x, -1, Integer::sum);
if (mp.get(x) == 0) {
mp.remove(x);
}
size--;
}
}
boolean contains(T x) {
return mp.containsKey(x);
}
T greatest() {
return mp.lastKey();
}
T smallest() {
return mp.firstKey();
}
int size() {
return size;
}
int diffSize() {
return mp.size();
}
}
class Multiset<T> {
int size = 0;
Map<T, Integer> mp = new HashMap<>();
void add(T x) {
mp.merge(x, 1, Integer::sum);
size++;
}
boolean contains(T x) {
return mp.containsKey(x);
}
void remove(T x) {
if (mp.containsKey(x)) {
mp.merge(x, -1, Integer::sum);
if (mp.get(x) == 0) {
mp.remove(x);
}
size--;
}
}
int size() {
return size;
}
int diffSize() {
return mp.size();
}
}
static class Range {
int l, r;
int id;
public int getL() {
return l;
}
public int getR() {
return r;
}
public Range(int l, int r, int id) {
this.l = l;
this.r = r;
this.id = id;
}
}
static class Array {
static Range[] readRanges(int n, FastScanner in) {
Range[] result = new Range[n];
for (int i = 0; i < n; i++) {
result[i] = new Range(in.nextInt(), in.nextInt(), i);
}
return result;
}
static List<List<Integer>> intInit2D(int n) {
List<List<Integer>> res = new ArrayList<>();
for (int i = 0; i < n; i++) {
res.add(new ArrayList<>());
}
return res;
}
static boolean isSorted(Integer[] a) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
static public long sum(int[] a) {
long sum = 0;
for (int x : a) {
sum += x;
}
return sum;
}
static public long sum(long[] a) {
long sum = 0;
for (long x : a) {
sum += x;
}
return sum;
}
static public long sum(Integer[] a) {
long sum = 0;
for (int x : a) {
sum += x;
}
return sum;
}
static public int min(Integer[] a) {
int mn = Integer.MAX_VALUE;
for (int x : a) {
mn = Math.min(mn, x);
}
return mn;
}
static public int min(int[] a) {
int mn = Integer.MAX_VALUE;
for (int x : a) {
mn = Math.min(mn, x);
}
return mn;
}
static public int max(Integer[] a) {
int mx = Integer.MIN_VALUE;
for (int x : a) {
mx = Math.max(mx, x);
}
return mx;
}
static public int max(int[] a) {
int mx = Integer.MIN_VALUE;
for (int x : a) {
mx = Math.max(mx, x);
}
return mx;
}
static public int[] readint(int n, FastScanner in) {
int[] out = new int[n];
for (int i = 0; i < out.length; i++) {
out[i] = in.nextInt();
}
return out;
}
}
class Graph {
List<List<Integer>> graph;
Graph(int n) {
create(n);
}
void create(int n) {
List<List<Integer>> graph = new ArrayList<>();
for (int i = 0; i < n; i++) {
graph.add(new ArrayList<>());
}
this.graph = graph;
}
void readBi(int m, FastScanner in) {
for (int i = 0; i < m; i++) {
int v = in.nextInt() - 1;
int u = in.nextInt() - 1;
graph.get(v).add(u);
graph.get(u).add(v);
}
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream io) {
br = new BufferedReader(new InputStreamReader(io));
}
public String line() {
String result = "";
try {
result = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public int[] nextArray(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = in.nextInt();
}
return res;
}
public long[] nextArrayL(int n) {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = in.nextLong();
}
return res;
}
public Long[] nextArrayL2(int n) {
Long[] res = new Long[n];
for (int i = 0; i < n; i++) {
res[i] = in.nextLong();
}
return res;
}
public Integer[] nextArray2(int n) {
Integer[] res = new Integer[n];
for (int i = 0; i < n; i++) {
res[i] = in.nextInt();
}
return res;
}
public long nextLong() {
return Long.parseLong(next());
}
}
void run_t_tests() {
int t = in.nextInt();
int i = 0;
while (t-- > 0) {
solve(in, out, i++);
}
}
void run_one() {
solve(in, out, -1);
}
@Override
public void run() {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
if (use_n_tests) {
run_t_tests();
} else {
run_one();
}
out.close();
}
static FastScanner in;
static PrintWriter out;
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(null, new Main(), "", stack_size);
thread.start();
thread.join();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
944ff608df3ee808319ed54f806d51d4
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) {
FastScanner in = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-->0) {
int n = in.nextInt();
long x[] = new long[n], y[] = new long[n];
for(int i=0;i<n;i++){
x[i] = in.nextInt(); y[i] = in.nextInt();
}
ruffleSort(x); ruffleSort(y);
if(n%2==1){
out.println(1);
}
else{
out.println((x[n/2]-x[(n-1)/2]+1)*(y[n/2]-y[(n-1)/2]+1));
}
}
out.flush();
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while(!st.hasMoreTokens())
try { st = new StringTokenizer(br.readLine()); }
catch(IOException e) {}
return st.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
}
static final Random random = new Random();
static void ruffleSort(long[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n);long temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
28fc3903ba2251931082491ed4950a86
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class forces{
public static void main(String[] args){
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-- > 0){
solve(scn);
}
}
public static void solve(Scanner scn){
int n = scn.nextInt();
ArrayList<Integer> x = new ArrayList<>();
ArrayList<Integer> y = new ArrayList<>();
for(int i = 0; i < n; i++){
int a = scn.nextInt();
int b = scn.nextInt();
x.add(a);
y.add(b);
}
Collections.sort(x);
Collections.sort(y);
if(x.size() % 2 == 1){
System.out.println(1);
return;
}
else{
long x1 = 0, y1 = 0, x2 = 0, y2 = 0;
x1 = x.get(x.size() / 2);
y1 = y.get(y.size() / 2);
x2 = x.get((x.size() / 2) - 1);
y2 = y.get((y.size() / 2) - 1);
long delx = Math.abs(x1 - x2) + 1;
long dely = Math.abs(y1 - y2) + 1;
long ans = (delx*dely);
System.out.println(ans);
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
c542441fd0303dc954b08d4700fde83c
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static int n;
public static void main(String[] args) throws Exception {
int t = Integer.parseInt(in.readLine());
while(t--!=0) {
n = Integer.parseInt(in.readLine());
int [] x = new int [n+1];
int [] y = new int [n+1];
for(int i=1;i<=n;i++) {
String [] s = in.readLine().split(" ");
x[i] = Integer.parseInt(s[0]);
y[i] = Integer.parseInt(s[1]);
}
out.println((long)solve(x)*(long)solve(y));
}
out.flush();
}
static int solve(int [] a) {
Arrays.sort(a,1,a.length);
return a[(a.length+1)/2] - a[a.length/2]+1;
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
c7527e6bd1477892c04c79ae405b3400
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
import static java.lang.Double.parseDouble;
import static java.lang.Integer.compare;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.in;
public class Main {
private static final int MOD = (int) (1E9 + 7);
static FastScanner scanner = new FastScanner(in);
public static void main(String[] args) throws IOException {
// Write your solution here
int t = 1;
t = parseInt(scanner.nextLine());
while (t-- > 0) {
solve();
}
}
private static void solve() throws IOException {
int n = scanner.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for (int i = 0; i < n; i++) {
x[i] = scanner.nextInt();
y[i] = scanner.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
if(n % 2 != 0){
System.out.println("1");
return;
}
long ans = (x[n/2] - x[n/2 - 1] + 1L) * (y[n/2] - y[n/2 - 1] + 1L);
System.out.println(ans);
}
private static int add(int a, int b) {
long res = ((long) (a + MOD) % MOD + (b + MOD)) % MOD;
return (int) res;
}
private static int mul(int a, int b) {
long res = ((long) a % MOD * b % MOD) % MOD;
return (int) res;
}
private static int pow(int a, int b) {
a %= MOD;
int res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
private static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
private static class Pair implements Comparable<Pair> {
int index, value;
public Pair(int index, int value) {
this.index = index;
this.value = value;
}
public int compareTo(Pair o) {
if (value != o.value) return compare(value, o.value);
return compare(index, o.index);
}
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
return null;
}
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return parseInt(next());
}
long nextLong() {
return parseLong(next());
}
double nextDouble() {
return parseDouble(next());
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
5358b96cb5bc0847d099ec1d4c030dc1
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main2 {
public Main2() throws FileNotFoundException {
// File file = Paths.get("input.txt").toFile();
// if (file.exists()) {
// System.setIn(new FileInputStream(file));
// }
long t = System.currentTimeMillis();
FastReader reader = new FastReader();
int tt = reader.nextInt();
for (int ttt = 0; ttt < tt; ttt++) {
int n = reader.nextInt();
long[] x=new long[n];
long[] y=new long[n];
for(int i=0;i<n;i++) {
x[i]=reader.nextLong();
y[i]=reader.nextLong();
}
Arrays.sort(x);
Arrays.sort(y);
int idx1=(n+1)/2-1;
int idx2=(n+2)/2-1;
long xx=x[idx2]-x[idx1]+1;
long yy=y[idx2]-y[idx1]+1;
//System.out.println(xx+":"+yy);
System.out.println(xx*yy);
//269327966===151858805
// 40899823069840630
}
// System.out.println("TIME: "+(System.currentTimeMillis()-t));
}
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) throws FileNotFoundException {
new Main2();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
d2f89d31ad215420f0c69884bd6921fe
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.awt.*;
public class B
{
BufferedReader in;
PrintWriter ob;
StringTokenizer st;
public static void main(String[] args) throws IOException {
new B().run();
}
void run() throws IOException {
in=new BufferedReader(new InputStreamReader(System.in));
ob=new PrintWriter(System.out);
int t = ni();
while(t-->0)
solve();
ob.flush();
}
void solve() throws IOException {
int n = ni();
int x[] = new int[n];
int y[] = new int[n];
for (int i=0 ; i<n ; i++) {
x[i] = ni();
y[i] = ni();
}
if( n%2 == 1 ) {
ob.println("1");
} else {
Arrays.sort(x);
Arrays.sort(y);
long ans = (x[n/2] - x[n/2-1] +1)*1L*(y[n/2] - y[n/2-1] +1);
ob.println(ans);
}
}
String ns() throws IOException {
return nextToken();
}
long nl() throws IOException {
return Long.parseLong(nextToken());
}
int ni() throws IOException {
return Integer.parseInt(nextToken());
}
double nd() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
if(st==null || !st.hasMoreTokens())
st=new StringTokenizer(in.readLine());
return st.nextToken();
}
int[] nia(int start,int b) throws IOException {
int a[]=new int[b];
for(int i=start;i<b;i++)
a[i]=ni();
return a;
}
long[] nla(int start,int n) throws IOException {
long a[]=new long[n];
for (int i=start; i<n ;i++ ) {
a[i]=nl();
}
return a;
}
public void tr(Object... o) {
ob.println(Arrays.deepToString(o));
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
a3a2663dfe3456312f34c4893643fab7
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public final class Solution {
static PrintWriter out = new PrintWriter(System.out);
static FastReader in = new FastReader();
static long mod = (long) 1e9 + 7;
static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(1, 0), new Pair(0, -1), new Pair(0, 1)};
public static void main(String[] args) {
int t = i();
out:
while (t-- > 0) {
int n = i();
long[] x = new long[n];
long[] y = new long[n];
for (int i = 0; i < n; i++) {
x[i] = l();
y[i] = l();
}
Arrays.sort(x);
Arrays.sort(y);
if (n % 2 == 1) {
out.println(1);
} else {
out.println((x[n / 2] - x[n / 2 - 1] + 1) * (y[n / 2] - y[n / 2 - 1] + 1));
}
}
out.flush();
}
static boolean isPS(double number) {
double sqrt = Math.sqrt(number);
return ((sqrt - Math.floor(sqrt)) == 0);
}
static int sd(long i) {
int d = 0;
while (i > 0) {
d += i % 10;
i = i / 10;
}
return d;
}
static int[] leastPrime;
static void sieveLinear(int N) {
int[] primes = new int[N];
int idx = 0;
leastPrime = new int[N + 1];
for (int i = 2; i <= N; i++) {
if (leastPrime[i] == 0) {
primes[idx++] = i;
leastPrime[i] = i;
}
int curLP = leastPrime[i];
for (int j = 0; j < idx; j++) {
int p = primes[j];
if (p > curLP || (long) p * i > N) {
break;
} else {
leastPrime[p * i] = p;
}
}
}
}
static int lower(long A[], long x) {
int l = -1, r = A.length;
while (r - l > 1) {
int m = (l + r) / 2;
if (A[m] >= x) {
r = m;
} else {
l = m;
}
}
return r;
}
static int upper(long A[], long x) {
int l = -1, r = A.length;
while (r - l > 1) {
int m = (l + r) / 2;
if (A[m] <= x) {
l = m;
} else {
r = m;
}
}
return l;
}
static void swap(int A[], int a, int b) {
int t = A[a];
A[a] = A[b];
A[b] = t;
}
static int lowerBound(int A[], int low, int high, int x) {
if (low > high) {
if (x >= A[high]) {
return A[high];
}
}
int mid = (low + high) / 2;
if (A[mid] == x) {
return A[mid];
}
if (mid > 0 && A[mid - 1] <= x && x < A[mid]) {
return A[mid - 1];
}
if (x < A[mid]) {
return lowerBound(A, low, mid - 1, x);
}
return lowerBound(A, mid + 1, high, x);
}
static long pow(long a, long b) {
long pow = 1;
long x = a;
while (b != 0) {
if ((b & 1) != 0) {
pow = (pow * x) % mod;
}
x = (x * x) % mod;
b /= 2;
}
return pow;
}
static boolean isPrime(long N) {
if (N <= 1) {
return false;
}
if (N <= 3) {
return true;
}
if (N % 2 == 0 || N % 3 == 0) {
return false;
}
for (int i = 5; i * i <= N; i = i + 6) {
if (N % i == 0 || N % (i + 2) == 0) {
return false;
}
}
return true;
}
static void print(char A[]) {
for (char c : A) {
out.print(c);
}
out.println();
}
static void print(boolean A[]) {
for (boolean c : A) {
out.print(c + " ");
}
out.println();
}
static void print(int A[]) {
for (int c : A) {
out.print(c + " ");
}
out.println();
}
static void print(long A[]) {
for (long i : A) {
out.print(i + " ");
}
out.println();
}
static void print(List<Integer> A) {
for (int a : A) {
out.print(a + " ");
}
}
static void printYes() {
out.println("YES");
}
static void printNo() {
out.println("NO");
}
static int i() {
return in.nextInt();
}
static long l() {
return in.nextLong();
}
static String s() {
return in.nextLine();
}
static int[] input(int N) {
int A[] = new int[N];
for (int i = 0; i < N; i++) {
A[i] = in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[] = new long[N];
for (int i = 0; i < A.length; i++) {
A[i] = in.nextLong();
}
return A;
}
static int GCD(int a, int b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
static long GCD(long a, long b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
}
class BIT {
int n;
int[] tree;
public BIT(int n) {
this.n = n;
this.tree = new int[n + 1];
}
public static int lowbit(int x) {
return x & (-x);
}
public void update(int x) {
while (x <= n) {
++tree[x];
x += lowbit(x);
}
}
public int query(int x) {
int ans = 0;
while (x > 0) {
ans += tree[x];
x -= lowbit(x);
}
return ans;
}
public int query(int x, int y) {
return query(y) - query(x - 1);
}
}
class SegmentTree {
long[] t;
public SegmentTree(int n) {
t = new long[n + n];
Arrays.fill(t, Long.MIN_VALUE);
}
public long get(int i) {
return t[i + t.length / 2];
}
public void add(int i, long value) {
i += t.length / 2;
t[i] = value;
for (; i > 1; i >>= 1) {
t[i >> 1] = Math.max(t[i], t[i ^ 1]);
}
}
// max[a, b]
public long max(int a, int b) {
long res = Long.MIN_VALUE;
for (a += t.length / 2, b += t.length / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
if ((a & 1) != 0) {
res = Math.max(res, t[a]);
}
if ((b & 1) == 0) {
res = Math.max(res, t[b]);
}
}
return res;
}
}
class Pair {
int i, j;
Pair(int i, int j) {
this.i = i;
this.j = j;
}
}
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
b153befb0903363448e6c8597d8e5426
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import com.sun.org.apache.regexp.internal.RE;
import java.util.*;
public class Main {
static Scanner scan = new Scanner(System.in);
public static void slove(){
int n = scan.nextInt();
int[] X = new int[n];
int[] Y = new int[n];
int idx = 0;
for(int i=0;i<n;i++){
int x = scan.nextInt();
int y = scan.nextInt();
X[idx] = x;
Y[idx++] = y;
}
Arrays.sort(X);
Arrays.sort(Y);
long sum = 0;
if(idx % 2 == 0){
int t = X[idx/2];
int lt = X[idx/2 - 1];
if(t == lt){
sum = 1;
}else{
sum = t - lt + 1;
}
}else{
sum = 1;
}
if(idx % 2 == 0){
int t = Y[idx/2];
int lt = Y[idx/2 - 1];
if(t == lt){
sum *= 1;
}else{
sum *= t - lt + 1;
}
}else{
sum *=1;
}
System.out.println(sum);
}
public static void main(String[] args) {
int T = scan.nextInt();
while(T-->0){
slove();
}
}
}
class Node{
int x;
int y;
public Node(int x, int y) {
this.x = x;
this.y = y;
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
5d1720e89b0ca8c4f58e115e11c08c8a
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.io.*;
public class Equal {
static class pair implements Comparable<pair> {
int x;
int y;
public pair(int u, int v) {
this.x = u;
this.y = v;
}
@Override
public int compareTo(pair o) {
return o.x-x;
}
}
static int[][]mem=new int[1001][1001];
// static int dp(int n,int k){
// if(n>=mem.length)
// return 0;
// if(k<0||k>=mem.length)
// return 0;
// if(mem[n][k]!=-1)
// return mem[n][k];
// }
static String timeInc(String time,int h,int m){
String []s =time.split(":");
int i=0;
int hh=0;
int mm=0;
while (i<s[0].length()&&s[0].charAt(i)=='0'){
i++;
}
if(i<s[0].length())
hh=Integer.parseInt(s[0].substring(i));
i=0;
while (i<s[1].length()&&s[1].charAt(i)=='0'){
i++;
}
if(i<s[1].length())
mm=Integer.parseInt(s[1].substring(i));
mm++;
if(mm%m==0){
mm=0;
hh++;
if(hh%h==0)
hh=0;
}
String hs=""+hh;
while(hs.length()<2)
hs="0"+hs;
String ms=""+mm;
while (ms.length()<2)
ms="0"+ms;
return hs+":"+ms;
}
static boolean validMirror(String s,int h,int m){
HashSet<Character>hs=new HashSet<>();
hs.add('3');
hs.add('4');
hs.add('6');
hs.add('7');
hs.add('9');
for (int i = 0; i <s.length() ; i++) {
if(hs.contains(s.charAt(i))){
return false;
}
}
String mirrored="";
for (int i = s.length()-1; i >=0 ; i--) {
if(s.charAt(i)=='5'){
mirrored+="2";
continue;
}
if(s.charAt(i)=='2'){
mirrored+="5";
continue;
}
mirrored+=s.charAt(i);
}
int i=0;
int hh=0;
int mm=0;
String []s2 =mirrored.split(":");
while (i<s2[0].length()&&s2[0].charAt(i)=='0'){
i++;
}
if(i<s2[0].length())
hh=Integer.parseInt(s2[0].substring(i));
i=0;
while (i<s2[1].length()&&s2[1].charAt(i)=='0'){
i++;
}
if(i<s2[1].length())
mm=Integer.parseInt(s2[1].substring(i));
if(hh>=h||mm>=m)
return false;
return true;
}
public static void main(String[] args) throws IOException {
//BufferedReader br = new BufferedReader(new FileReader("name.in"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
PrintWriter out = new PrintWriter(System.out);
int T=Integer.parseInt(br.readLine());
while(T-->0){
int n=Integer.parseInt(br.readLine());
Integer []x=new Integer[n];
Integer []y=new Integer[n];
for (int i = 0; i < n; i++) {
st=new StringTokenizer(br.readLine());
x[i]=Integer.parseInt(st.nextToken());
y[i]=Integer.parseInt(st.nextToken());
}
Arrays.sort(x);
Arrays.sort(y);
if(n%2==1){
out.println(1);
}
else {
long ans=x[n/2]-x[n/2-1]+1;
long ans2=y[n/2]-y[n/2-1]+1;
out.println(ans*ans2);
}
}
out.flush();
out.close();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
b42fff0229f9bb8bfbf7229cfc23f959
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Collections;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Khater
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
BEasternExhibition solver = new BEasternExhibition();
solver.solve(1, in, out);
out.close();
}
static class BEasternExhibition {
int n;
pair[] arr;
public void solve(int testNumber, Scanner sc, PrintWriter pw) {
int t = 1;
t = sc.nextInt();
while (t-- > 0) {
n = sc.nextInt();
arr = new pair[n];
ArrayList<Integer> arx = new ArrayList<>();
ArrayList<Integer> ary = new ArrayList<>();
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
arr[i] = new pair(x, y);
arx.add(x);
ary.add(y);
}
Collections.sort(arx);
Collections.sort(ary);
if (n % 2 == 0) {
pw.println(1l * (arx.get(n / 2) - arx.get(n / 2 - 1) + 1) * (ary.get(n / 2) - ary.get(n / 2 - 1) + 1));
} else {
pw.println(1);
}
}
}
public class pair implements Comparable<pair> {
long a;
long b;
public pair(long a, long b) {
this.a = a;
this.b = b;
}
public int compareTo(pair o) {
return a != o.a ? Long.compare(a, o.a) : Long.compare(b, o.b);
}
public String toString() {
return a + " " + b;
}
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
42fd830cd89e2b7dd6d2207bd6ac6d70
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
submit();
}
public void submit() {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
for(int i = 0; i < N; i++) {
int n = scan.nextInt();
long[] x = new long[n];
long[] y = new long[n];
for(int j = 0; j < n; j++) {
x[j] = (long) scan.nextInt();
y[j] = (long) scan.nextInt();
}
if(n % 2 == 1) System.out.println(1);
else {
Arrays.sort(x);
Arrays.sort(y);
long x1 = x[(n - 1) / 2];
long x2 = x[n / 2];
long y1 = y[(n - 1) / 2];
long y2 = y[n / 2];
System.out.println((x2 - x1 + 1) * (y2 - y1 + 1));
}
}
return;
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
6851aca278fceaeeaba65ba715063f3d
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
/*
Goal: Become better in CP!
Key: Consistency and Discipline
Desire: SDE @ Google USA
Motto: Do what i Love <=> Love what i do
If you don't use your brain 100%, it deteriorates gradually
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class A {
static StringBuffer str=new StringBuffer();
static int n;
static long x[], y[];
static void solve(){
Arrays.sort(x);
Arrays.sort(y);
if(n%2==0){
long xc=x[n/2]-x[n/2-1]+1;
long yc=y[n/2]-y[n/2-1]+1;
str.append(xc*yc).append("\n");
}else str.append("1\n");
}
public static void main(String[] args) throws java.lang.Exception {
BufferedReader bf;
PrintWriter pw;
boolean lenv=false;
if(lenv){
bf = new BufferedReader(
new FileReader("input.txt"));
pw=new PrintWriter(new
BufferedWriter(new FileWriter("output.txt")));
}else{
bf = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
}
int q1 = Integer.parseInt(bf.readLine().trim());
while (q1-- > 0) {
n=Integer.parseInt(bf.readLine().trim());
x=new long[n];
y=new long[n];
for(int i=0;i<n;i++){
String s[]=bf.readLine().trim().split("\\s+");
long u=Long.parseLong(s[0]);
long v=Long.parseLong(s[1]);
x[i]=u;
y[i]=v;
}
solve();
}
pw.println(str);
pw.flush();
// System.outin.print(str);
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
11a10b8c0c305f8feefda1ca7cfc4842
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import javax.sql.rowset.spi.SyncResolver;
import java.io.*;
import java.nio.channels.NonReadableChannelException;
import java.text.DateFormatSymbols;
public class Solution {
static int a[];
static FastScanner fs = null;
public static void main(String[] args) {
fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = fs.nextInt();
outer:
while (t-- > 0) {
int n = fs.nextInt();
ArrayList<Long> xArrayList = new ArrayList<>();
ArrayList<Long> yArrayList = new ArrayList<>();
for(int i=0;i<n;i++) {
long x = fs.nextLong();
long y = fs.nextLong();
xArrayList.add(x);
yArrayList.add(y);
}
Collections.sort(xArrayList);
Collections.sort(yArrayList);
if(xArrayList.size()%2==0) {
long ans = xArrayList.get((n)/2) - xArrayList.get((n-1)/2) +1;
ans = ans*(yArrayList.get((n)/2) - yArrayList.get((n-1)/2)+1);
out.println(ans);
}else {
long ans = 1;
out.println(ans);
}
}
out.close();
}
// static int count=0;
public static void solve(int l,int u, int ht[],int count) {
int maxid=-1;
int max = Integer.MIN_VALUE;
for(int i=l;i<=u;i++) {
if(a[i]>max) {
max = a[i];
maxid=i;
}
}
ht[maxid]=count;
solve(l, maxid-1, ht,count+1);
solve(maxid+1, u, ht,count+1);
}
static long bit[]; // '1' index based array
public static void update(int n,int i,int x){
for(;i<n;i+=(i&(-i))){
bit[i] += x;
}
}
public static long sum(int i){
long sum=0;
for(;i>0 ;i -= (i&(-i))){
sum += bit[i];
}
return sum;
}
static class Pair implements Comparable<Pair> {
int x;
int y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
public int compareTo(Pair o) {
return this.x - o.x;
}
}
static long power(long x, long y, long p) {
if (y == 0)
return 1;
if (x == 0)
return 0;
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static long power(long x, long y) {
if (y == 0)
return 1;
if (x == 0)
return 0;
long res = 1;
while (y > 0) {
if (y % 2 == 1)
res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
static void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a) l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++) a[i] = l.get(i);
}
static 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[] readlongArray(int n){
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static boolean prime[];
static void sieveOfEratosthenes(int n) {
prime = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++) {
// If prime[p] is not changed, then it is a
// prime
if (prime[p] == true) {
// Update all multiples of p
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
}
public static int log2(int x) {
return (int) (Math.log(x) / Math.log(2));
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
static long nCk(int n, int k) {
long res = 1;
for (int i = n - k + 1; i <= n; ++i)
res *= i;
for (int i = 2; i <= k; ++i)
res /= i;
return res;
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
5bdd41bee347220faa680f6b59f53164
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) {
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int T = in.nextInt();
for(int ttt = 1; ttt <= T; ttt++) {
int n = in.nextInt();
long[] x = new long[n];
long[] y = new long[n];
for(int i = 0; i < n; i++) {
x[i] = in.nextLong();
y[i] = in.nextLong();
}
Arrays.sort(x);
Arrays.sort(y);
long ans = (x[n/2]-x[(n-1)/2]+1) * (y[n/2]-y[(n-1)/2]+1);
out.println(ans);
}
out.close();
}
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;
}
int[] readInt(int size) {
int[] arr = new int[size];
for(int i = 0; i < size; i++)
arr[i] = Integer.parseInt(next());
return arr;
}
long[] readLong(int size) {
long[] arr = new long[size];
for(int i = 0; i < size; i++)
arr[i] = Long.parseLong(next());
return arr;
}
int[][] read2dArray(int rows, int cols) {
int[][] arr = new int[rows][cols];
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++)
arr[i][j] = Integer.parseInt(next());
}
return arr;
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
6011c4f41597ef91d766c9b7a883671c
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) {
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int T = in.nextInt();
for(int ttt = 1; ttt <= T; ttt++) {
int n = in.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for(int i = 0; i < n; i++) {
x[i] = in.nextInt();
y[i] = in.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
long d1 = x[n/2]-x[(n-1)/2]+1;
long d2 = y[n/2]-y[(n-1)/2]+1;
System.out.println(d1*d2);
}
out.close();
}
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;
}
int[] readInt(int size) {
int[] arr = new int[size];
for(int i = 0; i < size; i++)
arr[i] = Integer.parseInt(next());
return arr;
}
long[] readLong(int size) {
long[] arr = new long[size];
for(int i = 0; i < size; i++)
arr[i] = Long.parseLong(next());
return arr;
}
int[][] read2dArray(int rows, int cols) {
int[][] arr = new int[rows][cols];
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++)
arr[i][j] = Integer.parseInt(next());
}
return arr;
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
c1c59c09ec4b2ab435ed556e44c7cdef
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class B1486{
static FastScanner fs = null;
public static void main(String[] args) {
fs = new FastScanner();
int t = fs.nextInt();
while(t-->0){
int n = fs.nextInt();
int a[] = new int[n];
int b[] = new int[n];
for(int i=0;i<n;i++){
a[i] = fs.nextInt();
b[i] = fs.nextInt();
}
Arrays.sort(a);
Arrays.sort(b);
long ans = 1;
if(n%2==0){
ans = ((long)a[n/2]-(long)a[n/2-1]+1)*((long)b[n/2]-(long)b[n/2-1]+1);
}
System.out.println(ans);
}
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
8c0fa7dd6d1c0dca1289c178b057bca0
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class CF1486_D2_B {
public static void main(String[] args) {
FastScanner scanner = new FastScanner();
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
solve(scanner);
}
}
private static void solve(FastScanner scanner) {
int n = scanner.nextInt();
ArrayList<Integer> list = new ArrayList<>(n);
// int min = Integer.MAX_VALUE;
// int max = Integer.MIN_VALUE;
int[] x = new int[n];
int[] y = new int[n];
for (int i = 0; i < n; i++) {
x[i] = scanner.nextInt();
y[i] = scanner.nextInt();
// min = Math.min(min, x + y);
// max = Math.max(max, x + y);
// list.add(x + y);
}
Arrays.sort(x);
Arrays.sort(y);
long midx = x[n / 2] - x[(n - 1) / 2] + 1;
long midy = y[n / 2] - y[(n - 1) / 2] + 1;
System.out.println(midx * midy);
// HashMap<Long, Integer> map = new HashMap<>();
// for (int i = 0; i <= max; i++) {
// long l = 0;
// for (Integer x : list) {
// l += Math.abs(x - i);
// }
// map.put(l, map.getOrDefault(l, 0) + 1);
// }
//
//
// long res = Integer.MAX_VALUE;
// for (Map.Entry<Long, Integer> e : map.entrySet()) {
// res = Math.min(res, e.getKey());
// }
// System.out.println(map.get(res));
}
static class Pair {
int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
return x == pair.x &&
y == pair.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
Integer[] nextArray(int n, boolean object) {
Integer[] arr = new Integer[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
1f10e66069e06f3e90ec9d9c2b84f593
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main{
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[] nextArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long[] nextArray(long n) {
long[] a = new long[(int) n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static class FastWriter extends PrintWriter {
FastWriter(){
super(System.out);
}
void println(int[] array) {
for(int i=0; i<array.length; i++) {
print(array[i]+" ");
}
println();
}
void println(long [] array) {
for(int i=0; i<array.length; i++) {
print(array[i]+" ");
}
println();
}
}
static int MOD=998244353;
public static void main(String[] args) throws IOException {
FastScanner in = new FastScanner();
FastWriter out = new FastWriter();
int t=in.nextInt();
//int t=1;
while (t-->0){
int n=in.nextInt();
int[] a=new int[n];
int[] b=new int[n];
for (int i = 0; i < n; i++) {
a[i]=in.nextInt();
b[i]=in.nextInt();
}
Arrays.sort(a);
Arrays.sort(b);
out.println( (long)(a[n/2]-a[(n-1)/2]+1)*(long)(b[n/2]-b[(n-1)/2]+1) );
}
out.close();
}
static boolean check(int[] a){
for (int i = 0; i < a.length - 1; i++) {
if(a[i]!=a[i+1]){
return false;
}
}
return true;
}
//Arrays.sort(a, (o1, o2) -> (o1[0] - o2[0]));
static int subarray_lessthan_k(int[] A,int n,int k){
int s=0,e=0,sum=0,cnt=0;
while(e<n){
sum+=A[e];
while(s<=e&&sum>k){
sum-=A[s++];
}
cnt+=e-s+1;
e++;
}
return cnt;
}
static int totalPrimeFactors(int n) {
int cnt=0;
while (n%2==0) {
cnt++;
n /= 2;
}
int num= (int) Math.sqrt(n);
for (int i = 3; i <= num; i+= 2) {
while (n%i == 0) {
cnt++;
n /= i;
num=(int)Math.sqrt(n);
}
}
if (n > 2){
cnt++;
}
return cnt;
}
static char get(int i){
return (char)(i+'a');
}
static boolean distinct(int num){
HashSet<Integer> set=new HashSet<>();
int len=String.valueOf(num).length();
while (num!=0){
set.add(num%10);
num/=10;
}
return set.size()==len;
}
static int maxSubArraySum(int a[],int st,int en) {
int max_s = Integer.MIN_VALUE, max_e = 0,ind=0,ind1=1;
for (int i = st; i <= en; i++) {
max_e+= a[i];
if (max_s < max_e){
max_s = max_e;
ind=ind1;
}
if (max_e < 0){
max_e = 0;
ind1=i+1;
}
}
if(st==0){
return max_s;
}
if(ind==1){
return a[0]+2*max_s;
}else {
return 2*max_s+maxSubArraySum(a,0,ind-1);
}
//return max_s;
}
static void segmentedSieve(ArrayList<Integer> res,int low, int high) {
if(low < 2){
low = 2;
}
ArrayList<Integer> prime = new ArrayList<>();
simpleSieve(high, prime);
boolean[] mark = new boolean[high - low + 1];
for (int i = 0; i < mark.length; i++){
mark[i] = true;
}
for (int i = 0; i < prime.size(); i++) {
int loLim = (low / prime.get(i)) * prime.get(i);
if (loLim < low){
loLim += prime.get(i);
}
if (loLim == prime.get(i)){
loLim += prime.get(i);
}
for (int j = loLim; j <= high; j += prime.get(i)) {
mark[j - low] = false;
}
}
for (int i = low; i <= high; i++) {
if (mark[i - low]){
res.add(i);
}
}
}
static void simpleSieve(int limit, ArrayList<Integer> prime) {
int bound = (int)Math.sqrt(limit);
boolean[] mark = new boolean[bound + 1];
for (int i = 0; i <= bound; i++){
mark[i] = true;
}
for (int i = 2; i * i <= bound; i++) {
if (mark[i]) {
for (int j = i * i; j <= bound; j += i){
mark[j] = false;
}
}
}
for (int i = 2; i <= bound; i++) {
if (mark[i]){
prime.add(i);
}
}
}
static int highestPowerOf2(int n) {
if (n < 1){ return 0; }
int res = 1;
for (int i = 0; i < 8 * Integer.BYTES; i++) {
int curr = 1 << i;
if (curr > n){ break; }
res = curr;
}
return res;
}
static int reduceFraction(int x, int y) {
int d= gcd(x, y);
return x/d+y/d;
}
static boolean subset(int[] ar,int n,int sum){
if(sum==0){
return true;
}
if(n<0||sum<0){
return false;
}
return subset(ar,n-1,sum)||subset(ar,n-1,sum-ar[n]);
}
static boolean isPrime(int n){
if(n<=1) return false;
for(int i = 2;i<=Math.sqrt(n);i++){
if (n % i == 0) return false;
}
return true;
}
static int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
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 int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
static boolean isPowerOfTwo(long n) {
if(n==0){
return false;
}
while (n%2==0){
n/=2;
}
return n==1;
}
static boolean isPerfectSquare(int x){
if (x >= 0) {
int sr = (int)Math.sqrt(x);
return ((sr * sr) == x);
}
return false;
}
static int lower_bound(int[] arr, int x) {
int low_limit = 0, high_limit = arr.length, mid;
while (low_limit < high_limit) {
mid = (low_limit + high_limit) / 2;
if (arr[mid] >= x){
high_limit = mid;
}else{
low_limit = mid + 1;
}
}
return low_limit;
}
static int upper_bound(int[] arr, int x) {
int low_limit = 0, high_limit = arr.length, mid;
while (low_limit < high_limit) {
mid = (low_limit + high_limit) / 2;
if (arr[mid] > x){
high_limit = mid;
}else{
low_limit = mid + 1;
}
}
return low_limit;
}
static int binarySearch(int[] ar,int n,int num){
int low=0,high=n-1;
while (low<=high){
int mid=(low+high)/2;
if(ar[mid]==num){
return mid;
}else if(ar[mid]>num){
high=mid-1;
}else {
low=mid+1;
}
}
return -1;
}
static int fib(int n) {
long F[][] = new long[][]{{1,1},{1,0}};
if (n == 0){
return 0;
}
power(F, n-1);
return (int)F[0][0];
}
static void multiply(long F[][], long M[][]) {
long x = (F[0][0]*M[0][0])%1000000007 + (F[0][1]*M[1][0])%1000000007;
long y = (F[0][0]*M[0][1])%1000000007 + (F[0][1]*M[1][1])%1000000007;
long z = (F[1][0]*M[0][0])%1000000007 + (F[1][1]*M[1][0])%1000000007;
long w = (F[1][0]*M[0][1])%1000000007 + (F[1][1]*M[1][1])%1000000007;
F[0][0] = x%1000000007;
F[0][1] = y%1000000007;
F[1][0] = z%1000000007;
F[1][1] = w%1000000007;
}
static void power(long F[][], int n) {
if( n == 0 || n == 1){
return;
}
long M[][] = new long[][]{{1,1},{1,0}};
power(F, n/2);
multiply(F, F);
if (n%2 != 0){
multiply(F, M);
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
b0dabbdcc25f01f1d779be0c93b24f9c
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
public class Solutions {
// static ArrayList<ArrayList<Integer>>list=new ArrayList<ArrayList<Integer>>();
static FastScanner scr=new FastScanner();
static PrintStream out=new PrintStream(System.out);
public static void main(String []args) {
int t=scr.nextInt();
while(t-->0) {
solve();
}
}
static void solve() {
int n=scr.nextInt();
long x[]=new long[n];
long y[]=new long[n];
for(int i=0;i<n;i++) {
x[i]=scr.nextLong();
y[i]=scr.nextLong();
}
if(n%2==1) {
out.println(1);
}else {
Arrays.sort(x);
Arrays.sort(y);
long xx=x[n/2]-x[n/2-1]+1;
long yy=y[n/2]-y[n/2-1]+1;
out.println(xx*yy);
}
}
static long nc2(long n) {
return n*(n-1)/2;
}
static int []reverse(int a[]){
int n=a.length;
int b[]=new int[n];
int index=0;
for(int i=n-1;i>=0;i--) {
b[index]=a[i];
}
return b;
}
static boolean isPrime(int n) {
for(int i=2;i*i<=n;i++) {
if(n%i==0) {
return false;
}
}
return true;
}
static void swap(int a[],int i,int j) {
int temp=a[i];a[i]=a[j];
a[j]=temp;
}
static long modPow(long base,long exp,long mod) {
if(exp==0) {
return 1;
}
if(exp%2==0) {
long res=(modPow(base,exp/2,mod));
return (res*res)%mod;
}
return (base*modPow(base,exp-1,mod))%mod;
}
static long gcd(long a,long b) {
if(b==0) {
return a;
}
return gcd(b,a%b);
}
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[] sort(int a[]) {
Arrays.sort(a);
return a;
}
int []reverse(int a[]){
int b[]=new int[a.length];
int index=0;
for(int i=a.length-1;i>=0;i--) {
b[index]=a[i];
}
return b;
}
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[] readLongArray(int n) {
long [] a=new long [n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static int MAX=Integer.MAX_VALUE;
static int MIN=Integer.MIN_VALUE;
}class triplet{
int x;
int y;
int z;
triplet(int fisrt,int second,int third){
this.x=fisrt;
this.y=second;
this.z=third;
}
}
class pair{
int x=0;
int y=0;
pair(int first,int second){
this.x=first;
this.y=second;
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
f0e47b733d5fb65881d93150b62be221
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class pre459
{
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args)
{
FastReader obj = new FastReader();
int tc = obj.nextInt();
while (tc--!=0){
int n = obj.nextInt(),x[] = new int[n],y[] = new int[n];
for(int i=0;i<n;i++){
x[i] = obj.nextInt();
y[i] = obj.nextInt();
}
if((n&1)==1){
System.out.println(1);
continue;
}
Arrays.sort(x);
Arrays.sort(y);
if(n>2){
long xRange = x[n/2]-x[n/2-1]+1,yRange = y[n/2]-y[n/2-1]+1;
System.out.println(xRange*yRange);
}
else{
long xRange = x[1]-x[0]+1,yRange = y[1]-y[0]+1;
System.out.println(xRange*yRange);
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
8a2a4c4dc8c323bb816009e1ff23e064
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
public class EasternExhibition {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int[]arr=new int[n];
int[]narr=new int[n];
for(int i=0;i<n;i++) {
arr[i]=sc.nextInt();
narr[i]=sc.nextInt();
}
if(n%2!=0) {
System.out.println(1);
}else {
Arrays.sort(arr);
Arrays.sort(narr);
long a=arr[n/2]-arr[(n/2) -1]+1;
long b=narr[n/2]-narr[(n/2) -1]+1;
System.out.println(a*b);
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
86392b893a67f9a5ed6bf707d1ab3a0a
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class B {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-- != 0) {
int n = sc.nextInt();
int[] arr1 = new int[n];
int[] arr2 = new int[n];
for(int i=0; i<n; i++) {
arr1[i] = sc.nextInt();
arr2[i] = sc.nextInt();
}
long ans = solve(arr1, n) * solve(arr2, n);
out.println(ans);
}
out.close();
}
static long solve(int[] arr1, int n) {
Arrays.sort(arr1);
return (arr1[n/2] - arr1[(n-1)/2] + 1);
}
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();
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
9ad6bb94753c3604122aebd7b053b6d9
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class B {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-- != 0) {
int n = sc.nextInt();
int[] arr1 = new int[n];
int[] arr2 = new int[n];
for(int i=0; i<n; i++) {
arr1[i] = sc.nextInt();
arr2[i] = sc.nextInt();
}
long ans = solve(arr1, n) * solve(arr2, n);
out.println(ans);
}
out.close();
}
static long solve(int[] arr1, int n) {
Arrays.sort(arr1);
return (long)(arr1[n/2] - arr1[(n-1)/2] + 1);
}
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();
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
ae44dd7ed5f31a1a5b194808ee8baea0
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
/**
* Coder: SumitRaut
* Date: 27-02-2021 14:23
*/
public class Main {
public static void main(String[] args) throws IOException {
Fs = new FastReader();
out = new PrintWriter(System.out);
int t=Fs.nextInt();
while(t-->0) {
int n=Fs.nextInt();
int x[]=new int[n],y[]=new int[n];
for(int i=0;i<n;++i) {
x[i]=Fs.nextInt();
y[i]=Fs.nextInt();
}
ruffleSort(x);
ruffleSort(y);
int m1=(n-1)>>1;
int m2=(n)>>1;
out.println(((long)(x[m2]-x[m1]+1)*(long)(y[m2]-y[m1]+1)));
}
out.close();
}
static PrintWriter out;
static FastReader Fs;
static final Random random = new Random();
static void ruffleSort(int[] a) {
int n = a.length;
for (int i = 0; i < n; ++i) {
int oi = random.nextInt(n), tmp = a[oi];
a[oi] = a[i];
a[i] = tmp;
}
Arrays.sort(a);
}
static class FastReader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public FastReader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public FastReader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String nextLine() throws IOException {
byte[] buf = new byte[64]; // 64 line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
} else {
continue;
}
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public String next() throws IOException {
byte[] buf = new byte[64]; // 64 line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == ' ' || c == '\n') {
if (cnt != 0) {
break;
} else {
continue;
}
}
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;
}
public int[] readArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; ++i)
a[i] = nextInt();
return a;
}
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
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
23715007bd753d30bf4a5d8641bc38d8
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;
public class CodeForcesB {
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;
}
int[] nextArray(int n)
{
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=nextInt();
return arr;
}
}
static boolean palin(char[] arr)
{
if(arr.length==1)
return false;
for(int i=0;i<arr.length/2;i++)
if(arr[i]!=arr[arr.length-1-i])
return false;
return true;
}
static int gcd(int a, int b)
{
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
static boolean palin(String all)
{
for(int i=0;i<all.length()-1;i++)
{
for(int j=0;j<=i;j++)
{
if(palin(all.substring(j,all.length()-i+j).toCharArray()))
return true;
}
}
return false;
}
static void helper(int n,int[] arr,StringBuilder sb)
{
int max=0;
for(int i=1;i<n;i++)
{
if(arr[i]-arr[max]>0)
max=i;
}
for(int i=max;i<n;i++)
sb.append(arr[i]+" ");
if(max>0)
helper(max, arr, sb);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader fs=new FastReader();
PrintWriter out=new PrintWriter(System.out);
//out.print("111");
int T=fs.nextInt();
StringBuilder sb=new StringBuilder();
while(T-->0)
{
int n=fs.nextInt();
//int[] arr=fs.nextArray(n);
//long x=fs.nextLong();
//int[] hnv=new int[n];
//long[] arr=new long[n];
int[] x=new int[n];
int[] y=new int[n];
for(int i=0;i<n;i++)
{
x[i]=fs.nextInt();
y[i]=fs.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
if(n%2!=0)
{
System.out.println(1);
continue;
}
else {
int xi=x[n/2]-x[n/2-1]+1;
int yi=y[n/2]-y[n/2-1]+1;
System.out.println((long)xi*(long)yi);
}
//System.out.println(sb);
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
f90ffc0d27efb26d94b155e9d14b53b4
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
FastOutput out = new FastOutput(System.out);
for(int T = sc.nextInt(); T > 0; --T) {
int n = sc.nextInt();
int[] x = new int[n], y = new int[n];
for(int i = 0; i < n; ++i) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
Arrays.parallelSort(x);
Arrays.parallelSort(y);
System.out.println((long) (x[n/2]-x[(n-1)/2]+1) * (y[n/2]-y[(n-1)/2]+1));
}
}
}
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[] readArrayInt(int fst, int lst) {
int[] a = new int[lst];
for(int i = fst; i < lst; ++i) a[i] = nextInt();
return a;
}
long[] readArrayLong(int fst, int lst) {
long[] a = new long[lst];
for(int i = fst; i < lst; ++i) a[i] = nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
class FastOutput implements AutoCloseable, Closeable, Appendable {
private static final int THRESHOLD = 1 << 13;
private final Writer os;
private StringBuilder cache = new StringBuilder(THRESHOLD * 2);
public FastOutput append(CharSequence csq) {
cache.append(csq);
return this;
}
public FastOutput append(CharSequence csq, int start, int end) {
cache.append(csq, start, end);
return this;
}
private void afterWrite() {
if (cache.length() < THRESHOLD) {
return;
}
flush();
}
public FastOutput(Writer os) {
this.os = os;
}
public FastOutput(OutputStream os) {
this(new OutputStreamWriter(os));
}
public FastOutput append(char c) {
cache.append(c);
afterWrite();
return this;
}
public FastOutput append(int c) {
cache.append(c);
afterWrite();
return this;
}
public FastOutput append(String c) {
cache.append(c);
afterWrite();
return this;
}
public FastOutput println(String c) {
return append(c).println();
}
public FastOutput println() {
return append(System.lineSeparator());
}
public FastOutput flush() {
try {
os.append(cache);
os.flush();
cache.setLength(0);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return this;
}
public void close() {
flush();
try {
os.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public String toString() {
return cache.toString();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
5f52f570a65a365cd35275fad641f939
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
public class Round703B {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn = new Scanner(System.in);
int T = scn.nextInt();
for(int t = 0; t < T; t++) {
int n = scn.nextInt();
long[] x = new long[n];
long[] y = new long[n];
for(int i = 0; i < n; i++) {
x[i] = scn.nextLong();
y[i] = scn.nextLong();
}
if(n % 2 != 0) {
System.out.println(1);
}else {
Arrays.sort(x);
Arrays.sort(y);
long fval = x[n/2];
long sval = x[n/2 -1];
long diff = fval - sval + 1;
long fval2 = y[n/2];
long sval2 = y[n/2 -1];
long diff2 = fval2 - sval2 + 1;
System.out.println(diff*diff2);
}
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
13cefb4bc3e4cbdbe43787bf65e10cda
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class B1486 {
public static void main(String[] args) throws Exception {
int t = i();
for (int i=0; i<t; i++) {
int n = i();
long[][] coords = new long[2][n];
for (int j=0; j<n; j++) {
coords[0][j] = l(); coords[1][j] = l();
}
Arrays.sort(coords[0]);
Arrays.sort(coords[1]);
long ans = 1;
if (n%2==0) ans*=(coords[0][n/2]-coords[0][n/2-1]+1)*(coords[1][n/2]-coords[1][n/2-1]+1);
out.println(ans);
}
in.close();
out.close();
}
static BufferedReader in;
static StringTokenizer st = new StringTokenizer("");
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
// static PrintWriter out;
/*
* static { try { in = Files.newBufferedReader(Paths.get("haybales.in")); out =
* new PrintWriter(new BufferedWriter(new FileWriter("haybales.out"))); } catch
* (Exception e) { in = new BufferedReader(new InputStreamReader(System.in)); }
* }
*/
static {
in = new BufferedReader(new InputStreamReader(System.in));
}
static void check() throws Exception {
while (!st.hasMoreTokens())
st = new StringTokenizer(in.readLine());
}
static String s() throws Exception {
check();
return st.nextToken();
}
static int i() throws Exception {
return Integer.parseInt(s());
}
static long l() throws Exception {
return Long.parseLong(s());
}
static double d() throws Exception {
return Double.parseDouble(s());
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
9fa7948721f7aba7c6d674318a82d756
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.util.Scanner;
import java.io.*;
import javax.lang.model.util.ElementScanner6;
import static java.lang.System.out;
import java.util.Stack;
import java.util.Queue;
import java.util.LinkedList;
public class B1486
{
static int mod=(int)(1e9+7);
static long MOD=(long)(1e9+7);
static FastReader in=new FastReader();
static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static void main(String args[])
{
int tc=1;
tc=in.nextInt();
tcloop: while(tc-->0)
{
int n=in.nextInt();
long x[]=new long[n];
long y[]=new long[n];
long sumx=0;
long sumy=0;
//HashSet<Pair> hs=new HashSet<>();
for(int i=0;i<n;i++)
{
x[i]=in.nextLong();
y[i]=in.nextLong();
}
sort(x);
sort(y);
long ans=(x[n/2]-x[(n-1)/2]+1)*(y[n/2]-y[(n-1)/2]+1);
pr.println(ans);
}
pr.flush();
}
static class Pair implements Comparable<Pair> {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int hashCode() {
return this.x ^ this.y;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Pair other = (Pair) obj;
if (x != other.x)
return false;
if (y != other.y)
return false;
return true;
}
@Override
public int compareTo(Pair o) {
return x - o.y;
}
}
static void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
int[] readIntArray(int n)
{
int a[]=new int[n];
for(int i=0;i<n;i++)a[i]=nextInt();
return a;
}
long[] readLongArray(int n)
{
long a[]=new long[n];
for(int i=0;i<n;i++)a[i]=nextLong();
return a;
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
abd4b24c97d86511534640a772d6269a
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Eastern_Exibition {
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 shuffle(long[] a) {
Random r = new Random();
for (int i = 0; i <= a.length - 2; i++) {
int j = i + r.nextInt(a.length - i);
swap(a, i, j);
}
Arrays.sort(a);
}
public static void swap(long[] a, int i, int j) {
long temp = a[i];
a[i] = a[j];
a[j] = temp;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader t = new FastReader();
PrintWriter o = new PrintWriter(System.out);
int test = t.nextInt();
while (test-- > 0) {
int n = t.nextInt();
long[] x = new long[n];
long[] y = new long[n];
for (int i = 0; i < n; ++i) {
x[i] = t.nextLong();
y[i] = t.nextLong();
}
shuffle(x);
shuffle(y);
long cntx = x[n >> 1] - x[(n - 1) >> 1] + 1;
long cnty = y[n >> 1] - y[(n - 1) >> 1] + 1;
o.println(cntx * cnty);
}
o.flush();
o.close();
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
532fbc175cc51dacc8d7b63df4d7f7c4
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.Arrays;
import java.util.Scanner;
public class B703b {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for(int i=0; i<n; i++){
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
long ans;
if((n&1) == 0){
Arrays.sort(x);
Arrays.sort(y);
int mid1 = (n/2);
int mid2 = (n/2)-1;
long rangeX = (x[mid1]-x[mid2])+1;
long rangeY = (y[mid1]-y[mid2])+1;
ans = rangeX * rangeY;
}
else{
ans=1;
}
System.out.println(ans);
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
972de9e8671a345b227599d8b49e082a
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
public class pcarp{
static int max_value;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int[] x= new int[n];
int[] y= new int[n];
for(int i=0;i<n;i++){
x[i]=sc.nextInt();
y[i]=sc.nextInt();
}
long a = value(x);
long b = value(y);
long ans = a*b;
System.out.println(ans);
}
}
public static long value(int[] arr){
Arrays.sort(arr);
return arr[arr.length/2]-arr[(arr.length-1)/2]+1;
}
static void function(int l, int r, int[] arr, int[] depth, int d){
if(r<l){
return;
}
if(r==l){
depth[l]=d;
return;
}
int m = l;
for(int i=l+1;i<=r;i++){
if(arr[m]<arr[i]){
m=i;
}
}
depth[m]=d;
function(l,m-1,arr,depth,d+1);
function(m+1,r,arr,depth,d+1);
}
static boolean perfectCube(long N)
{
long cube_root;
cube_root = (long)Math.round(Math.cbrt(N));
// If cube of cube_root is equals to N,
// then print Yes Else print No
if (cube_root * cube_root * cube_root == N) {
return true;
}
return false;
}
public static int value(int n){
if(n==0){
return 0;
}
int cnt=0;
while(n>0){
cnt++;
n/=2;
}
return cnt;
}
public static int value1(int n){
int cnt=0;
while(n>1){
cnt++;
n/=2;
}
return cnt;
}
public static String function(String s){
if(check(s)){
return s;
}
if(s.length()==2 && s.charAt(0)==s.charAt(1)){
return "";
}
if(s.charAt(0)==s.charAt(1)){
return function(s.substring(2,s.length()));
}
else{
return function(s.charAt(0)+function(s.substring(1,s.length())));
}
}
static boolean isPowerOfTwo(int n){
if(n==0)
return false;
return (int)(Math.ceil((Math.log(n) / Math.log(2)))) ==
(int)(Math.floor(((Math.log(n) / Math.log(2)))));
}
static boolean isPerfectSquare(double x)
{
if (x >= 0) {
double sr = Math.sqrt(x);
return ((sr * sr) == x);
}
return false;
}
public static boolean isPerfect(int n){
int a = (int)Math.sqrt(n);
if(a*a==n){
return true;
}
return false;
}
public static boolean check(String s){
if(s.length()==1){
return true;
}
for(int i=1;i<s.length();i++){
if(s.charAt(i)==s.charAt(i-1)){
return false;
}
}
return true;
}
public static boolean isPrime(int n){
boolean flag=true;
while(n%2==0){
n=n/2;
flag=false;
}
for(int i=3;i<=Math.sqrt(n);i+=2){
if(n%i==0){
flag=false;
while(n%i==0){
n=n/i;
}
}
}
return flag;
}
public static void dfst(ArrayList<ArrayList<Integer>> graph,int src, int deg,boolean ef, boolean of, boolean[] vis, boolean[] flip, int[] init, int[] goal){
if(vis[src]){
return;
}
vis[src]=true;
if((deg%2==0 && ef) || (deg%2==1 && of)){
init[src]=1-init[src];
}
if(init[src]!=goal[src]){
flip[src]=true;
if(deg%2==0){
ef=!ef;
}
else{
of=!of;
}
}
for(int i=0;i<graph.get(src).size();i++){
if(!vis[graph.get(src).get(i)]){
dfst(graph,graph.get(src).get(i),deg+1,ef,of,vis,flip,init,goal);
}
}
}
public static void dfs(ArrayList<ArrayList<Integer>> graph, int src, int val, boolean[] vis){
vis[src]=true;
int cur_val =0;
for(int i=0;i<graph.get(src).size();i++){
if(!vis[graph.get(src).get(i)]){
cur_val=val+1;
dfs(graph,graph.get(src).get(i),cur_val,vis);
}
if(max_value<cur_val){
max_value=cur_val;
}
cur_val=0;
}
}
public static ArrayList<Integer> pf(int n){
ArrayList<Integer> arr = new ArrayList<>();
boolean flag=false;
while(n%2==0){
flag=true;
n/=2;
}
if(flag){
arr.add(2);
}
for(int i=3;i<=Math.sqrt(n);i++){
if(n%i==0){
arr.add(i);
while(n%i==0){
n/=i;
}
}
}
if(n>1){
arr.add(n);
}
return arr;
}
static int gcd(int a, int b){
if(b==0){
return a;
}
else{
return gcd(b,a%b);
}
}
static boolean function(int n, int i, int[] arr, int sum){
if(sum==0){
return true;
}
if(i==n && sum!=0){
return false;
}
if(sum<arr[i]){
return function(n,i+1,arr,sum);
}
else{
return function(n,i+1,arr,sum-arr[i]) || function(n,i+1,arr,sum);
}
}
public static long fact( long n, long mod){
long res =1;
for(int i=1;i<=n;i++){
res%=mod;
i%=mod;
res=(res*i)%mod;
}
return res;
}
public static long nCk(long n,long k, long mod){
return (fact(n,mod)%mod*modular(fact(k,mod),mod-2,mod)%mod*modular(fact(n-k,mod),mod-2,mod)%mod)%mod;
}
public static long modular(long n, long e, long mod){
long res = 1;
n%=mod;
if (n == 0) return 0;
while(e>0){
if((e&1)==1){
res=(res*n)%mod;
}
e=e>>1;
n=(n*n)%mod;
}
return res;
}
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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
3d2868762f5b169ddc04541d1eb58a78
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
//I give up
public class Main {
public static void main(String[] args) {
// System.in and System.out are input and output streams, respectively.
InputReader r = new InputReader(System.in);
int t= r.nextInt();
while(t-->0){
int n = r.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for(int i = 0; i < n; i++){
x[i] = r.nextInt();
y[i] = r.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
if(n%2!=0)
System.out.println(1);
else{
long a = x[n/2] - x[n/2-1]+1;
long b = y[n/2] - y[n/2-1]+1;
System.out.println(a * b);
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
| |
PASSED
|
0900c5155977cbf3d5bb853199521832
|
train_110.jsonl
|
1613658900
|
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
|
256 megabytes
|
import java.util.*;
import java.io.*;
import java.math.*;
/**
*
* @Har_Har_Mahadev
*/
public class B {
private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353;
private static int N = 0;
public static void process() throws IOException {
int n = sc.nextInt();
long x[] = new long[n];
long y[] = new long[n];
for(int i=0; i<n; i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
ruffleSort(x);
ruffleSort(y);
if(n%2 == 1) {
System.out.println(1);
return;
}
System.out.println((x[n/2] - x[n/2-1]+1) * (y[n/2] - y[n/2-1]+1));
}
//=============================================================================
//--------------------------The End---------------------------------
//=============================================================================
static FastScanner sc;
static PrintWriter out;
public static void main(String[] args) throws IOException {
boolean oj = true;
if (oj) {
sc = new FastScanner();
out = new PrintWriter(System.out);
} else {
sc = new FastScanner(100);
out = new PrintWriter("output.txt");
}
int t = 1;
t = sc.nextInt();
while (t-- > 0) {
process();
}
out.flush();
out.close();
}
static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
return Integer.compare(this.x, o.x);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Pair)) return false;
Pair key = (Pair) o;
return x == key.x && y == key.y;
}
@Override
public int hashCode() {
int result = x;
result = 31 * result + y;
return result;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static void println(Object o) {
out.println(o);
}
static void println() {
out.println();
}
static void print(Object o) {
out.print(o);
}
static void pflush(Object o) {
out.println(o);
out.flush();
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static int max(int x, int y) {
return Math.max(x, y);
}
static int min(int x, int y) {
return Math.min(x, y);
}
static int abs(int x) {
return Math.abs(x);
}
static long abs(long x) {
return Math.abs(x);
}
static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
static long max(long x, long y) {
return Math.max(x, y);
}
static long min(long x, long y) {
return Math.min(x, y);
}
public static int gcd(int a, int b) {
BigInteger b1 = BigInteger.valueOf(a);
BigInteger b2 = BigInteger.valueOf(b);
BigInteger gcd = b1.gcd(b2);
return gcd.intValue();
}
public static long gcd(long a, long b) {
BigInteger b1 = BigInteger.valueOf(a);
BigInteger b2 = BigInteger.valueOf(b);
BigInteger gcd = b1.gcd(b2);
return gcd.longValue();
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
public static int lower_bound(int[] arr, int x) {
int low = 0, high = arr.length, mid = -1;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x)
high = mid;
else
low = mid + 1;
}
return low;
}
public static int upper_bound(int[] arr, int x) {
int low = 0, high = arr.length, mid = -1;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] > x)
high = mid;
else
low = mid + 1;
}
return low;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner() throws FileNotFoundException {
br = new BufferedReader(new InputStreamReader(System.in));
}
FastScanner(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;
}
int[] readArray(int n) throws IOException {
int[] A = new int[n];
for (int i = 0; i != n; i++) {
A[i] = sc.nextInt();
}
return A;
}
long[] readArrayLong(int n) throws IOException {
long[] A = new long[n];
for (int i = 0; i != n; i++) {
A[i] = sc.nextLong();
}
return A;
}
}
static void ruffleSort(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
}
|
Java
|
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
|
1 second
|
["1\n4\n4\n4\n3\n1"]
|
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
|
Java 8
|
standard input
|
[
"binary search",
"geometry",
"shortest paths",
"sortings"
] |
e0a1dc397838852957d0e15ec98d5efe
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
| 1,500
|
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
|
standard output
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.