Skip to content

Commit c81c6c2

Browse files
authored
Merge pull request #170 from AlgorithmWithGod/khj20006
[20250225] BOJ / G2 / 징검다리 게임 / 권혁준
2 parents 70fb0d5 + 4565b9a commit c81c6c2

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Node{
7+
int attacks = 0;
8+
int mine = 0;
9+
Node(int attacks, int mine){
10+
this.attacks = attacks;
11+
this.mine = mine;
12+
}
13+
}
14+
15+
class Main {
16+
17+
// IO field
18+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
19+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
20+
static StringTokenizer st;
21+
22+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
23+
static int nextInt() {return Integer.parseInt(st.nextToken());}
24+
static long nextLong() {return Long.parseLong(st.nextToken());}
25+
static void bwEnd() throws Exception {bw.flush();bw.close();}
26+
27+
// Additional field
28+
29+
static int N, K;
30+
static int[] A;
31+
static String command;
32+
33+
public static void main(String[] args) throws Exception {
34+
35+
ready();
36+
solve();
37+
38+
bwEnd();
39+
40+
}
41+
42+
static void ready() throws Exception{
43+
44+
N = Integer.parseInt(br.readLine());
45+
A = new int[N+2];
46+
nextLine();
47+
for(int i=1;i<=N;i++) A[i] = nextInt();
48+
K = Integer.parseInt(br.readLine());
49+
command = br.readLine();
50+
51+
}
52+
53+
static void solve() throws Exception{
54+
55+
int idx = 0, cur = 1;
56+
while(idx < command.length()) {
57+
if(command.charAt(idx) == 'J') {
58+
idx++;
59+
if(A[cur+1] != 0) {
60+
bw.write("NO");
61+
return;
62+
}
63+
cur++;
64+
break;
65+
}
66+
if(command.charAt(idx) == 'D') {
67+
if(A[cur+1] <= -1) A[cur+1] = 0;
68+
}
69+
else {
70+
if(A[cur+1] == -1) {
71+
bw.write("NO");
72+
return;
73+
}
74+
A[cur+1] = Math.max(0, A[cur+1] - 1);
75+
}
76+
idx++;
77+
}
78+
if(cur == 1) {
79+
bw.write("NO");
80+
return;
81+
}
82+
83+
int atts = 0, mine = 0;
84+
List<Node> L = new ArrayList<>();
85+
for(int i=idx;i<idx+K;i++) {
86+
if(command.charAt(i%K) == 'J') {
87+
L.add(new Node(atts, mine));
88+
atts = 0;
89+
mine = 0;
90+
}
91+
else if(command.charAt(i%K) == 'D') {
92+
if(atts == 0) mine = 1;
93+
}
94+
else {
95+
atts++;
96+
}
97+
}
98+
99+
100+
idx = 0;
101+
while(cur < N) {
102+
Node now = L.get(idx%L.size());
103+
if(A[cur+1] == -1) {
104+
if(now.mine == 0) {
105+
bw.write("NO");
106+
return;
107+
}
108+
}
109+
else {
110+
if(now.attacks < A[cur+1]) {
111+
bw.write("NO");
112+
return;
113+
}
114+
}
115+
A[cur+1] = 0;
116+
cur++;
117+
idx++;
118+
}
119+
bw.write("YES");
120+
121+
}
122+
123+
}
124+
125+
```

0 commit comments

Comments
 (0)