์ฝ๋ํธ๋ฆฌ | ์ฝ๋ฉํ ์คํธ ์ค๋น๋ฅผ ์ํ ์๊ณ ๋ฆฌ์ฆ ์ ์
๊ตญ๊ฐ๋ํ๊ฐ ๋ง๋ ์ฝ๋ฉ ๊ณต๋ถ์ ๊ฐ์ด๋๋ถ ์ฝ๋ฉ ์์ด๋ณด๋ถํฐ ๊ฟ์ ์ง์ฅ ์ฝํ ํฉ๊ฒฉ๊น์ง, ๊ตญ๊ฐ๋ํ๊ฐ ์์ ํ ์ปค๋ฆฌํ๋ผ์ผ๋ก ์ค๋นํด๋ณด์ธ์.
www.codetree.ai
์ด๋๊ฐ ํ๋ฆฐ๊ฑด์ง ๋ชจ๋ฅด๊ฒ ๋ค..
๋ด๊ฐ ํ๋ฆฐ ์ผ์ด์ค
์ ๋ ฅ
50 189
44 35 33 1
29 48 1 28 19 10 7 38 5 45 30 2 40 14 29 47 7 12 16 30 27 8 47 22 35 31 16 29 10 11 13 33 20 46 6 44 45 36 24 12 42 33 48 32 14 11 17 23 27 43 25 5 39 32 31 47 33 37 2 45 6 17 21 6 18 44 40 7 22 1 43 4 1 12 46 38 27 26 1 31 0 27 47 11 38 2 12 21 25 47 46 41 1 38 48 20 5 43 15 19 5 38 1 3 25 1 44 28 45 29 21 20 6 39 7 32 34 21 19 20 24 18 46 6 31 16 24 43 42 43 40 48 2 15 7 37 29 33 37 41 1 32 20 13 36 35 34 43 7 29 11 22 34 6 49 25 14 1 40 30 46 24 18 0 8 42 42 31 8 49 0 24 28 27 41 21 43 16 17 3 5 13 44 22 34 39 21 10 2 21 39 15 34 46 36 26 11 10 10 17 34 0 30 49 11 36 15 5 20 44 42 14 4 46 38 43 9 5 37 25 10 2 24 23 19 3 49 26 36 16 46 33 11 48 17 36 11 40 49 42 19 45 17 13 38 1 2 18 39 18 9 25 27 41 9 22 12 33 40 18 17 21 22 43 5 2 30 5 42 22 14 29 38 39 5 17 24 2 49 2 3 23 3 44 42 46 10 44 4 4 15 7 18 49 5 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1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
๋๋ก ๋ณํ warrior์ ์๋ 7์ด ๋์์ผ ํ๋๋ฐ ๋ด ์ฝ๋์์ 8์ด ๋์จ๋ค..
๊ทธ๋ฆผํ์ผ๋ก ์ ์ถ๋ ฅ์ ๋ํด ๊ทธ๋ ค๋ณด์๋๋ฐ 8์ด ๋์จ๋ค.
๋๋ก ๋ณํ warrior๋ฅผ ์ธ๋ ๋ก์ง, ๊ทธ๋ฆผ์๋ฅผ ๋ง๋๋ ๋ก์ง์ ํ๋ฆฌ์ง ์์๋ค๋ ๋ป์ธ๋ฐ
๊ทธ๋ฌ๋ฉด warrior๊ฐ ๋ฉ๋์ฌ์๊ฒ ๊ฐ๋ ๋ก์ง์ด ํ๋ ธ๊ฑฐ๋
warrior๊ฐ ๊ณต๊ฒฉํ๋ ๋ก์ง์ด ํ๋ ธ๊ฑฐ๋
๋ฉ๋์ฌ๊ฐ warrior๋ฅผ ๊ณต๊ฒฉํ๋ ๋ก์ง์ด ํ๋ ธ๊ฑฐ๋
๋ฉ๋์ฌ๊ฐ ์ต๋จ๊ฒฝ๋ก๋ก ๊ฐ๋ ๋ก์ง์ด ํ๋ ธ๊ฑฐ๋ ?
์ด๋๊ฐ ํ๋ฆฐ๊ฑฐ์ง
์๊ฒ๋ ์
- bfs๋ฅผ ํ์ฉํ์ฌ ์ต๋จ๊ฒฝ๋ก๋ฅผ ๊ตฌํ๋ ๋ฐฉ๋ฒ
- prev ๋ฐฐ์ด์ ๋ฌ์ ์ด์ ๋ฐฉ๋ฌธ ์์น๋ฅผ ์ ์ฅํ์ฌ ๊ตฌํ ์ ์๋ค.
- ๋๋ ๋ฐฐ์ด์ ์ต๋จ๊ฒฝ๋ก cnt๊ฐ์ ๊ธฐ๋กํ ๋ค cnt๋ฅผ 1์ฉ ๊ฐ์์ํค๋ฉด์ ๊ฒฝ๋ก๋ฅผ ์ญ ์ถ์ ํ ์ ์๋ค.
- ํด๋์ค๋ฅผ ๋ง๋ค์ง ์๊ณ , ์ฌ๋ฌ ์ขํ ๋ฐฐ์ด ๋ณ์๋ฅผ ํตํด์ ์ํ๋ฅผ ํ์ธํ ์ ์๋ค.
- warrior ํด๋์ค์ ๋๋ก ๋ณํ๋ ์ฌ๋ถ๋ฅผ ํ์ธํ๋ ๋ฉค๋ฒ๋ณ์๋ฅผ ๋์ง ์๊ณ warrior์ ์ขํ๋ฅผ ์ด์ฉํ sightMap[][] ๋ณ์์ ์ ๊ทผํ์ฌ ๋๋ก ๋ณํ๋ ์ฌ๋ถ๋ฅผ ํ์ธํ ์ ์๋ค.
- ํด๋์ค์ ์ขํ๋ฅผ ์ด์ฉํ์ฌ ์ํ๋ฅผ ๋ํ๋ผ ์ ์๋ค.
- ์ ๋ฌธ์ ์์๋ Warrior์ ์ขํ๊ฐ -1์ด๋ฉด ์ฌ๋งํ ์ํ
import java.util.*;
import java.io.*;
class Warrior{
int r,c;
public Warrior(int r,int c){
this.r = r;
this.c = c;
}
}
public class Main {
static int N,M;
static int[][] map;
static int[][] warriorCnt;
static Warrior[] warriors;
static int[] medusa, park; // ๋ฉ๋์ฌ์ ๊ณต์์ ์ขํ
static int[] firstDr = {-1,1,0,0};
static int[] firstDc = {0,0,-1,1};
// 0 : ์, 1 : ์ฐ, 2 : ํ, 3 : ์ข, 4 : ์ค๋ฅธ์ชฝ ์ ๋๊ฐ์ , 5 : ์ค๋ฅธ์ชฝ ์๋ ๋๊ฐ์ , 6 : ์ผ์ชฝ ์๋ ๋๊ฐ์ , 7 : ์ผ์ชฝ ์ ๋๊ฐ์
static int[] eightDr = {-1,0,1,0,-1,1,1,-1};
static int[] eightDc = {0,1,0,-1,1,1,-1,-1};
static Deque<int[]> medusaWay;
static int[][] medusaSight;
static boolean isRange(int r,int c) {
if(r < 0 || r>= N) return false;
if(c < 0 || c>= N) return false;
return true;
}
static boolean findMedusaWay(){
// bfs๋ก ์ต๋จ๊ฒฝ๋ก ์ฐพ๊ธฐ (์ญ์ถ์ )
int[][] copyMap = new int[N][]; // ์ญ์ถ์ ์ ์ํ map
for(int i=0;i<N;i++){
copyMap[i] = Arrays.copyOf(map[i],N);
for(int j=0;j<N;j++){
if(copyMap[i][j] == 1) copyMap[i][j] = -1;
}
}
Deque<int[]> q = new ArrayDeque<>();
int mr,mc;
mr = medusa[0];
mc = medusa[1];
q.offer(new int[]{mr,mc,1});
copyMap[mr][mc] = 1;
while(!q.isEmpty()){
int[] cur = q.pollFirst();
int cr = cur[0];
int cc = cur[1];
int cnt = cur[2];
if(cr == park[0] && cc == park[1]){ // ์ต์ข
๋ชฉ์ ์ง ๊น์ง ๊ฐ์
break;
}
for(int d=0;d<4;d++){
int nr = cr + firstDr[d];
int nc = cc + firstDc[d];
if(isRange(nr,nc) && copyMap[nr][nc] == 0){
copyMap[nr][nc] = cnt + 1;
q.offer(new int[]{nr,nc,cnt + 1});
}
}
}
if(copyMap[park[0]][park[1]]==0){ // ๊ณต์๊น์ง ๊ฐ ์ ์๋ ๊ฒฝ์ฐ
return false;
}
/*
* for(int i=0;i<N;i++) { for(int j=0;j<N;j++) {
* System.out.printf("%2d",copyMap[i][j]); } System.out.println(); }
*/
// ์ต๋จ๊ฒฝ๋ก๋ฅผ ์ฐพ๊ธฐ (cnt ๊ฐ์ ์ญ์ถ์ )
q = new ArrayDeque<>();
q.offer(new int[]{park[0],park[1],copyMap[park[0]][park[1]]});
medusaWay.offer(new int[]{park[0],park[1]});
while(!q.isEmpty()){
int[] cur = q.pollFirst();
int cr = cur[0];
int cc = cur[1];
int cnt = cur[2];
if(cnt == 1){
medusaWay.pollFirst(); // ์ถ๋ฐ์์น๋ ํ์์ ์ญ์
break;
}
// ์ฐ ์ข ์ ํ
// ํ์ฌ cnt ๊ฐ ๋ณด๋ค 1 ์์ ์ขํ ์ฐพ๊ธฐ
for(int d=3;d>=0;d--){
int nr = cr + firstDr[d];
int nc = cc + firstDc[d];
if( isRange(nr,nc) && copyMap[nr][nc] == cnt - 1){
q.offer(new int[]{nr,nc,cnt-1});
medusaWay.offerFirst(new int[]{nr,nc});
break;
}
}
}
return true;
}
static int findDirWithWarrior(int mr, int mc, int wr, int wc) {
if(wr==mr) {
if(wc<mc) return 3;
if(wc>mc) return 1;
}else if(wc==mc) {
if(wr<mr) return 0;
if(wr>mr) return 2;
}
if(wr<mr && wc<mc) {
return 7;
}
if(wr<mr && wc>mc) {
return 4;
}
if(wr>mr && wc<mc) {
return 6;
}
if(wr>mr && wc>mc) {
return 5;
}
return -1;
}
static void makeShadow(int r,int c,int md, int d,int[][] sight) { // (r,c) ์ขํ์์ d ๋ฐฉํฅ์ผ๋ก ๊ทธ๋ฆผ์(-1) ์๊น
// ์ฒ์ (r,c) ์ขํ๋ ๊ทธ๋ฆผ์์์ ์ ์ธ
Deque<int[]> q = new ArrayDeque<>();
q.offer(new int[] {r,c});
while(!q.isEmpty()) {
int size = q.size();
int[] first_cur = q.peekFirst();
for(int i=0;i<size;i++) {
int[] cur = q.pollFirst();
int cr = cur[0];
int cc = cur[1];
int nr = cr + firstDr[md];
int nc = cc + firstDc[md];
if(isRange(nr,nc)) {
sight[nr][nc] = -1;
q.offer(new int[] {nr,nc});
}else {
/*
* System.out.println("๊ทธ๋ฆผ์ ๊ทธ๋ฆฐ ๊ฒฐ๊ณผ"); for(int a=0;a<N;a++) { for(int b=0;b<N;b++)
* { System.out.printf("%2d", sight[a][b]); } System.out.println(); }
* System.out.println();
*/
return;
}
}
if(d > 3) {
int nr,nc;
nr = first_cur[0] + eightDr[d];
nc = first_cur[1] + eightDc[d];
if(isRange(nr,nc)) {
q.offerFirst(new int[] {nr,nc});
sight[nr][nc] = -1;
}
}
}
}
static int checkSight(int r,int c,int d, int[][] medusaSight) { // (r,c) : ๋ฉ๋์ฌ์ ์ขํ
int cnt = 0;
System.out.printf("%d ๋ฐฉํฅ์ผ๋ก ๋ฐ๋ผ๋ดค์ ๋ \n",d);
Deque<int[]> q = new ArrayDeque<>();
q.offer(new int[] {r,c});
int flag = 0;
while(!q.isEmpty()) {
int size = q.size();
for(int i=0;i<size;i++) {
int[] cur = q.pollFirst();
int cr = cur[0];
int cc = cur[1];
if(warriorCnt[cr][cc] > 0 && medusaSight[cr][cc] == 1 ) {
System.out.printf("(%d, %d) ์ขํ ์ ์ฌ %d๊ฐ ๋๋ก ๋ณํจ \n",cr,cc,warriorCnt[cr][cc]);
cnt += warriorCnt[cr][cc];
int dir = findDirWithWarrior(r,c,cr,cc);
makeShadow(cr,cc,d,dir,medusaSight);
}
int nr = cr + firstDr[d];
int nc = cc + firstDc[d];
if(!isRange(nr,nc)) {
flag = 1;
continue;
}
if(medusaSight[nr][nc]!=-1) {
medusaSight[nr][nc] = 1;
}
q.offer(new int[] {nr,nc});
}
if(flag==1) break;
int nnr,nnc;
int[] p = q.peekFirst();
if(d==0 || d==1) { // ์ ํ
nnr = p[0];
nnc = p[1] - 1;
}else { // ์ข ์ฐ
nnr = p[0] - 1;
nnc = p[1];
}
if(isRange(nnr,nnc)) {
q.offerFirst(new int[] {nnr,nnc});
if(medusaSight[nnr][nnc]!=-1) medusaSight[nnr][nnc] = 1;
}
p = q.peekLast();
if(d==0 || d==1) { // ์ ํ
nnr = p[0];
nnc = p[1] + 1;
}else { // ์ข ์ฐ
nnr = p[0] + 1;
nnc = p[1];
}
if(isRange(nnr,nnc)) {
q.offerLast(new int[] {nnr,nnc});
if(medusaSight[nnr][nnc]!=-1) medusaSight[nnr][nnc] = 1;
}
}
return cnt;
}
static int findMedusaSight(int r,int c) {
int max = 0;
int maxD = -1;
for(int d=0;d<4;d++) {
int[][] mSight = new int[N][N];
int result = checkSight(r,c,d,mSight);
if(result > max ) {
max = result;
maxD = d;
medusaSight = mSight;
}
}
System.out.println(maxD + "๋ฐฉํฅ์ผ๋ก ๊ฒฐ์ ");
/*
* for(int i=0;i<medusaSight.length;i++) {
* System.out.println(Arrays.toString(medusaSight[i])); }
* System.out.println("-----------------");
*/
return max;
}
static int calcDistance(int r1,int c1, int r2, int c2) {
return Math.abs(r1-r2) + Math.abs(c1-c2);
}
static int[] moveWarrior() {
int moveCnt = 0, attackCnt = 0;
for(int i=0;i<M;i++) {
int warriorR = warriors[i].r;
int warriorC = warriors[i].c;
if(warriorR==-1) continue;
if(medusaSight[warriorR][warriorC]==1) continue;
int distance = calcDistance(medusa[0],medusa[1],warriorR,warriorC);
boolean isMoved = false;
// first move
for(int d=0;d<4;d++) {
int warriorNr = warriorR + firstDr[d];
int warriorNc = warriorC + firstDc[d];
if(!isRange(warriorNr, warriorNc)) continue;
if(medusaSight[warriorNr][warriorNc]==1) continue;
if( distance > calcDistance(medusa[0],medusa[1],warriorNr,warriorNc)) {
warriorCnt[warriorR][warriorC] -= 1;
warriors[i].r = warriorNr;
warriors[i].c = warriorNc;
warriorCnt[warriorNr][warriorNc] += 1;
isMoved = true;
moveCnt += 1;
break;
}
}
if(!isMoved) continue;
if(warriors[i].r == medusa[0] && warriors[i].c == medusa[1]) { // ๊ณต๊ฒฉ ๊ทธ๋ฆฌ๊ณ ์ฃฝ์
attackCnt += 1;
warriorCnt[warriors[i].r][warriors[i].c] -= 1;
warriors[i].r = -1;
warriors[i].c = -1;
continue; // ์ด ์กฐ๊ฑด์ ๋น ํธ๋ฆผ
}
warriorR = warriors[i].r;
warriorC = warriors[i].c;
distance = calcDistance(medusa[0],medusa[1],warriorR,warriorC);
for(int d=0;d<4;d++) {
int rd = (d+2)%4;
int warriorNr = warriorR + firstDr[rd];
int warriorNc = warriorC + firstDc[rd];
if(!isRange(warriorNr, warriorNc)) continue;
if(medusaSight[warriorNr][warriorNc]==1) continue;
if( distance > calcDistance(medusa[0],medusa[1],warriorNr,warriorNc)) {
warriorCnt[warriorR][warriorC] -= 1;
warriors[i].r = warriorNr;
warriors[i].c = warriorNc;
warriorCnt[warriorNr][warriorNc] += 1;
moveCnt += 1;
break;
}
}
if(warriors[i].r == medusa[0] && warriors[i].c == medusa[1]) {
attackCnt += 1;
warriorCnt[warriors[i].r][warriors[i].c] -= 1;
warriors[i].r = -1;
warriors[i].c = -1;
}
}
return new int[] {moveCnt,attackCnt};
}
static void print(int[][] arr) {
for(int i=0;i<arr.length;i++) {
for(int j=0;j<arr[i].length;j++) {
System.out.printf("%2d", arr[i][j]);
}
System.out.println();
}
System.out.println("------------------");
}
static void solve(){
// 0. ๋ฉ๋์ฌ์ ์ต๋จ๊ฒฝ๋ก ์ฐพ๊ธฐ (medusaWay ํ์ ๊ธฐ๋ก)
if(!findMedusaWay()) {
System.out.println(-1);
return;
}
StringBuilder sb = new StringBuilder();
while(true) {
// 1. ๋ฉ๋์ฌ ์ด๋
int[] way = medusaWay.pollFirst();
int nr = way[0];
int nc = way[1];
medusa[0] = nr;
medusa[1] = nc;
System.out.printf("๋ฉ๋์ฌ ์์น : (%d, %d) \n",medusa[0],medusa[1]);
if(medusa[0]==park[0] && medusa[1] == park[1]) {
sb.append(0);
break;
}
for(int m=0;m<M;m++) {
Warrior warrior = warriors[m];
if(warrior.r == -1) continue; // ์ด ์กฐ๊ฑด๋ ๋น ํธ๋ฆผ
if(warrior.r == medusa[0] && warrior.c == medusa[1]) {
warriorCnt[warrior.r][warrior.c] -= 1;
warrior.r = -1;
warrior.c = -1;
System.out.printf("%d ๋ฒ ์ ์ฌ ์ด๋ํ ๋ฉ๋์ฌ์๊ฒ ์กํ\n",m);
}
}
System.out.println("warriorCnt[][]");
print(warriorCnt);
// 2. ๋ฉ๋์ฌ ์์
int stoneCnt = findMedusaSight(medusa[0],medusa[1]);
System.out.println("๋ฉ๋์ฌ ์์ ");
print(medusaSight);
System.out.printf("๋์ด ๋ ์ ์ฌ์ ์ : %d \n", stoneCnt);
// 3. ์ ์ฌ๋ค ์ด๋
int[] warriorMoveResult = moveWarrior();
System.out.println("์ ์ฌ๋ค์ ์ด๋ ํ ๊ฒฐ๊ณผ");
print(warriorCnt);
sb.append(warriorMoveResult[0]).append(" ").append(stoneCnt).append(" ").append(warriorMoveResult[1]).append("\n");
}
System.out.println(sb.toString());
}
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
Deque<Integer> dq = new ArrayDeque<>();
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
map = new int[N][N];
warriors = new Warrior[M];
warriorCnt = new int[N][N];
medusa = new int[2];
park = new int[2];
st = new StringTokenizer(br.readLine());
medusa[0] = Integer.parseInt(st.nextToken());
medusa[1] = Integer.parseInt(st.nextToken());
park[0] = Integer.parseInt(st.nextToken());
park[1] = Integer.parseInt(st.nextToken());
medusaWay = new ArrayDeque<>();
st = new StringTokenizer(br.readLine());
for(int i=0;i<M;i++){
int r,c;
r = Integer.parseInt(st.nextToken());
c = Integer.parseInt(st.nextToken());
warriors[i] = new Warrior(r,c);
warriorCnt[r][c] += 1;
}
for(int i=0;i<N;i++){
st = new StringTokenizer(br.readLine());
for(int j=0;j<N;j++){
map[i][j] = Integer.parseInt(st.nextToken());
}
}
solve();
}
}
'๐์ฝ๋ฉํ ์คํธ:CodingTest' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[PCCP ๋ชจ์๊ณ ์ฌ #1] 4๋ฒ - ์ด์์ฒด์ (0) | 2024.12.12 |
---|---|
PCCP ๋ชจ์๊ณ ์ฌ1ํ 3๋ฒ (0) | 2024.12.11 |
2024 ์ผ์ฑSW์ญ๋ํ ์คํธ ํ๋ฐ๊ธฐ ์ค์ 1๋ฒ (0) | 2024.12.02 |
์์ด(n๊ณผm ๋ฌธ์ ) ์ต์ ํ ์ํค๊ธฐ && ์กฐํฉ (0) | 2024.10.29 |
[HSAT 4ํ ์ ๊ธฐ ์ฝ๋ฉ ์ธ์ฆํ๊ฐ ๊ธฐ์ถ] ํต๊ทผ๋ฒ์ค ์ถ๋ฐ ์์ ๊ฒ์ฆํ๊ธฐ (0) | 2024.06.28 |