-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path황정훈.java
More file actions
94 lines (88 loc) · 2.68 KB
/
황정훈.java
File metadata and controls
94 lines (88 loc) · 2.68 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.io.*;
import java.util.*;
public class Main {
static BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw= new BufferedWriter(new OutputStreamWriter(System.out));
static StringBuilder sb = new StringBuilder();
static StringTokenizer st;
static int N;
static boolean can = false;
static char[][] Class;
static class Point{
int r, c;
public Point(int r, int c){
this.r = r;
this.c = c;
}
}
static ArrayList<Point> Ts = new ArrayList<>();
static ArrayList<Point> Xs = new ArrayList<>();
public static void main(String[] args) throws Exception {
N = Integer.parseInt(br.readLine());
Class = new char[N][N];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < N; j++) {
Class[i][j] = st.nextToken().charAt(0);
if (Class[i][j]=='X')
Xs.add(new Point(i, j));
else if (Class[i][j]=='T')
Ts.add(new Point(i, j));
}
}
fill(0, 3);
sb.append(can? "YES" : "NO");
bw.write(sb.toString());
bw.flush();
bw.close();
br.close();
}
static void fill(int s, int remain){
if(can)
return;
if (remain==0){
chk();
return;
}
for (int i = s; i < Xs.size(); i++) {
Point cur = Xs.get(i);
Class[cur.r][cur.c] = 'O';
fill(i+1, remain-1);
Class[cur.r][cur.c] = 'X';
}
}
static void chk(){
int r, c;
for (Point t : Ts){
r = t.r-1;
c = t.c;
while(0<=r && r<N && 0<=c && c<N){
if(Class[r][c]=='O' || Class[r][c]=='T') break;
else if(Class[r][c]=='S') return;
r--;
}
r = t.r;
c = t.c+1;
while(0<=r && r<N && 0<=c && c<N){
if(Class[r][c]=='O' || Class[r][c]=='T') break;
else if(Class[r][c]=='S') return;
c++;
}
r = t.r+1;
c = t.c;
while(0<=r && r<N && 0<=c && c<N){
if(Class[r][c]=='O' || Class[r][c]=='T') break;
else if(Class[r][c]=='S') return;
r++;
}
r = t.r;
c = t.c-1;
while(0<=r && r<N && 0<=c && c<N){
if(Class[r][c]=='O' || Class[r][c]=='T') break;
else if(Class[r][c]=='S') return;
c--;
}
}
can = true;
}
}