Search is not available for this dataset
name
stringlengths 2
112
| description
stringlengths 29
13k
| source
int64 1
7
| difficulty
int64 0
25
| solution
stringlengths 7
983k
| language
stringclasses 4
values |
---|---|---|---|---|---|
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int n;
int a, b, c, d;
int main() {
scanf("%d", &n);
printf("YES\n");
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("%d\n", ((2 * (a % 2) + (b % 2)) % 4 + 4) % 4 + 1);
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
int n;
scanf("%d", &n);
puts("YES");
for (int i = 0; i < n; i++) {
int x1, y1, x2, y2;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
if (x1 & 1 && y1 & 1) {
puts("1");
} else if (x1 & 1 && !(y1 & 1)) {
puts("2");
} else if (!(x1 & 1) && y1 & 1) {
puts("3");
} else {
puts("4");
}
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const long long maxn = 200010;
long long n, a, b, c, d;
long long dz = 1e9;
long long cd[2][2] = {{1, 2}, {3, 4}};
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
cout << "YES" << endl;
for (long long i = 0; i < (long long)(n); i++) {
cin >> a >> b >> c >> d;
if (a > c) swap(a, c);
if (b > d) swap(b, d);
cout << cd[(c + dz) % 2][(d + dz) % 2] << endl;
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
scanf("%d", &n);
puts("YES");
for (int i = 0; i < n; i++) {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("%d\n", ((12 + 2 * (a % 2) + (b % 2)) % 4) + 1);
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.ArrayList;
public class D {
static class Scanner{
BufferedReader br=null;
StringTokenizer tk=null;
public Scanner(){
br=new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException{
while(tk==null || !tk.hasMoreTokens()) {
String cad = br.readLine();
if (cad == null)
return null;
tk=new StringTokenizer(cad);
}
return tk.nextToken();
}
public int nextInt() throws NumberFormatException, IOException{
return Integer.valueOf(next());
}
public long nextLong() throws NumberFormatException, IOException{
return Long.valueOf(next());
}
public double nextDouble() throws NumberFormatException, IOException{
return Double.valueOf(next());
}
}
public static void main(String args[]) throws NumberFormatException, IOException{
Scanner sc = new Scanner();
int N = sc.nextInt();
System.out.println("YES");
for(int i = 0; i < N; i++) {
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
System.out.println(2*(x1 & 1) + (y1 & 1) + 1);
}
}
}
| JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
printf("YES\n");
int a, b, c, d;
for (int i = 0; i < n; i++) {
scanf("%d%d%d%d", &a, &b, &c, &d);
if (a < 0) a *= -1;
if (b < 0) b *= -1;
if (c < 0) c *= -1;
if (d < 0) d *= -1;
if ((a & 1) && (b & 1))
printf("4\n");
else if ((a & 1) == 0 && (b & 1))
printf("1\n");
else if ((a & 1) && (b & 1) == 0)
printf("2\n");
else
printf("3\n");
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n = int(input())
print("YES")
for i in range(n):
x1, y1, x2, y2 = map(int, input().split())
print((x1 % 2) * 2 + (y1 % 2) + 1) | PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
printf("YES\n");
for (int i = 1; i <= n; i++) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
if (x1 % 2 == 0) {
if (y1 % 2 == 0)
printf("1\n");
else
printf("2\n");
} else {
if (y1 % 2 == 0)
printf("3\n");
else
printf("4\n");
}
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << "YES\n";
for (int i = 1; i <= n; i++) {
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << (2 * ((x1 % 2 + 2) % 2) + (y1 % 2 + 2) % 2) + 1 << "\n";
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author littlesheep
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskD solver = new TaskD();
solver.solve(1, in, out);
out.close();
}
static class TaskD {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
out.println("YES");
for (int i = 0; i < n; ++i) {
int x1, y1, x2, y2;
x1 = in.nextInt();
y1 = in.nextInt();
x2 = in.nextInt();
y2 = in.nextInt();
out.println(Math.abs(x1 % 2) * 2 + Math.abs(y1 % 2) + 1);
}
}
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (Exception e) {
throw new UnknownError();
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n = int(input())
print("YES")
for i in range(n):
t1, y1, x2, y2 = input().split()
print((int(t1) % 2) * 2 + (int(y1) % 2) + 1) | PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int x[500500];
int y[500500];
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++) {
int tmp1, tmp2;
scanf("%d%d%d%d", &x[i], &y[i], &tmp1, &tmp2);
}
puts("YES");
for (int i = 1; i <= n; i++) {
if (x[i] < 0) x[i] = -x[i];
if (y[i] < 0) y[i] = -y[i];
if (x[i] % 2 == 1 && y[i] % 2 == 1)
puts("1");
else if (x[i] % 2 == 1 && y[i] % 2 == 0)
puts("2");
else if (x[i] % 2 == 0 && y[i] % 2 == 1)
puts("3");
else
puts("4");
}
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int dx44[5] = {0, -1, -1, 1, 1};
const int dy44[5] = {0, -1, 1, -1, 1};
const int dx4[5] = {0, -1, 0, 1, 0};
const int dy4[5] = {0, 0, 1, 0, -1};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int maxn = 5e5 + 5;
const double PI = acos(-1.0);
const long long mod = 1e9 + 7;
long long po(long long a, long long b, long long mod) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long gcd(long long a, long long b) {
if (a == 0) {
return b;
} else {
return gcd(b % a, a);
}
}
void YES() {
puts("YES");
exit(0);
}
void Yes() { puts("Yes"); }
void NO() {
puts("NO");
exit(0);
}
void No() { puts("No"); }
void one() {
puts("-1");
exit(0);
}
int ans[maxn];
void solve() {
int n;
scanf("%d", &(n));
for (int i = 1; i <= n; i++) {
int xx1, xx2, yy1, yy2;
scanf("%d", &(xx1)), scanf("%d", &(yy1)), scanf("%d", &(xx2)),
scanf("%d", &(yy2));
xx1 = abs(xx1);
yy1 = abs(yy1);
if ((xx1 % 2 == 0) && (yy1 % 2 == 0)) ans[i] = 1;
if ((xx1 % 2 == 0) && (yy1 % 2 == 1)) ans[i] = 2;
if ((xx1 % 2 == 1) && (yy1 % 2 == 0)) ans[i] = 3;
if ((xx1 % 2 == 1) && (yy1 % 2 == 1)) ans[i] = 4;
}
puts("YES");
for (int i = 1; i <= n; i++) {
printf("%d\n", ans[i]);
}
}
int main() {
solve();
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
template <typename T>
bool maxup(T& a, const T&& b) {
if (a < b) {
a = b;
return true;
};
}
template <typename T>
bool maxup(T& a, const T& b) {
if (a < b) {
a = b;
return true;
};
}
template <typename T>
bool minup(T& a, const T&& b) {
if (a > b) {
a = b;
return true;
};
}
template <typename T>
bool minup(T& a, const T& b) {
if (a > b) {
a = b;
return true;
};
}
using VV = vector<vector<long long>>;
using V = vector<long long>;
using P = pair<long long, long long>;
using IP = pair<long long, P>;
template <typename T>
inline void input(vector<T>& v) {
for (auto& x : v) cin >> x;
}
signed main() {
long long n;
cin >> n;
cout << "YES" << endl;
for (signed i = signed(0); i < signed(n); i++) {
long long x, y, p, q;
cin >> x >> y >> p >> q;
cout << (((abs(x) % 2) << 1) | abs(y) % 2) + 1 << endl;
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int x[500500];
int y[500500];
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++) {
int tmp1, tmp2;
scanf("%d%d%d%d", &x[i], &y[i], &tmp1, &tmp2);
}
printf("YES\n");
for (int i = 1; i <= n; i++) {
if (x[i] < 0) x[i] = -x[i];
if (y[i] < 0) y[i] = -y[i];
if (x[i] % 2 == 1 && y[i] % 2 == 1)
printf("1\n");
else if (x[i] % 2 == 1 && y[i] % 2 == 0)
printf("2\n");
else if (x[i] % 2 == 0 && y[i] % 2 == 1)
printf("3\n");
else
printf("4\n");
}
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
cout << "YES\n";
for (int i = 0; i < n; ++i) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << (x1 & 1) + ((y1 & 1) << 1) + 1 << endl;
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | '''plan
noticed that if both upperle
'''
from sys import stdin, stdout
n = int(stdin.readline().rstrip())
# n = int(input())
coordinates = []
# for i in range(n):
# coordinates.append([int(x) % 2 for x in input().split()])
for i in range(n):
coordinates.append([int(x) % 2 for x in stdin.readline().rstrip().split()])
stdout.write('YES\n')
for coordinate in coordinates:
x1, y1, x2, y2 = coordinate
stdout.write(str(2 * x2 + y2 + 1) + '\n')
| PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e3;
const int INF = 1e9;
int main() {
int n;
cin >> n;
cout << "YES\n";
for (int i = 0; i < n; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1 += INF;
y1 += INF;
int r = (x1 % 2) * 2 + (y1 % 2) + 1;
cout << r << endl;
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 |
import java.io.*;
import java.util.*;
/**
*
* @author Sourav Kumar Paul (spaul100)
* NIT Silchar
*/
public class SolveD {
public static Reader in;
public static PrintWriter out;
public static long mod = 1000000007;
public static long inf = 100000000000000000l;
public static long fac[],inv[];
public static int union[];
public static void solve(){
int n = in.nextInt();
Pair pair[] = new Pair[n];
out.println("YES");
for(int i=0; i<n; i++)
{
pair[i] = new Pair(Math.abs(in.nextInt()), Math.abs(in.nextInt()), in.nextInt(), in.nextInt(), i);
if(pair[i].x1 %2==1 && pair[i].y1 %2==1)
out.println(1);
else if(pair[i].x1 %2==1 && pair[i].y1%2==0)
out.println(2);
else if(pair[i].x1%2==0 && pair[i].y1%2==1)
out.println(3);
else
out.println(4);
}
}
private static boolean check(Pair ff, Pair ss) {
if((ff.x1 - ss.x2 == 0) && Math.min(ff.y2, ss.y2) - Math.max(ff.y1,ss.y1) >0)
return true;
if((ff.y1 - ss.y2 ==0 ) && (Math.min(ff.x2, ss.x2) - Math.max(ff.x1,ss.x1) >0))
return true;
if((ss.y1- ff.y2 ==0) && (Math.min(ff.x2,ss.x2) - Math.max(ff.x1, ss.x1) > 0))
return true;
return false;
}
/**
* ############################### Template ################################
*/
public static class Pair implements Comparable{
int x1,y1,x2,y2, ind;
Pair(int x1, int y1, int x2, int y2, int ind)
{
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.ind = ind;
}
@Override
public int compareTo(Object o)
{
Pair pp = (Pair)o;
if(pp.x1 == x1)
{
if(pp.y1 == y1)
return 0;
else if(y1>pp.y1)
return 1;
else
return -1;
}
else if (x1>pp.x1)
return 1;
else
return -1;
}
}
public static void init()
{
for(int i=0; i<union.length; i++)
union[i] = i;
}
public static int find(int n)
{
return (union[n]==n)?n:(union[n]=find(union[n]));
}
public static void unionSet(int i ,int j)
{
union[find(i)]=find(j);
}
public static boolean connected(int i,int j)
{
return union[i]==union[j];
}
public static long gcd(long a, long b) {
long x = Math.min(a,b);
long y = Math.max(a,b);
while(x!=0)
{
long temp = x;
x = y%x;
y = temp;
}
return y;
}
public static long modPow(long base, long exp, long mod) {
base = base % mod;
long result =1;
while(exp > 0)
{
if(exp % 2== 1)
{
result = (result * base) % mod;
exp --;
}
else
{
base = (base * base) % mod;
exp = exp >> 1;
}
}
return result;
}
public static void cal()
{
fac = new long[1000005];
inv = new long[1000005];
fac[0]=1;
inv[0]=1;
for(int i=1; i<=1000000; i++)
{
fac[i]=(fac[i-1]*i)%mod;
inv[i]=(inv[i-1]*modPow(i,mod-2,mod))%mod;
}
}
public static long ncr(int n, int r)
{
return (((fac[n]*inv[r])%mod)*inv[n-r])%mod;
}
SolveD() throws IOException {
in = new Reader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
solve();
out.flush();
out.close();
}
public static void main(String args[]) {
new Thread(null, new Runnable() {
public void run() {
try {
new SolveD();
} catch (Exception e) {
e.printStackTrace();
}
}
}, "1", 1 << 26).start();
}
public static class Reader {
public BufferedReader reader;
public StringTokenizer st;
public Reader(InputStreamReader stream) {
reader = new BufferedReader(stream);
st = null;
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public String nextLine() throws IOException{
return reader.readLine();
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
}
}
| JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskD solver = new TaskD();
solver.solve(1, in, out);
out.close();
}
static class TaskD {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.readInt();
int[][] ans = new int[2][];
ans[0] = new int[]{1, 2};
ans[1] = new int[]{3, 4};
out.println("YES");
while (n-- > 0) {
int x1 = Math.abs(in.readInt());
int y1 = Math.abs(in.readInt());
in.readInt();
in.readInt();
out.println(ans[x1 % 2][y1 % 2]);
}
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
int n;
int main() {
scanf("%d", &n);
puts("YES");
for (int i = 0, x, y, _, __; i < n; ++i) {
scanf("%d%d%d%d", &x, &y, &_, &__);
printf("%d\n", (((x & 1) << 1) | (y & 1)) + 1);
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int n, x[maxn], y[maxn], xx[maxn], yy[maxn];
int ans[maxn];
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++) {
scanf("%d %d %d %d", &x[i], &y[i], &xx[i], &yy[i]);
x[i] = min(x[i], xx[i]);
y[i] = max(y[i], yy[i]);
}
for (int i = 1; i <= n; i++) {
ans[i] = 2 * (abs(x[i]) % 2) + abs(y[i]) % 2 + 1;
}
puts("YES");
for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
long long n, a, b, c, d;
cout << "YES\n";
cin >> n;
while (n--) {
cin >> a >> b >> c >> d;
cout << abs(c % 2) + 1 + 2 * abs(d % 2) << "\n";
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | from sys import stdin,stdout
n = int(stdin.readline())
stdout.write("YES")
stdout.write('\n')
for i in range(n):
x1, y1, x2, y2 = map(int,stdin.readline().split())
stdout.write(str((x1 % 2) * 2 + (y1 % 2) + 1))
stdout.write('\n')
| PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | /**
* Created by tagirov2 on 28.06.2017.
*/
import java.util.*;
import java.io.*;
public class Sample02_01
{
public static void main (String [] param)
{
boolean oj = System.getProperty ("ONLINE_JUDGE") != null;
Scanner in = new Scanner (System.in);
PrintWriter out = new PrintWriter (System.out);
FileReader reader;
Writer writer;
if ( ! oj )
{
try
{
reader = new FileReader ("C:\\TRR\\2017\\Task\\07 Codeforces\\022\\D.TXT");
in = new Scanner (reader);
}
catch (IOException ex)
{
System.out.println(ex.getMessage());
}
try
{
writer = new FileWriter("C:\\TRR\\2017\\Task\\07 Codeforces\\022\\D.OUT", false);
out = new PrintWriter(writer);
}
catch (IOException ex)
{
System.out.println(ex.getMessage());
}
}
int n = in.nextInt();
if ( ! oj )
{
out.print("n = " + n);
}
out.println ("YES");
for ( int i=0; i < n; i++ )
{
int x = in.nextInt () % 2;
int y = in.nextInt () % 2;
in.nextInt (); in.nextInt ();
if ( x == 0 && y == 0 )
out.println ("1");
else if ( x == 0 && y != 0 )
out.println ("2");
else if ( x != 0 && y == 0 )
out.println ("3");
else
out.println ("4");
}
out.flush();
}
}
| JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
inline void EnableFileIO(const string& fileName) {
if (fileName.empty()) return;
freopen((fileName + ".in").c_str(), "r", stdin);
freopen((fileName + ".out").c_str(), "w", stdout);
return;
}
const long long INF = 1e9;
const double EPS = 1e-10;
const int N = 5e5 + 100;
int n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
EnableFileIO("");
cin >> n;
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
long long a, b, c, d;
cin >> a >> b >> c >> d;
a += INF, b += INF, c += INF, d += INF;
if ((a & 1) && (b & 1)) {
cout << 1 << endl;
} else if ((a & 1)) {
cout << 2 << endl;
} else if ((b & 1)) {
cout << 3 << endl;
} else {
cout << 4 << endl;
}
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
inline int read() {
char c = getchar();
int x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
int n, x, y;
int main(int argc, const char* argv[]) {
n = read();
puts("YES");
for (int i = 1; i <= n; i++) {
x = read();
y = read();
x = min(x, read());
y = min(y, read());
x += 1e9;
y += 1e9;
if (x & 1) {
if (y & 1)
puts("1");
else
puts("2");
} else {
if (y & 1)
puts("3");
else
puts("4");
}
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package Round_395_Div_2;
import java.util.Scanner;
/**
*
* @author DAFFODIL
*/
public class D
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x1, y1, x2, y2;
System.out.println("YES");
for(int i=0;i<n;i++)
{
x1 = sc.nextInt();
y1 = sc.nextInt();
x2 = sc.nextInt();
y2 = sc.nextInt();
int c = ((12 + 2 * (x1 % 2) + (y1 % 2)) % 4) + 1;
System.out.println(c);
}
}
}
| JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* @author Don Li
*/
public class TimofeyRectangles {
void solve() {
int n = in.nextInt();
out.println("YES");
for (int i = 0; i < n; i++) {
int x1 = in.nextInt(), y1 = in.nextInt(), x2 = in.nextInt(), y2 = in.nextInt();
out.printf("%d%n", (x1 % 2 + y1 % 2 * 2 + 4) % 4 + 1);
}
}
public static void main(String[] args) {
in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
out = new PrintWriter(System.out);
new TimofeyRectangles().solve();
out.close();
}
static FastScanner in;
static PrintWriter out;
static class FastScanner {
BufferedReader in;
StringTokenizer st;
public FastScanner(BufferedReader in) {
this.in = in;
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
}
}
| JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n = int(input())
a = [0 for i in range(n)]
for i in range(n):
inp = input().split()
x = int(inp[0])
y = int(inp[1])
a[i] = 2 * (x % 2) + (y % 2) + 1
print("YES")
print("\n".join(str(i) for i in a))
| PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, x1, y1, x2, y2;
cin >> n;
cout << "YES" << '\n';
for (int i = 1; i <= n; i++) {
cin >> x1 >> y1 >> x2 >> y2;
if ((x1 % 2 + 2) % 2 == 1) {
if ((y1 % 2 + 2) % 2 == 1)
cout << "1" << '\n';
else
cout << "2" << '\n';
} else {
if ((y1 % 2 + 2) % 2 == 1)
cout << "3" << '\n';
else
cout << "4" << '\n';
}
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int n, a, b, c, d;
int main() {
scanf("%d", &n);
printf("YES\n");
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("%d\n", 1 + 2 * (abs(a) % 2) + abs(b) % 2);
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int Z = (int)1e5 + 111;
const int INF = (int)1e9 + 111;
int main() {
int n, x1, x2, y1, y2;
scanf("%d", &n);
printf("YES\n");
while (n--) {
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1 = min(x1, x2);
y1 = min(y1, y2);
if (x1 % 2 && !(y1 % 2))
cout << 4 << '\n';
else
cout << 1 + abs(x1 % 2) + abs(y1 % 2) << '\n';
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | import java.io.*;
import java.util.LinkedList;
import java.util.Objects;
import java.util.StringTokenizer;
import java.util.TreeSet;
public final class Main {
static char[] chars = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
static char[] chars1 = {'#', '*', '&'};
static char[] chars2 = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
static boolean oneColor = true;
// x1<0
// x1+k*2>0;
// k*2>-x1;
// k=-x1/2
public void solve() {
int n = in.nextInt();
out.println("YES");
for (int i = 0; i < n; i++) {
int x1 = in.nextInt();
int y1 = in.nextInt();
int x2 = in.nextInt();
int y2 = in.nextInt();
if (x1 < 0) {
double k = (double)(-x1) / 2;
x1=(int)(k*2)+2;
}
if (y1 < 0) {
double k = (double)(-y1) / 2;
y1=(int)(k*2)+2;
}
out.println(2 * (x1 % 2) + (y1 % 2) + 1);
}
}
public void check(TreeSet<Integer>[] a, int index, int maincolor, int c[], TreeSet<Integer> is) {
if (c[index] != maincolor) {
oneColor = false;
return;
}
if (a[index] != null) {
for (int i : a[index]) {
if (!is.contains(i)) {
is.add(i);
check(a, i, maincolor, c, is);
}
}
}
}
static class Library {
static boolean isPrime(int a) {
if (a == 1) {
return false;
}
for (int i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
static long bpow(long x, long n, long m) {
long count = 1;
if (n == 0) {
return 1;
}
while (n > 0) {
if ((n & 1) == 1) {
count *= x;
count %= m;
}
x *= x;
x %= m;
n >>= 1;
}
return count % m;
}
static long GCD(long a, long b) {
if (b == 0) return a;
return GCD(b, a % b);
}
}
class Pair<X, Y> implements Comparable<Pair<X, Y>> {
public X first;
public Y second;
public Pair(X first, Y second) {
this.first = first;
this.second = second;
}
@Override
public int hashCode() {
int hash = 7;
hash = 11 * hash + Objects.hashCode(this.first);
hash = 11 * hash + Objects.hashCode(this.second);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Pair<?, ?> other = (Pair<?, ?>) obj;
if (!Objects.equals(this.first, other.first)) {
return false;
}
if (!Objects.equals(this.second, other.second)) {
return false;
}
return true;
}
@Override
public int compareTo(Pair<X, Y> p) {
return ((Comparable<X>) first).compareTo(p.first);
}
@Override
public String toString() {
return first + " " + second;
}
}
class Node<E> {
E element;
Node<E> next;
Node<E> prev;
Node(E element, Node next, Node prev) {
this.element = element;
this.next = next;
this.prev = prev;
}
}
// -------------I/O------------- \\
private FScanner in;
private PrintWriter out;
public static void main(String[] args) {
new Main().runIO();
}
void run() {
try {
in = new FScanner(new File("input.txt"));
out = new PrintWriter(new BufferedWriter(new FileWriter(new File("output.txt"))));
solve();
out.close();
in.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
void runIO() {
in = new FScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
solve();
out.close();
in.close();
}
class FScanner {
private BufferedReader br;
private StringTokenizer st;
public FScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
void useString(String s) {
if (s != null) {
st = new StringTokenizer(s);
}
}
void updateST() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
}
String next() {
updateST();
return st.nextToken();
}
Long[] nextLongArray() {
updateST();
LinkedList<Long> ll = new LinkedList<>();
while (st.hasMoreElements()) {
ll.add(Long.parseLong(st.nextToken()));
}
Long[] arr = new Long[1];
return ll.toArray(arr);
}
Integer[] nextIntArray() {
updateST();
LinkedList<Integer> ll = new LinkedList<>();
while (st.hasMoreElements()) {
ll.add(Integer.parseInt(st.nextToken()));
}
Integer[] arr = new Integer[1];
return ll.toArray(arr);
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
updateST();
StringBuilder sb = new StringBuilder(st.nextToken());
while (st.hasMoreElements()) {
sb.append(st.nextToken());
}
return sb.toString();
}
void close() {
try {
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
} | JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | print('YES')
for _ in range(int(input())):
a,b,c,d = map(int,input().split())
print((2*(a%2))+(b%2)+1) | PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class D {
public static void main(String[] args) throws Exception {
FastScanner scan = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int n = scan.nextInt();
out.println("YES");
for(int i = 0; i < n; i++){
int a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt(), d = scan.nextInt();
out.println(2*(a&1) + (b&1) + 1);
}
out.close();
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine());
} catch (Exception e){e.printStackTrace();}
}
public String next() {
if (st.hasMoreTokens()) return st.nextToken();
try {st = new StringTokenizer(br.readLine());}
catch (Exception e) {e.printStackTrace();}
return st.nextToken();
}
public int nextInt() {return Integer.parseInt(next());}
public long nextLong() {return Long.parseLong(next());}
public double nextDouble() {return Double.parseDouble(next());}
public String nextLine() {
String line = "";
try {line = br.readLine();}
catch (Exception e) {e.printStackTrace();}
return line;
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for(int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n){
long[] a = new long[n];
for(int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
public double[] nextDoubleArray(int n){
double[] a = new double[n];
for(int i = 0; i < n; i++) a[i] = nextDouble();
return a;
}
public char[][] nextGrid(int n, int m){
char[][] grid = new char[n][m];
for(int i = 0; i < n; i++) grid[i] = next().toCharArray();
return grid;
}
}
} | JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int aa[2000600];
int haha[2000600];
int main() {
int n;
scanf("%d", &n);
int x, y;
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
scanf("%d%d", &x, &y);
if (x % 2 == 0) {
if (y % 2 == 0)
cout << 1 << endl;
else
cout << 2 << endl;
} else {
if (y % 2 == 0)
cout << 3 << endl;
else
cout << 4 << endl;
}
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int n;
int main() {
scanf("%d", &n);
puts("YES");
for (int i = 0; i < n; ++i) {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
printf("%d\n", 2 * (a & 1) + (b & 1) + 1);
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x1, y1, x2, y2;
cin >> n;
cout << "YES\n";
for (long long i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2;
long long a = abs(x1 % 2), b = abs(y1 % 2);
cout << a * 2 + b + 1 << "\n";
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n = int(input())
rectangles = []
for i in range(n):
a, b, c, d = tuple(map(int,input().split()))
rectangles.append((a,b))
print("YES")
for i in range(n):
a,b = rectangles[i][0], rectangles[i][1]
if a%2 == 0 and b%2 == 0:
print(1)
elif a%2 == 0 and b%2 == 1:
print(2)
elif a%2 == 1 and b%2 == 0:
print(3)
else:
print(4)
| PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int n, a, b, c, d;
int main() {
puts("YES");
scanf("%d", &n);
while (n--) {
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("%d\n", ((a & 1) << 1) + (b & 1) + 1);
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
int main() {
int n;
printf("YES\n");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x1, y1, x2, y2;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
printf("%d\n", ((12 + 2 * (x1 % 2) + (y1 % 2)) % 4) + 1);
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n = input()
print "YES"
for _ in range(n):
a,b,c,d = map(int, raw_input().split())
a = min(a, c)
b = min(b, d)
print 1+(a%2)*2+b%2
| PYTHON |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x1, y1, x2, y2;
scanf("%d", &n);
puts("YES");
while (n--) {
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1 = abs(x1);
y1 = abs(y1);
if (x1 % 2 == 1 && y1 % 2 == 1)
puts("1");
else if (x1 % 2 == 0 && y1 % 2 == 1)
puts("2");
else if (x1 % 2 == 1 && y1 % 2 == 0)
puts("3");
else
puts("4");
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int n, a, b, c, d;
int main() {
cin >> n, puts("YES");
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("%d\n", 1 + (a & 1) + ((b & 1) << 1));
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n=input()
print "YES"
for i in range(n):
x1,y1,x2,y2=map(int,raw_input().split(" "))
if x1%2==0 and y1%2==0:
print 1
elif (x1%2==0 and y1%2!=0):
print 2
elif (x1%2!=0 and y1%2!=0):
print 3
else:
print 4
| PYTHON |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | '''plan
noticed that if both upperle
'''
from sys import stdin, stdout
# n = int(stdin.readline().rstrip())
# n = int(input())
all_lines = stdin.read().split('\n')
stdout.write('YES\n')
for line in all_lines[1:-1]:
x1, y1, x2, y2 = (int(x) % 2 for x in line.split())
num = 2 * x2 + y2 + 1
# stdout.write(str(x2) + ' ' + str(y2) + '\n')
print(str(num) + '\n')
#stdout.flush()
#exit()
# for i in range(n):
# coordinates.append([int(x) % 2 for x in input().split()])
# for i in range(n):
# coordinates.append([int(x) % 2 for x in stdin.readline().rstrip().split()])
# stdout.write('YES\n')
# for coordinate in coordinates:
# x1, y1, x2, y2 = coordinate
# stdout.write(str(2 * x2 + y2 + 1) + '\n')
| PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int mod = 1000000007;
const double pi = acos(-1.0);
inline void gn(long long& x) {
int sg = 1;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
c == '-' ? (sg = -1, x = 0) : (x = c - '0');
while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
x *= sg;
}
inline void gn(int& x) {
long long t;
gn(t);
x = t;
}
inline void gn(unsigned long long& x) {
long long t;
gn(t);
x = t;
}
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
long long powmod(long long a, long long x, long long mod) {
long long t = 1ll;
while (x) {
if (x & 1) t = t * a % mod;
a = a * a % mod;
x >>= 1;
}
return t;
}
const int maxn = 5e5 + 5;
int dx[] = {0, 0, 1, 1};
int dy[] = {0, 1, 1, 0};
int main() {
int n;
gn(n);
puts("YES");
for (int i = (1); i <= (n); i++) {
int a, b, c, d;
gn(a);
gn(b);
gn(c);
gn(d);
a = abs(a);
b = abs(b);
a = a % 2;
b = b % 2;
for (int i = (0); i <= (3); i++) {
if (a == dx[i] && b == dy[i]) printf("%d\n", i + 1);
}
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | import java.io.*;
import java.util.*;
import java.math.*;
public class utkarsh {
InputStream is;
PrintWriter out;
void solve(){
//Enter code here
out.println("YES");
int a,b,c,d;
int n=ni();
for(int i=0; i<n; i++){
a=ni();
b=ni();
c=ni();
d=ni();
int ans=1;
if(a%2==0){
ans+=2;
}
if(b%2==0){
ans++;
}
out.println(ans);
}
}
public static void main(String[] args) {
utkarsh play=new utkarsh();
play.run();
}
void run(){
is=System.in;
out=new PrintWriter(System.out);
solve();
out.flush();
}
byte input[]=new byte[1024];
int len=0,ptr=0;
int readByte(){
if(ptr>=len){
ptr=0;
try{
len=is.read(input);
}catch(IOException e){
throw new InputMismatchException();
}
if(len<=0){
return -1;
}
}
return input[ptr++];
}
boolean isSpaceChar(int c){
return !( c >= 33 && c <= 126 );
}
int skip(){
int b=readByte();
while(b!=-1 && isSpaceChar(b)){
b=readByte();
}
return b;
}
char nc(){
return (char)skip();
}
String ns(){
int b=skip();
StringBuilder sb=new StringBuilder();
while(!isSpaceChar(b)){
sb.appendCodePoint(b);
b=readByte();
}
return sb.toString();
}
int ni(){
int n=0,b=readByte();
boolean minus=false;
while(b!=-1 && !( (b>='0' && b<='9') || b=='-')){
b=readByte();
}
if(b=='-'){
minus=true;
b=readByte();
}
while(b>='0' && b<='9'){
n=n*10 + (b - '0');
b=readByte();
}
return minus ? -n : n;
}
long nl(){
long n=0L;
int b=readByte();
boolean minus=false;
while(b!=-1 && !( (b>='0' && b<='9') || b=='-')){
b=readByte();
}
if(b=='-'){
minus=true;
b=readByte();
}
while(b>='0' && b<='9'){
n=n*10 + (b - '0');
b=readByte();
}
return minus ? -n : n;
}
double nd(){
return Double.parseDouble(ns());
}
float nf(){
return Float.parseFloat(ns());
}
int[] na(int n){
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=ni();
}
return a;
}
char[] ns(int n){
char c[]=new char[n];
int i,b=skip();
for(i=0;i<n;i++){
if(isSpaceChar(b)){
break;
}
c[i]=(char)b;
b=readByte();
}
return i==n ? c : Arrays.copyOf(c,i);
}
} | JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n = int(input())
print("YES")
for i in range(n):
z1, y1, x2, y2 = input().split()
print((int(z1) % 2) * 2 + (int(y1) % 2) + 1) | PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
int main() {
int n, a, b, c, d;
cin >> n;
puts("YES");
while (n--) {
cin >> a >> b >> c >> d;
cout << 1 + 2 * (abs(a) % 2) + (abs(b) % 2) << endl;
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y, z;
cin >> n;
cout << "YES\n";
while (n--) {
cin >> x >> y >> z >> z;
cout << ((x & 1) * 2 + (y & 1) + 1) << '\n';
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
inline void ri(int &x) {
x = 0;
static char c;
bool t = 0;
while (c = getchar(), c < '0' || c > '9')
if (c == '-')
t = 1;
else
t = 0;
do x = x * 10 + c - '0';
while (c = getchar(), c >= '0' && c <= '9');
if (t) x = -x;
}
int main() {
int i, T, l, r, u, d;
ri(T);
cout << "YES\n";
while (T--) {
ri(l);
ri(u);
ri(r);
ri(d);
l = abs(min(l, r));
u = abs(min(u, d));
if ((l & 1) && (u & 1)) puts("1");
if ((l & 1) && (~u & 1)) puts("2");
if ((~l & 1) && (u & 1)) puts("3");
if ((~l & 1) && (~u & 1)) puts("4");
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
using itn = int;
const long double PI = 3.141592653589793238;
long long pow(long long x, long long pw) {
long long res = 1;
for (; pw; pw >>= 1) {
if (pw & 1) {
res *= x;
}
x = x * x;
}
return res;
}
void NO() {
cout << "NO";
exit(0);
}
long long gcd(long long a, long long b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
long long lcd(long long a, long long b) { return a * b / gcd(a, b); }
long long INF = 1000L * 1000L * 1000L + 150L;
long long n;
struct Rect {
long long x1, x2, y1, y2;
Rect(long long x1, long long x2, long long y1, long long y2)
: x1(x1), x2(x2), y1(y1), y2(y2) {}
bool hor(Rect other) {
return (x1 == other.x2 || x2 == other.x1) &&
!(y1 >= other.y2 || other.y1 >= y2);
}
bool vert(Rect other) {
return (y1 == other.y2 || y2 == other.y1) &&
!(x1 >= other.x2 || other.x1 >= x2);
}
};
vector<Rect> r;
map<int, vector<int> > X;
map<int, vector<int> > Y;
map<int, int> cX;
map<int, int> cY;
set<int> usedX;
set<int> usedY;
void dfsx(int v, int c) {
usedX.insert(v);
cX[v] = c;
for (int u : X[v]) {
if (usedX.count(u)) {
continue;
}
dfsx(u, 1 - c);
}
}
void dfsy(int v, int c) {
usedY.insert(v);
cY[v] = c;
for (int u : Y[v]) {
if (usedY.count(u)) {
continue;
}
dfsy(u, 1 - c);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; ++i) {
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
r.emplace_back(x1, x2, y1, y2);
X.emplace(x1, vector<int>());
X[x1].push_back(x2);
X[x2].push_back(x1);
Y.emplace(y1, vector<int>());
Y[y1].push_back(y2);
Y[y2].push_back(y1);
}
for (int k = 0; k < n; ++k) {
int x = r[k].x1;
if (!usedX.count(x)) {
dfsx(x, 0);
}
}
for (int k = 0; k < n; ++k) {
int y = r[k].y1;
if (!usedY.count(y)) {
dfsy(y, 0);
}
}
cout << "YES\n";
for (int j = 0; j < n; ++j) {
cout << (cX[r[j].x1] + 2 * cY[r[j].y1] + 1) << "\n";
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
vector<pair<int, int> > po(4);
cin >> po[0].first >> po[0].second;
cin >> po[1].first >> po[1].second;
po[2].first = po[0].first;
po[2].second = po[1].second;
po[3].first = po[1].first;
po[3].second = po[0].second;
sort(po.begin(), po.end());
if (po[0].first % 2 == 0 and po[0].second % 2 == 0)
cout << 1 << endl;
else if (po[0].first % 2 != 0 and po[0].second % 2 == 0)
cout << 2 << endl;
else if (po[0].first % 2 == 0 and po[0].second % 2 != 0)
cout << 3 << endl;
else
cout << 4 << endl;
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int nn = (int)2000000;
const long double eps = 3 * 10e-8;
const long double eps1 = 5 * 10e-8;
const unsigned long long INF = (unsigned long long)(1e19 * 1.7);
const long long mod = 10;
int main() {
long long n;
cout << "YES\n";
cin >> n;
for (int i = 0; i < n; i++) {
long long x, y;
cin >> x >> y;
cout << ((4 * (long long)1e10 + 2 * (x % 2) + y % 2) % 4) + 1 << ' ';
cin >> x >> y;
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
inline int read() {
char c = getchar();
int x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
int n, x, y, x2, y2;
int xx[N], yy[N];
int main(int argc, const char* argv[]) {
n = read();
for (int i = 1; i <= n; i++) {
x = read() + 1e9 + 5;
y = read() + 1e9 + 5;
x2 = read() + 1e9 + 5;
y2 = read() + 1e9 + 5;
xx[i] = min(x, x2);
yy[i] = min(y, y2);
}
puts("YES");
for (int i = 1; i <= n; i++) {
if (xx[i] & 1) {
if (yy[i] & 1)
puts("1");
else
puts("2");
} else {
if (yy[i] & 1)
puts("3");
else
puts("4");
}
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int i, j, n, m, a, b, c, d, op, maxi, mini, mij, ls, ld, ul, timp, k,
cul[1000005];
string s, t;
int f[1000005], k1, k2, k3;
vector<int> v[1000005];
char ch;
void go(int nod, int tata, int parinte) {
f[nod] = parinte;
if (cul[nod] != cul[tata] && tata != parinte) {
if (parinte == 1) {
if (k1 == 0) a = nod, b = tata;
k1 = 1;
}
if (parinte == a) k2 = 1;
if (parinte == b) k3 = 1;
}
for (int i = 0; i < v[nod].size(); i++)
if (f[v[nod][i]] != parinte) go(v[nod][i], nod, parinte);
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
cout << "YES\n";
for (i = 1; i <= n; i++) {
cin >> a >> b >> c >> d;
a = abs(a);
b = abs(b);
cout << a % 2 * 2 + b % 2 + 1 << '\n';
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int n;
int col[500005];
struct Rec {
int x0, y0, x1, y1, index;
} r[500005];
inline void read(int &x) {
x = 0;
char c = getchar();
int f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = 10 * x + c - '0';
c = getchar();
}
x *= f;
}
int main() {
read(n);
for (int i = 1; i <= n; i++) {
read(r[i].x0);
read(r[i].y0);
read(r[i].x1);
read(r[i].y1);
r[i].index = i;
}
for (int i = 1; i <= n; i++) col[i] = (r[i].x0 & 1) * 2 + (r[i].y0 & 1) + 1;
puts("YES");
for (int i = 1; i <= n; i++) printf("%d\n", col[i]);
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
MyBufferedReader in = new MyBufferedReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskD solver = new TaskD();
solver.solve(1, in, out);
out.close();
}
static class TaskD {
static final int oddodd = 1;
static final int evenodd = 2;
static final int oddeven = 3;
static final int eveneven = 4;
static final int COLOR = 4;
public void solve(int testNumber, MyBufferedReader in, PrintWriter out) {
int n = in.getAnInt();
int[][] rects = new int[n][5];
for (int i = 0; i < n; i++) {
int[] data = in.getALineOfInts(4);
for (int j = 0; j < 4; j++) {
rects[i][j] = data[j];
}
}
int[] colorUsage = new int[5];
for (int[] rect : rects) {
int x = rect[0];
int y = rect[1];
int color;
int xmod = Math.abs(x % 2);
int ymod = Math.abs(y % 2);
if (xmod == 1 && ymod == 1) {
color = oddodd;
} else if (xmod == 0 && ymod == 1) {
color = evenodd;
} else if (xmod == 1 && ymod == 0) {
color = oddeven;
} else {
color = eveneven;
}
rect[COLOR] = color;
colorUsage[color]++;
}
out.println("YES");
for (int[] rect : rects) {
out.println(rect[COLOR]);
}
}
}
static class MyBufferedReader {
BufferedReader in;
public MyBufferedReader(InputStream s) {
this.in = new BufferedReader(new InputStreamReader(s));
}
public int getAnInt() {
int res = -1;
try {
res = Integer.parseInt(new StringTokenizer(in.readLine()).nextToken());
} catch (IOException e) {
e.printStackTrace();
}
return res;
}
public int[] getALineOfInts(int numExpected) {
int[] res = new int[numExpected];
StringTokenizer st = null;
try {
st = new StringTokenizer(in.readLine());
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < numExpected; i++)
res[i] = Integer.parseInt(st.nextToken());
return res;
}
}
}
| JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int Inf = 0x7fffffff;
const int maxn = 1e5 + 5;
const double eps = 1e-10;
int n;
int main() {
while (cin >> n) {
int a, b, c, d;
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c >> d;
cout << 2 * (a & 1) + (b & 1) + 1 << endl;
}
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
puts("YES");
while (n--) {
int x, y;
scanf("%d%d%*d%*d", &x, &y);
cout << (((x & 1) << 1) + (y & 1) + 1) << endl;
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool updateMin(T& a, T b) {
return a > b ? a = b, 1 : 0;
}
template <class T>
inline bool updateMax(T& a, T b) {
return a < b ? a = b, 1 : 0;
}
inline int nextInt() {
int x;
scanf("%d", &x);
return x;
}
inline long long nextI64() {
long long d;
cin >> d;
return d;
}
inline char nextChr() {
scanf(" ");
return getchar();
}
inline string nextStr() {
string s;
cin >> s;
return s;
}
inline double nextDbf() {
double x;
scanf("%lf", &x);
return x;
}
inline long long nextlld() {
long long d;
scanf("%lld", &d);
return d;
}
inline long long next64d() {
long long d;
scanf("%I64d", &d);
return d;
}
int main() {
int n = nextInt();
puts("YES");
for (int i = 0; i < n; i++) {
int x = nextInt();
int y = nextInt();
nextInt();
nextInt();
if (x & 1)
puts(y & 1 ? "1" : "2");
else
puts(y & 1 ? "3" : "4");
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int INF = 1e9 + 7;
const long double EPS = 1e-9;
const long double PI = 3.14159265359;
int main() {
int n;
cin >> n;
cout << "YES\n";
for (int i = 0; i < n; i++) {
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << ((12 + 2 * (x1 % 2) + (y1 % 2)) % 4) + 1 << endl;
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | # -*- coding: utf-8 -*-
# from __future__ import division
import sys
n = int(sys.stdin.readline())
data = [[0] * 4 for i in range(n)]
colors = [0] * n
for i in range(n):
data[i][0], data[i][1], data[i][2], data[i][3] = [int(x) for x in sys.stdin.readline().split()]
colors[i] = (data[i][0] % 2) * 2 + (data[i][1] % 2) + 1
print 'YES'
for x in colors:
print x
| PYTHON |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x1, y1, x2, y2;
;
cin >> n;
cout << "YES\n";
for (long long i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2;
if (x1 % 2 == 0 && y1 % 2 == 0) cout << "1\n";
if (x1 % 2 == 0 && y1 % 2 != 0) cout << "2\n";
if (x1 % 2 != 0 && y1 % 2 == 0) cout << "3\n";
if (x1 % 2 != 0 && y1 % 2 != 0) cout << "4\n";
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class TimofeyAndRectangles {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int n = Integer.parseInt(br.readLine());
out.println("YES");
for(int i = 0 ; i < n ; i++){
String[] s = br.readLine().split("\\s+");
int a = Integer.parseInt(s[0]), b = Integer.parseInt(s[1]);
out.println(2*(a&1)+(b&1)+1);
}
out.close();
}
}
| JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
int x1, y1, x2, y2;
cout << "YES" << endl;
;
for (int i = 0; i < n; ++i) {
cin >> x1 >> y1 >> x2 >> y2;
if (x1 > x2) {
swap(x2, x1);
swap(y2, y1);
}
if (y1 > y2) {
cout << 1 + 2 * (max(x1, 0 - x1) % 2) + max(y2, 0 - y2) % 2 << endl;
;
} else
cout << 1 + 2 * (max(x1, 0 - x1) % 2) + max(y1, 0 - y1) % 2 << endl;
;
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &(n));
printf("YES\n");
for (int i = 0; i < n; i++) {
int x1, x2, y1, y2;
scanf("%d%d", &(x1), &(y1));
scanf("%d%d", &(x2), &(y2));
x1 %= 2;
y1 %= 2;
if (x1 < 0) x1 += 2;
if (y1 < 0) y1 += 2;
printf("%d\n", (1 + x1 + 2 * y1));
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
int n;
int main() {
scanf("%d", &n);
puts("YES");
for (int i = 1; i <= n; i++) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int ans;
if (x1 % 2 && y1 % 2)
ans = 1;
else if (x1 % 2)
ans = 2;
else if (y1 % 2)
ans = 3;
else
ans = 4;
cout << ans << endl;
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n = input()
v = [None] * n
for i in xrange(n):
x1, y1, _, _ = map(int, raw_input().split())
v[i] = 2 * (y1 & 1) + (x1 & 1) + 1
print 'YES'
print '\n'.join(map(str, v)) | PYTHON |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n = int(input())
print("YES")
for i in range(n):
x1, y1, x2, y2 = input().split()
print((int(x1) % 2) * 2 + (int(y1) % 2) + 1) | PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const long double MAXN = 1e6 + 7, SZ = 3 * 1e8;
const long double MODM = 1e9 + 7, INF = 1e18 + 1;
const int N = 6 * 1e5 + 2;
vector<pair<int, pair<int, int>>> mas;
bool used[N];
int c[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
mas.resize(n);
cout << "YES\n";
for (int i = 0; i < n; ++i) {
pair<int, int> f, s;
cin >> f.first >> f.second >> s.first >> s.second;
int x = (((f.first) < 0) ? (-(f.first)) : (f.first));
int y = (((f.second) < 0) ? (-(f.second)) : (f.second));
if (x % 2 == 0 && y % 2 == 0) cout << 1 << "\n";
if (x % 2 == 1 && y % 2 == 0) cout << 2 << "\n";
if (x % 2 == 0 && y % 2 == 1) cout << 3 << "\n";
if (x % 2 == 1 && y % 2 == 1) cout << 4 << "\n";
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n = input()
print 'YES'
for i in xrange(n):
x1, y1, _, _ = map(int, raw_input().split())
print 2 * (y1 & 1) + (x1 & 1) + 1 | PYTHON |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int x, y, a, b, n;
void init() {
scanf("%d", &n);
puts("YES");
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d", &x, &y, &a, &b);
printf("%d\n", 2 * abs(x % 2) + abs(y % 2) + 1);
}
}
int main() {
init();
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int main() {
int n = read();
printf("YES\n");
for (int i = 1; i <= n; i++) {
int x1 = read(), y1 = read(), x2 = read(), y2 = read();
x1 = (x1 % 2 + 2) % 2, y1 = (y1 % 2 + 2) % 2;
printf("%d\n", x1 + (y1 << 1) + 1);
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
cout << "YES" << endl;
for (long long int i = 0; i < n; i++) {
long long int a, b, c, d;
cin >> a >> b >> c >> d;
long long int ans = 2 * (a % 2) + (b % 2);
ans += 20;
ans %= 4;
ans++;
cout << ans << endl;
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int sz = 1e6;
int main() {
int n, c[sz];
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1 %= 2;
if (x1 < 0) x1 += 2;
y1 %= 2;
if (y1 < 0) y1 += 2;
c[i] = x1 + 2 * y1;
}
printf("YES\n");
for (int i = 0; i < n; i++) printf("%d\n", c[i] + 1);
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
inline void read(int &X);
inline void print(int X);
const int Maxn = 5E5 + 5;
const int Maxm = 20000005;
int N;
int main() {
read(N);
int x1, y1, x2, y2;
puts("YES");
for (register int i = (1); i <= (N); i++)
read(x1), read(y1), read(x2), read(y2),
printf("%d\n", (x1 & 1) * 2 + (y1 & 1) + 1);
return 0;
}
inline void read(int &X) {
char c;
bool flag;
for (c = getchar(); (c < '0' || c > '9') && (c != '-'); c = getchar())
;
if (c == '-')
X = 0, flag = false;
else
X = c ^ 48, flag = true;
for (c = getchar(); c >= '0' && c <= '9';
X = X * 10 + (c ^ 48), c = getchar())
;
if (!flag) X = -X;
}
inline void print(int X) {
if (X >= 10) print(X / 10);
putchar('0' + (X % 10));
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
void Get_Val(int &Ret) {
Ret = 0;
char ch;
while (ch = getchar(), ch > '9' || ch < '0')
;
do {
(Ret *= 10) += ch - '0';
} while (ch = getchar(), ch >= '0' && ch <= '9');
}
int main() {
int N, a, b, c, d;
printf("YES\n");
Get_Val(N);
while (N--) {
scanf("%d%d%d%d", &a, &b, &c, &d);
a += 1000000000, b += 1000000000, c += 1000000000, d += 1000000000;
printf("%d\n", ((a & 1) << 1) + (b & 1) + 1);
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N = 5e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n;
int bx[N], by[N], ux[N], uy[N];
vector<int> G[N];
struct Line {
int x, y, id;
Line() {}
Line(int x, int y, int id) : x(x), y(y), id(id) {}
bool operator<(const Line& l) const {
if (x == l.x) {
if (y == l.y) return id > l.id;
return y < l.y;
}
return x < l.x;
}
};
void solve(int* bx, int* ux, int* by, int* uy) {
vector<Line> events;
for (int i = 1; i <= n; ++i) {
events.push_back(Line(bx[i], by[i], -i));
events.push_back(Line(bx[i], uy[i], i));
events.push_back(Line(ux[i], by[i], -i));
events.push_back(Line(ux[i], uy[i], i));
}
sort(events.begin(), events.end());
int sum = 1;
for (int i = 1; i < events.size(); ++i) {
sum += events[i].id < 0 ? 1 : -1;
int preID = abs(events[i - 1].id), curID = abs(events[i].id);
cout << "\"test\""
<< " = "
<< "test"
<< " ";
cout << "sum"
<< " = " << sum << " ";
cout << "preID"
<< " = " << preID << " ";
cout << "curID"
<< " = " << curID << endl;
if (sum >= 2) {
G[preID].push_back(curID);
G[curID].push_back(preID);
cout << "preID"
<< " = " << preID << " ";
cout << "curID"
<< " = " << curID << endl;
}
}
}
int c[N];
int choose(int u) {
bool vis[5] = {};
for (int v : G[u]) vis[c[v]] = 1;
for (int i = 1; i <= 4; ++i)
if (!vis[i]) return i;
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d%d%d%d", bx + i, by + i, ux + i, uy + i);
for (int i = 1; i <= n; ++i) c[i] = (abs(bx[i]) & 1) << 1 | (abs(by[i]) & 1);
puts("YES");
for (int i = 1; i <= n; ++i) printf("%d\n", c[i] + 1);
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n = int(input())
coordinates = []
for i in range(n):
coordinates.append([int(x) % 2 for x in input().split()])
print('YES')
for coordinate in coordinates:
x1, y1, x2, y2 = coordinate
print(2*x2 + y2 + 1)
| PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int c[2][2];
void init() {
c[0][0] = 1;
c[0][1] = 2;
c[1][0] = 3;
c[1][1] = 4;
}
int x[500500], y[500500];
int main() {
int n;
init();
scanf("%d", &n);
int y1, y2, x1, x2;
printf("YES\n");
for (int i = 0; i < int(n); i++) {
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
x[i] = min(x1, x2);
y[i] = min(y1, y2);
}
for (int i = 0; i < int(n); i++)
printf("%d\n", c[(x[i] % 2 + 2) % 2][(y[i] % 2 + 2) % 2]);
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | from sys import stdin,stdout
n = int(stdin.readline())
a = [0 for i in range(n)]
for i in range(n):
inp = stdin.readline().split()
x = int(inp[0])
y = int(inp[1])
a[i] = 2 * (x % 2) + (y % 2) + 1
stdout.write("YES")
stdout.write('\n')
stdout.write("\n".join(str(i) for i in a)) | PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1};
const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1};
const double pi = acos(-1.0);
const int N = 110;
int n;
int main() {
puts("YES");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x0, y0, x1, y1;
scanf("%d", &x0), scanf("%d", &y0), scanf("%d", &x1), scanf("%d", &y1);
if (x0 < 0) x0 = -x0;
if (y0 < 0) y0 = -y0;
if (x0 % 2 == 1 && y0 % 2 == 1) puts("1");
if (x0 % 2 == 1 && y0 % 2 == 0) puts("2");
if (x0 % 2 == 0 && y0 % 2 == 1) puts("3");
if (x0 % 2 == 0 && y0 % 2 == 0) puts("4");
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
struct rect {
int x1, y1, x2, y2;
rect(int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0)
: x1(x1), y1(y1), x2(x2), y2(y2) {}
} r[N];
int col[N];
map<int, vector<int> > rx, ry;
int n;
int main(int argc, char* argv[]) {
ios::sync_with_stdio(0);
scanf("%d", &n);
for (int(i) = (0); (i) < (n); (i)++) {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
if (a % 2 == 0) {
if (b % 2 == 0) {
col[i] = 1;
} else {
col[i] = 2;
}
} else {
if (b % 2 == 0) {
col[i] = 3;
} else {
col[i] = 4;
}
}
}
printf("YES\n");
for (int(i) = (0); (i) < (n); (i)++) {
printf("%d\n", col[i]);
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
cout << "YES" << endl;
while (n--) {
long long a, b, c, d;
cin >> a >> b >> c >> d;
a = a % 2;
b = b % 2;
if (a && b)
cout << 1;
else if (a && !b)
cout << 2;
else if (!a && b)
cout << 3;
else
cout << 4;
cout << endl;
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1E-6;
int main() {
int x, y, a, b, n;
while (cin >> n) {
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
cin >> x >> y >> a >> b;
cout << (((x & 1) << 1) | (y & 1)) + 1 << ' ';
}
cout << endl;
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, v, vv, j, jj, x, y;
cin >> n;
cout << "YES\n";
for (int i = 0; i < n; i++) {
cin >> v >> vv >> j >> jj;
x = min(v, j);
y = min(vv, jj);
x = abs(x);
y = abs(y);
if (x % 2 == 0 && y % 2 == 0) {
cout << 1 << endl;
}
if (x % 2 == 1 && y % 2 == 0) {
cout << 2 << endl;
}
if (x % 2 == 1 && y % 2 == 1) {
cout << 3 << endl;
}
if (x % 2 == 0 && y % 2 == 1) {
cout << 4 << endl;
}
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
using namespace std;
const double pi = acos(-1.0);
int n;
int x[2], y[2];
int color() {
return (min(x[0], x[1]) % 2 + 2) % 2 * 2 + (min(y[0], y[1]) % 2 + 2) % 2 + 1;
}
int main() {
cout << "YES\n";
cin >> n;
for (long long(i) = (0); (i) < (n); ++(i)) {
for (long long(i) = (0); (i) < (2); ++(i)) cin >> x[i] >> y[i];
cout << color() << '\n';
}
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
int main() {
scanf("%d", &n);
int x, y, xx, yy;
printf("YES\n");
for (int i = 0; i < n; i++) {
scanf("%d%d%d%d", &x, &y, &xx, &yy);
if (x % 2 == 0 && y % 2 == 0)
printf("1\n");
else if (x % 2 == 0 && y % 2 != 0)
printf("2\n");
else if (x % 2 && !(y % 2))
printf("3\n");
else if (x % 2 && y % 2)
printf("4\n");
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author prakharjain
*/
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);
DTimofeyAndRectangles solver = new DTimofeyAndRectangles();
solver.solve(1, in, out);
out.close();
}
static class DTimofeyAndRectangles {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
rect[] rects = new rect[n];
out.println("YES");
for (int i = 0; i < n; i++) {
int x1 = in.nextInt();
int y1 = in.nextInt();
int x2 = in.nextInt();
int y2 = in.nextInt();
x2 += 1000000000;
y2 += 1000000000;
rects[i] = new rect(x1, y1, x2, y2, i);
int ans = 0;
if (x2 % 2 == 1) {
ans += 1;
}
if (y2 % 2 == 1) {
ans += 2;
}
out.println(ans + 1);
}
// Map<Integer, List<range>> xlmap = new HashMap<>();
// Map<Integer, List<range>> xrmap = new HashMap<>();
// Map<Integer, List<range>> ylmap = new HashMap<>();
// Map<Integer, List<range>> yrmap = new HashMap<>();
//
// for (int i = 0; i < n; i++) {
// rect cr = rects[i];
//
// //left ver
// range cr1 = new range(cr.y1, cr.y2, i);
//
// //right ver
// range cr2 = new range(cr.y1, cr.y2, i);
//
// //up hor
// range cr3 = new range(cr.x1, cr.x2, i);
//
// range cr4 = new range(cr.x1, cr.x2, i);
//
// if (!xlmap.containsKey(cr.x1)) {
// xlmap.put(cr.x1, new ArrayList<>());
// }
//
// if (!ylmap.containsKey(cr.y1)) {
// ylmap.put(cr.y1, new ArrayList<>());
// }
//
// if (!xrmap.containsKey(cr.x2)) {
// xrmap.put(cr.x2, new ArrayList<>());
// }
//
// if (!yrmap.containsKey(cr.y2)) {
// yrmap.put(cr.y2, new ArrayList<>());
// }
//
// xlmap.get(cr.x1).add(cr1);
// ylmap.get(cr.y1).add(cr3);
// xrmap.get(cr.x2).add(cr2);
// yrmap.get(cr.y2).add(cr4);
// }
//
// for (int key : xlmap.keySet()) {
// xlmap.get(key).sort((t1, t2) -> t1.l - t2.l);
// }
//
// for (int key : ylmap.keySet()) {
// ylmap.get(key).sort((t1, t2) -> t1.l - t2.l);
// }
//
// for (int key : xrmap.keySet()) {
// xrmap.get(key).sort((t1, t2) -> t1.l - t2.l);
// }
//
// for (int key : yrmap.keySet()) {
// yrmap.get(key).sort((t1, t2) -> t1.l - t2.l);
// }
//
// g = new List[n];
//
// for (int i = 0; i < n; i++) {
// g[i] = new ArrayList();
// }
//
// for (int i = 0; i < n; i++) {
// rect cr = rects[i];
//
// List<range> cl = xrmap.get(cr.x1);
// range r1 = indices(cl, cr.y1, cr.y2);
//
// for (int j = r1.l; j <= r1.r; j++) {
// g[cr.i].add(cl.get(j).i);
// //g[cl.get(j).i].add(cr.i);
// }
//
// cl = ylmap.get(cr.y2);
// r1 = indices(cl, cr.x1, cr.x2);
//
// for (int j = r1.l; j <= r1.r; j++) {
// g[cr.i].add(cl.get(j).i);
// //g[cl.get(j).i].add(cr.i);
// }
//
// cl = xlmap.get(cr.x2);
// r1 = indices(cl, cr.y1, cr.y2);
//
// for (int j = r1.l; j <= r1.r; j++) {
// g[cr.i].add(cl.get(j).i);
// //g[cl.get(j).i].add(cr.i);
// }
//
// cl = yrmap.get(cr.y1);
// r1 = indices(cl, cr.x1, cr.x2);
//
// for (int j = r1.l; j <= r1.r; j++) {
// g[cr.i].add(cl.get(j).i);
// //g[cl.get(j).i].add(cr.i);
// }
// }
//
// int[] ans = new int[n];
//
// List<Integer> vd = new ArrayList<>();
//
// for (int i = 0; i < n; i++) {
// vd.add(i);
// }
//
// vd.sort((v1, v2) -> g[v2].size() - g[v1].size());
//
// for (int k = 0; k < n; k++) {
//
// int i = vd.get(k);
//
// Set<Integer> s = new HashSet<>();
//
// for (int j = 0; j < g[i].size(); j++) {
// int v = (int) g[i].get(j);
//
// if (ans[v] != 0) {
// s.add(ans[v]);
// }
// }
//
// for (int j = 1; j <= 4; j++) {
// if (!s.contains(j)) {
// ans[i] = j;
// break;
// }
// }
// }
//
// out.println("YES");
//
// for (int i = 0; i < n; i++) {
// out.println(ans[i]);
// }
}
class rect {
int x1;
int y1;
int x2;
int y2;
int i;
public rect(int x1, int y1, int x2, int y2, int i) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.i = i;
}
}
}
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 static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void println(int i) {
writer.println(i);
}
}
}
| JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
int n, a, b, c, d, e[2][2] = {1, 2, 3, 4};
int main() {
scanf("%d", &n);
puts("YES");
while (n--) {
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("%d\n", e[a & 1][b & 1]);
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, x1, y1, x2, y2, i;
cin >> n;
cout << "YES\n";
for (i = 0; i < n; ++i) {
cin >> x1 >> y1 >> x2 >> y2;
if (x1 & 1 && y1 & 1)
cout << "1";
else if (!(x1 & 1) && y1 & 1)
cout << "2";
else if (x1 & 1 && !(y1 & 1))
cout << "3";
else
cout << "4";
cout << "\n";
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
int n;
cin >> n;
int x1, y1, x2, y2;
vector<int> ans(n);
for (ll i = 0, iLen = (n); i < iLen; ++i) {
cin >> x1 >> y1 >> x2 >> y2;
ans[i] = ((x1 % 2 + 2) % 2) + ((y1 % 2 + 2) % 2) * 2 + 1;
}
cout << "YES\n";
for (ll i = 0, iLen = (n); i < iLen; ++i) cout << ans[i] << "\n";
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;
/**
*
*/
public class TaskD {
public static void main(String[] args) {
InputStream inputStream;
String str = null;
if(str == null){
inputStream = System.in;
}else{
inputStream = new ByteArrayInputStream(str.getBytes());
}
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solver solver = new Solver();
solver.solve(1, in, out);
out.close();
}
static class Solver {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int numRectangles = in.nextInt();
HashMap<Integer, Rectangle> rectangles = new HashMap<>();
System.out.println("YES");
for(int i=1;i<=numRectangles;i++){
int x1 = in.nextInt();
int y1 = in.nextInt();
int x2 = in.nextInt();
int y2 = in.nextInt();
Rectangle r = new Rectangle(i, x1,y1,x2,y2);
rectangles.put(i,r);
}
for(int i=1;i<=numRectangles;i++){
System.out.println(rectangles.get(i).color);
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
class Rectangle{
int x1;
int x2;
int y1;
int y2;
int color = -1;
int id;
public Rectangle(int id, int x1, int y1, int x2, int y2){
this.id = id;
this.color = 2*(Math.abs(x1)%2)+(Math.abs(y1)%2)+1;
}
} | JAVA |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
cout << "YES\n";
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int x1, y1, x2, y2;
x1 = max(x1, x2);
y1 = max(y1, y2);
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
int c = 2 * (((x1 % 2) + 2) % 2) + (((y1 % 2) + 2) % 2);
printf("%d\n", c + 1);
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x1, x2, y1, y2;
cin >> n;
cout << "YES\n";
while (n--) {
cin >> x1 >> y1 >> x2 >> y2;
cout << ((x1 & 1) * 2 + (y1 & 1) + 1) << endl;
}
return 0;
}
| CPP |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 |
import sys
def rl(): return sys.stdin.readline()
def ni(): return int(rl())
def nsa(): return rl().split()
def nia(): return [int(x) for x in nsa()]
def nnia(n): return [nia() for _ in range(n)]
n = ni()
rects = nnia(n)
print('YES')
for r in rects:
print((r[0]%2)*2+(r[1]%2)+1)
| PYTHON3 |
764_D. Timofey and rectangles | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length
<image> The picture corresponds to the first example
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of rectangles.
n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1 < x2 β€ 109, - 109 β€ y1 < y2 β€ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
Output
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 β€ ci β€ 4) β the color of i-th rectangle.
Example
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1 | 2 | 10 | n = int(raw_input())
print "YES"
for cnt in xrange(n):
x1, y1, x2, y2 = raw_input().split()
x1 = int(x1)
y1 = int(y1)
print 2*(x1 % 2) + (y1 % 2) + 1
| PYTHON |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.