| Task: | Ruudukko |
| Sender: | TapaniS |
| Submission time: | 2025-11-29 14:30:48 +0200 |
| Language: | Java |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 16 |
| #2 | ACCEPTED | 42 |
| #3 | ACCEPTED | 42 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.09 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.49 s | 2, 3 | details |
| #3 | ACCEPTED | 0.63 s | 2, 3 | details |
| #4 | ACCEPTED | 0.76 s | 3 | details |
| #5 | ACCEPTED | 0.74 s | 3 | details |
Code
import java.util.*;
import java.io.*;
public class ruudut2 {
public static void main(String[] args) throws IOException {
// Scanner input = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] parts = br.readLine().split(" ");
int n = Integer.parseInt(parts[0]); // ruudukon koko
int m = Integer.parseInt(parts[1]); // operaatioiden maara
int[] y1 = new int[m]; // alkuarvot
int[] y2 = new int[m];
int[] x1 = new int[m];
int[] x2 = new int[m];
char[][] taulu = new char[n][n];
for (int i = 0; i < n; i++) {
for (int i2 = 0; i2 < n; i2++) {
taulu[i][i2] = '.';
}
}
for (int i = 0; i < m; i++) {
String[] parts2 = br.readLine().split(" ");
y1[i] = Integer.parseInt(parts2[0]);
x1[i] = Integer.parseInt(parts2[1]);
y2[i] = Integer.parseInt(parts2[2]);
x2[i] = Integer.parseInt(parts2[3]);
}
// input.close();
StringBuilder sb = new StringBuilder();
int[][] flip = new int[n+1][n+1];
int y11 = 0;
int x11 = 0;
int y22 = 0;
int x22 = 0;
for (int i2 = 0; i2 < m; i2++) {
y11 = y1[i2] - 1;
x11 = x1[i2] - 1;
y22 = y2[i2] - 1;
x22 = x2[i2] - 1;
flip[y11][x11] += 1;
if (x22 + 1 < n) flip[y11][x22 + 1] -= 1;
if (y22 + 1 < n) flip[y22 + 1][x11] -= 1;
if (y22 + 1 < n && x22 + 1 < n) flip[y22 + 1][x22 + 1] += 1;
}
// Prefix sum horizontally
for (int i = 0; i < n; i++) {
for (int j = 1; j < n; j++) {
flip[i][j] += flip[i][j - 1];
}
}
// Prefix sum vertically
for (int j = 0; j < n; j++) {
for (int i = 1; i < n; i++) {
flip[i][j] += flip[i - 1][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (flip[i][j] % 2 == 1) {
taulu[i][j] = (taulu[i][j] == '.') ? '#' : '.';
}
}
}
// tulostus
// sb.append(x[t-1]).append('\n');
// System.out.println(dy + " " + dx);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
sb.append(taulu[i][j]);
}
sb.append('\n');
}
System.out.print(sb.toString());
} // main
}Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 10 100 6 7 8 9 2 6 7 10 7 5 9 6 6 1 6 2 ... |
| correct output |
|---|
| ..##..##.. ##....##.# ..####..## ##.##..... ####....## ... |
| user output |
|---|
| ..##..##.. ##....##.# ..####..## ##.##..... ####....## ... |
Test 2
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| 500 100000 133 109 167 178 204 337 481 477 242 476 445 485 452 198 460 321 ... |
| correct output |
|---|
| .##....####.####..##....#.##.#... |
| user output |
|---|
| .##....####.####..##....#.##.#... |
Test 3
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| 500 100000 33 7 485 482 50 38 456 459 34 20 479 493 13 6 479 485 ... |
| correct output |
|---|
| .....#.####.#.#...####.##....#... |
| user output |
|---|
| .....#.####.#.#...####.##....#... |
Test 4
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 2000 100000 126 95 1489 1619 1473 29 1697 78 1290 1031 1588 1047 1209 1794 1546 1818 ... |
| correct output |
|---|
| ..........................####... |
| user output |
|---|
| ..........................####... |
Test 5
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 2000 100000 55 51 1842 1905 47 60 1997 1890 117 45 1920 1840 48 175 1987 1852 ... |
| correct output |
|---|
| #.#...#...###.#...#####..####.... |
| user output |
|---|
| #.#...#...###.#...#####..####.... |
