1+ /* *
2+ *
3+ * 0. 현재 물고기 정보 저장.
4+ * 1. 물고기가 이동할 수 있는 경우
5+ * 모든 물고기는 한칸씩 이동
6+ * 상어가 있는 칸 ( shark 로 확인 ) , 물고기의 냄새가 있는 칸 ( smell로 확인 ) , 격자의 범위는 x
7+ * -> 안되면 45도씩 이동해서 갈 수 있는지 확인
8+ *
9+ *
10+ * 2. 상어가 움직이는 경우
11+ * 1,2,3,4 중에 3개를 뽑고 중복순열을 만들어서 오름차순으로 정렬하기
12+ * 해당 값을 반복하면서
13+ * 좌표를 이동
14+ * 불가능하면 -> 이동x
15+ * 물고기가 있다면 -> 물고기 제외 count 추가
16+ * 물고기 제외 count max()
17+ * max인 값의 좌표로 이동후 물고기 냄새 표시하기.
18+ *
19+ *
20+ * 3. smell에서 time이 2인 얘들 삭제
21+ * 4. 기존의 fishse 그대로 적용... 오마갓...
22+ *
23+ *
24+ */
25+
26+ data class FISH (val x : Int , val y : Int , val arrow : Int )
27+ data class SMELL (val x : Int , val y : Int , var time : Int )
28+
29+ val fishPos = mapOf<Int , Pair <Int ,Int >>(
30+ 0 to Pair (0 ,0 ),
31+ 1 to Pair (0 ,- 1 ),
32+ 2 to Pair (- 1 ,- 1 ),
33+ 3 to Pair (- 1 ,0 ),
34+ 4 to Pair (- 1 ,1 ),
35+ 5 to Pair (0 ,1 ),
36+ 6 to Pair (1 ,1 ),
37+ 7 to Pair (1 ,0 ),
38+ 8 to Pair (1 ,- 1 )
39+ )
40+
41+ val sharkPos = mapOf (
42+ 1 to Pair (- 1 ,0 ),
43+ 3 to Pair (1 ,0 ),
44+ 2 to Pair (0 ,- 1 ),
45+ 4 to Pair (0 ,1 )
46+ )
47+
48+ var sharkX = 0
49+ var sharkY = 0
50+ var fishes = mutableListOf<FISH >()
51+ val smell = mutableListOf<SMELL >()
52+ val temp = mutableListOf<FISH >()
53+ val moveSharkList = mutableListOf<String >()
54+
55+
56+ fun main (){
57+ val (m,s) = readln().split(" " ).map { it.toInt() }
58+ repeat(m){
59+ val fi = readln().split(" " ).map { it.toInt() }
60+ fishes.add( FISH (fi[0 ],fi[1 ],fi[2 ]))
61+ }
62+
63+ val shark = readln().split(" " ).map { it.toInt() }
64+ sharkX = shark[0 ]
65+ sharkY = shark[1 ]
66+ makeMoveShark(arrayOf(1 ,2 ,3 ,4 ), Array (3 ){0 },0 ,3 )
67+ moveSharkList.sortDescending()
68+
69+ repeat(s){
70+ smell.forEach{ smell -> smell.time ++ }
71+ temp.clear()
72+ temp.addAll(fishes)
73+
74+ // 물고기 이동
75+ fishes.forEachIndexed { idx, fish ->
76+ var (x,y,arrow) = fish
77+ if (checkFish(x,y,arrow)){
78+ x + = fishPos[arrow]!! .first
79+ y + = fishPos[arrow]!! .second
80+ fishes[idx] = FISH (x,y,arrow)
81+ }else if (! checkFish(x,y,arrow)){
82+ // 이동할 수 없는 경우
83+ var i = 0
84+ while (i < 8 ){
85+ arrow = if ( arrow == 1 ) 8 else { arrow- 1 } // 45도 반시계로 돌리기
86+ if (checkFish(x,y,arrow)){
87+ x + = fishPos[arrow]!! .first
88+ y + = fishPos[arrow]!! .second
89+ fishes[idx] = (FISH (x,y,arrow))
90+ break
91+ }else {
92+ i++
93+ }
94+ }
95+ }
96+ }
97+
98+ // 상어의 우선순위 이동pos 찾기
99+ var removeMax = 0
100+ var removePos = " 444"
101+ moveSharkList.forEach sharkRepeat@{ pos ->
102+ var count = 0
103+ var tempMax = 0
104+ var tempSharkX = sharkX
105+ var tempSharkY = sharkY
106+ val tempFishList = mutableListOf<FISH >()
107+ tempFishList.clear()
108+ tempFishList.addAll(fishes)
109+ repeat(3 ){
110+ tempSharkX + = sharkPos[(pos[it]).digitToInt()]!! .first
111+ tempSharkY + = sharkPos[(pos[it]).digitToInt()]!! .second
112+ if (tempSharkX <= 4 && tempSharkY <= 4 ){
113+ count++
114+ tempFishList.forEachIndexed {idx , fish ->
115+ if (tempSharkX == fish.x && tempSharkY == fish.y){
116+ // 상어자리에 물고기가 있다면
117+ tempFishList[idx] = FISH (0 ,0 ,0 )
118+ tempMax++
119+ }
120+ }
121+ }
122+ }
123+
124+ if (count == 3 && tempMax >= removeMax){
125+ removeMax = tempMax
126+ removePos = pos
127+ if (removeMax == 3 ){ return @sharkRepeat }
128+ }
129+ }
130+
131+ removeFish(removePos) // 3번 이동( 물고기 제외 & 상어 좌표 이동 )
132+ smell.filter { it.time == 2 }.forEach { smell.remove(it) } // 두번 전에 생긴 물고기 냄새 지우기
133+ temp.forEach { fishes.add(it) }
134+ }
135+
136+ println (fishes.size)
137+ }
138+
139+ fun checkFish (x : Int , y : Int , arrow : Int ) : Boolean {
140+ val newX = x + fishPos[arrow]!! .first
141+ val newY = y + fishPos[arrow]!! .second
142+ return ! ((newX == sharkX && newY == sharkY) || (smell.any{ smell -> smell.x == newX && smell.y == newY}) || newX > 4 || newY > 4 )
143+ }
144+
145+ fun makeMoveShark (arr : Array <Int >, output : Array <Int >, depth : Int , r : Int ){
146+ if (depth == r){
147+ moveSharkList.add(output.joinToString(" " ))
148+ println ()
149+ return
150+ }
151+ for (i in arr.indices){
152+ output[depth] = arr[i]
153+ makeMoveShark(arr,output,depth+ 1 , r)
154+ }
155+ }
156+
157+ fun removeFish (moveShark : String ){
158+ moveShark.forEach {
159+ sharkX + = sharkPos[it.digitToInt()]!! .first
160+ sharkY + = sharkPos[it.digitToInt()]!! .second
161+ fishes.forEachIndexed {idx, fish ->
162+ if (sharkX == fish.x && sharkY == fish.y){
163+ // 상어자리에 물고기가 있다면
164+ fishes[idx] = FISH (0 ,0 ,0 )
165+ smell.add(SMELL (fish.x,fish.y,0 ))
166+ }
167+ }
168+ }
169+ fishes = fishes.filterNot { it.x == 0 && it.y == 0 && it.arrow == 0 }.toMutableList()
170+ }
0 commit comments