-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.java
74 lines (63 loc) · 2.01 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args){
Solve solve = new Solve();
solve.run();
}
}
class Solve{
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private long S, N, K, R1, R2, C1, C2;
private int[][] arr = new int[55][55];
private long grid = 1;
public void run(){
input();
calcGrid();
setArr(0, 0, 0, this.grid, 0);
printArr();
}
private void input(){
try{
String[] read = br.readLine().split(" ");
S = Long.parseLong(read[0]);
N = Long.parseLong(read[1]);
K = Long.parseLong(read[2]);
R1 = Long.parseLong(read[3]);
R2 = Long.parseLong(read[4]);
C1 = Long.parseLong(read[5]);
C2 = Long.parseLong(read[6]);
} catch(Exception e){}
}
private void calcGrid(){
for(int i = 0; i < S; i++) grid *= N;
}
private void setArr(int sec, long y, long x, long grid, int fill){
if(y > R2 || x > C2) return;
if(y + grid <= R1 || x + grid <= C1) return;
if(sec == S) {
arr[(int)(y-R1)][(int)(x-C1)] = fill;
return;
}
long gridDivN = grid / N;
long fillLeft = (N-K)/2;
long fillRight = fillLeft+K-1;
for(int i = 0; i < N; i++){
long nextY = y + gridDivN * i;
for(int j = 0; j < N; j++){
long nextX = x + gridDivN * j;
int nextFill = fill;
if(nextFill == 0 && i >= fillLeft && i <= fillRight && j >= fillLeft && j <= fillRight) nextFill = 1;
setArr(sec+1, nextY, nextX, gridDivN, nextFill);
}
}
}
private void printArr(){
for(int i = 0; i <= R2-R1; i++){
for(int j = 0; j <= C2-C1; j++){
System.out.print(arr[i][j]);
}
System.out.println();
}
}
}