Skip to content

Commit 2e79e75

Browse files
authored
Merge pull request #95 from AlgorithmWithGod/khj20006
[20250212] BOJ / P3 / 얼룩말 아트 / 권혁준
2 parents 72d1bf9 + f78d163 commit 2e79e75

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Main {
7+
8+
// IO field
9+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
static StringTokenizer st;
12+
13+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
14+
static int nextInt() {return Integer.parseInt(st.nextToken());}
15+
static long nextLong() {return Long.parseLong(st.nextToken());}
16+
static void bwEnd() throws Exception {bw.flush();bw.close();}
17+
18+
// Additional field
19+
static int[][] SQ, arr;
20+
static int W, H, K;
21+
22+
public static void main(String[] args) throws Exception {
23+
24+
ready();
25+
solve();
26+
27+
bwEnd();
28+
}
29+
30+
static void ready() throws Exception{
31+
32+
nextLine();
33+
H = nextInt();
34+
W = nextInt();
35+
K = nextInt();
36+
SQ = new int[W+2][H+2];
37+
arr = new int[W+2][H+2];
38+
39+
}
40+
41+
static void solve() throws Exception{
42+
43+
while(K-- > 0) {
44+
nextLine();
45+
int op = nextInt(), py = nextInt(), px = nextInt();
46+
px++;
47+
py++;
48+
if(op == 1) {
49+
int qy = nextInt(), qx = nextInt();
50+
qx++;
51+
qy++;
52+
Square(px,py,qx,qy);
53+
}
54+
else {
55+
int r = nextInt();
56+
if(r == 1) {
57+
arr[px][py]++;
58+
arr[px+1][py]++;
59+
arr[px-1][py]++;
60+
arr[px][py+1]++;
61+
arr[px][py-1]++;
62+
}
63+
else {
64+
RightUp(px-1,py+1,r-2);
65+
RightDown(px+1,py+1,r-2);
66+
LeftUp(px-1,py-1,r-2);
67+
LeftDown(px+1,py-1,r-2);
68+
Square(px-r,py,px+r,py);
69+
Square(px,py-r,px,py+r);
70+
arr[px][py]--;
71+
}
72+
}
73+
}
74+
75+
for(int i=1;i<=W;i++) {
76+
int s = 0;
77+
for(int j=1;j<=H;j++) {
78+
SQ[i+1][j] += SQ[i][j];
79+
s += SQ[i][j];
80+
arr[i][j] += s;
81+
bw.write(arr[i][j]%2 == 0 ? '.' : '#');
82+
}
83+
bw.write("\n");
84+
}
85+
86+
87+
}
88+
89+
static void Square(int px, int py, int qx, int qy) {
90+
SQ[px][py]++;
91+
SQ[qx+1][py]--;
92+
SQ[px][qy+1]--;
93+
SQ[qx+1][qy+1]++;
94+
}
95+
96+
static void RightUp(int x, int y, int r) {
97+
if(r == 0) {
98+
arr[x][y]++;
99+
return;
100+
}
101+
if(r == 1) {
102+
arr[x][y]++;
103+
arr[x-1][y]++;
104+
arr[x][y+1]++;
105+
return;
106+
}
107+
int nr = r/2;
108+
Square(x-nr,y,x,y+nr);
109+
RightUp(x-nr-1,y,(r-1)/2);
110+
RightUp(x,y+nr+1,(r-1)/2);
111+
}
112+
113+
static void RightDown(int x, int y, int r) {
114+
if(r == 0) {
115+
arr[x][y]++;
116+
return;
117+
}
118+
if(r == 1) {
119+
arr[x][y]++;
120+
arr[x+1][y]++;
121+
arr[x][y+1]++;
122+
return;
123+
}
124+
int nr = r/2;
125+
Square(x,y,x+nr,y+nr);
126+
RightDown(x+nr+1,y,(r-1)/2);
127+
RightDown(x,y+nr+1,(r-1)/2);
128+
}
129+
130+
static void LeftUp(int x, int y, int r) {
131+
if(r == 0) {
132+
arr[x][y]++;
133+
return;
134+
}
135+
if(r == 1) {
136+
arr[x][y]++;
137+
arr[x-1][y]++;
138+
arr[x][y-1]++;
139+
return;
140+
}
141+
int nr = r/2;
142+
Square(x-nr,y-nr,x,y);
143+
LeftUp(x-nr-1,y,(r-1)/2);
144+
LeftUp(x,y-nr-1,(r-1)/2);
145+
}
146+
147+
static void LeftDown(int x, int y, int r) {
148+
if(r == 0) {
149+
arr[x][y]++;
150+
return;
151+
}
152+
if(r == 1) {
153+
arr[x][y]++;
154+
arr[x+1][y]++;
155+
arr[x][y-1]++;
156+
return;
157+
}
158+
int nr = r/2;
159+
Square(x,y-nr,x+nr,y);
160+
LeftDown(x+nr+1,y,(r-1)/2);
161+
LeftDown(x,y-nr-1,(r-1)/2);
162+
}
163+
164+
}
165+
166+
```

0 commit comments

Comments
 (0)