Skip to content

Conversation

@wnsmir
Copy link
Collaborator

@wnsmir wnsmir commented Sep 5, 2025

πŸ”— 문제 링크

https://www.acmicpc.net/problem/15685

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

1h

✨ μˆ˜λ„ μ½”λ“œ

상어λ₯Ό μž‘κΈ°μ „ λͺΈν’€κΈ°λ¬Έμ œλ‘œ ν•œλ²ˆ ν’€μ–΄λ³΄μ•˜μŠ΅λ‹ˆλ‹€.
이 λ¬Έμ œμ—μ„œ μƒκ°ν–ˆλ˜μ μ€ λ”± λ‘κ°€μ§€μ˜€μŠ΅λ‹ˆλ‹€.

쀑심점이 μžˆλŠ” μƒνƒœμ—μ„œμ˜ νšŒμ „, λ§ˆμ§€λ§‰ μ’Œν‘œ 즉 λ‹€μŒ 쀑심점을 μ–΄λ–»κ²Œ μ—…λ°μ΄νŠΈν•΄μ£Όμ–΄μ•Ό ν•  것인가?

쀑심점이 μžˆλŠ” νšŒμ „μ€

def rot90(p, pivot):
    x, y = p
    px, py = pivot
    return (px - (y - py), py + (x - px))

μ΄λ ‡κ²Œ μ²˜λ¦¬ν•΄μ£Όμ—ˆμŠ΅λ‹ˆλ‹€.

λ‹€μŒ 쀑심점을 μ²˜λ¦¬ν•˜λŠ”κ²Œ μ’€ μ‹œκ°„μ΄ 많이 κ±Έλ ΈλŠ”λ° μ²˜μŒμ—λŠ” μ‹œμž‘μ μ—μ„œ bfs둜 κ°€μž₯λ©€λ¦¬μžˆλŠ” 점을 μ°Ύμ•„μ„œ 맀번 μ—…λ°μ΄νŠΈμ‹œμΌœμ€„κΉŒ ν–ˆμ§€λ§Œ λ„ˆλ¬΄ νˆ¬λ¨ΈμΉ˜μΈκ²ƒ κ°™μ•„ 쒀더 생각해본 κ²°κ³Ό

νšŒμ „ν•΄μ„œ μƒˆ λ¦¬μŠ€νŠΈμ— μΆ”κ°€ν•΄μ€„λ•Œ μ€‘μ‹¬μ μœΌλ‘œ λΆ€ν„° κ°€κΉŒμš΄μ λ“€λΆ€ν„° μΆ”κ°€ν•΄μ£Όλ©΄ λ§ˆμ§€λ§‰μ— μΆ”κ°€λ˜λŠ”μ μ΄ λ§ˆμ§€λ§‰μ μ΄ λ˜λŠ” 점을 μ΄μš©ν–ˆμŠ΅λ‹ˆλ‹€.
즉 μ€‘μ‹¬μ μœΌλ‘œλΆ€ν„° κ°€κΉŒμš΄μ μ„ λ¨Όμ € μΆ”κ°€ν•΄μ£Όλ €λ©΄ μ΄μ „μ„ΈλŒ€μ˜ 점듀을 λ’€μ—μ„œλΆ€ν„° μˆœνšŒν•˜λ©° μ„Έ μ„ΈλŒ€ 뒀에 ν•˜λ‚˜μ”© μΆ”κ°€ν•΄μ€λ‹ˆλ‹€.

그럼 제일 λ§ˆμ§€λ§‰μ›μ†Œκ°€ 늘 λ‹€μŒ νšŒμ „μ˜ 쀑심점이 λ©λ‹ˆλ‹€.

이후 κ΅¬ν˜„μ€ μ‰½κ²Œ ν•˜μ‹€ 수 μžˆμ„κ²λ‹ˆλ‹€!
I, jλ₯Ό μˆœνšŒν•˜λ©° 였λ₯Έμͺ½, μ•„λž˜, 였λ₯Έμͺ½μ•„λž˜ 3점이 λͺ¨λ‘ 1이면 answer += 1 ν•˜λ„λ‘ κ°„λ‹¨ν•˜κ²Œ κ΅¬ν˜„ν–ˆμŠ΅λ‹ˆλ‹€.
(늘 μš°ν•˜ν–₯ν•˜κΈ° 뗴문에 μ€‘λ³΅μ—†μŒ)

μ•„ 참고둜 x y의 λ°©ν–₯이 일반적이 λ¬Έμ œμ™€λŠ” λ°˜λŒ€μ—¬μ„œ 신경써주어야 ν•©λ‹ˆλ‹€.

N = int(input())
grid = [[0]*101 for _ in range(101)]

def rot90(p, pivot):
    x, y = p
    px, py = pivot
    return (px - (y - py), py + (x - px))

def curve(last_gen, last_spot):
    new_gen = last_gen[:]
    for dot in reversed(last_gen[:-1]): # 쀑심 μ œμ™Έ μ—­μˆœμœΌλ‘œ
        nx, ny = rot90(dot, last_spot)
        if 0 <= nx <= 100 and 0 <= ny <= 100:
            grid[ny][nx] = 1
        new_gen.append((nx, ny))
    return new_gen, new_gen[-1]

for _ in range(N):
    x, y, d, g = map(int, input().split())

    last_gen = [(x, y)]
    grid[y][x] = 1

    # 0μ„ΈλŒ€ λ§Œλ“€κΈ°
    if d == 0:
        last_spot = (x+1, y)
    elif d == 1:
        last_spot = (x, y-1)
    elif d == 2:
        last_spot = (x-1, y)
    else:
        last_spot = (x, y+1)

    last_gen.append(last_spot)
    lx, ly = last_spot
    if 0 <= lx <= 100 and 0 <= ly <= 100:
        grid[ly][lx] = 1

    # g μ„ΈλŒ€μˆ˜λ§ŒνΌ
    for _ in range(g):
        last_gen, last_spot = curve(last_gen, last_spot)

# μ‚¬κ°ν˜• 개수
answer = 0
for y in range(100):
    for x in range(100):
        if grid[y][x] == 1 and grid[y][x+1] == 1 and grid[y+1][x] == 1 and grid[y+1][x+1] == 1:
            answer += 1

print(answer)

Copy link
Member

@9kyo-hwang 9kyo-hwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

문제 자체λ₯Ό λ„μ €νžˆ 이해 λͺ»ν•˜κ² μ–΄μ„œ PR을 λ°”λ‘œ λ΄€λŠ”λ°λ„ 이해가 μ•ˆκ°”μŠ΅λ‹ˆλ‹€... κ·Έλž˜μ„œ λ‹€λ₯Έ λΈ”λ‘œκ·Έλ₯Ό λ³΄λ‹ˆκΉŒ μ•„μ˜ˆ λ‹€λ₯Έ λ°©μ‹μœΌλ‘œ μ ‘κ·Όν•˜λ”λΌκ΅¬μš”.

λ°©ν–₯ 였λ₯Έμͺ½μ„ 0, μœ„λ₯Ό 1, μ™Όμͺ½μ„ 2, μ•„λž˜μͺ½μ„ 3이라 λ§€ν•‘ν•˜κ³  λ¬Έμ œμ—μ„œ μ£Όμ–΄μ§„ μ˜ˆμ‹œλ₯Ό 확인해보면, μ•„λž˜μ™€ 같이 μ΄λ™ν•©λ‹ˆλ‹€.

gen 0: 0
gen 1: 0 1
gen 2: 0 1 2 1
gen 3: 0 1 2 1 2 3 2 1

μ„ΈλŒ€κ°€ 증가할 λ•Œλ§ˆλ‹€ λ°©ν–₯ 정보가 2λ°°μ”© λŠ˜μ–΄λ‚˜λŠ”λ°, 이λ₯Ό λŒ€μΉ­μ μœΌλ‘œ 확인해보면 λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

gen 1: 0 1
gen 2: 0 1 / 2 1
gen 2: 0 1 2 1
gen 3: 0 1 2 1 / 2 3 2 1

봐도 λͺ¨λ₯΄κ² μŠ΅λ‹ˆλ‹€. 더 λ“€μ–΄κ°€λ³΄κ² μŠ΅λ‹ˆλ‹€. ν•œ 번 λ‹€μŒ μ„ΈλŒ€μ˜ λ’€ μ ˆλ°˜μ„ λ’€μ§‘μ–΄λ³΄κ² μŠ΅λ‹ˆλ‹€.

gen 1: 0 1
gen 2: 0 1 / 1 2
gen 2: 0 1 2 1
gen 3: 0 1 2 1 / 1 2 3 2

μ΄μ œμ•Ό μ’€ λ³΄μž…λ‹ˆλ‹€. λ’€ μ ˆλ°˜μ€ 이전 μ„ΈλŒ€ λ°©ν–₯ 정보에 +1을 ν•œ 것을 μ—­μˆœμœΌλ‘œ λ‚˜μ—΄ν•œ κ²ƒμž…λ‹ˆλ‹€. 3 -> 4λ₯Ό κ°€λŠ” κ²½μš°μ—λ§Œ λͺ¨λ“ˆλŸ¬ 연산을 톡해 0으둜 돌리면 λ©λ‹ˆλ‹€.

이거λ₯Ό 기반으둜 μ½”λ“œλ₯Ό μž‘μ„±ν•˜λ©΄ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

Details

#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int N; cin >> N;
    vector<vector<bool>> board(101, vector<bool>(101, false));
    array<int, 4> dx{0, -1, 0, 1};  // R U L D
    array<int, 4> dy{1, 0, -1, 0};
    
    int x, y, d, g;
    while(N--) {
        cin >> y >> x >> d >> g;
        vector<int> directions;
        directions.reserve(1 << g);
        
        board[x][y] = true;
        
        x += dx[d]; y += dy[d];
        board[x][y] = true;
        directions.push_back(d);
        
        while(g--) {
            for(auto it = directions.rbegin(); it != directions.rend(); ++it) {
                int nd = (*it + 1) & 0b11;
                x += dx[nd]; y += dy[nd];
                board[x][y] = true;
                directions.push_back(nd);
            }
        }
    }
    
    int ans = 0;
    for(int i = 1; i < 100; ++i) {
        for(int j = 1; j < 100; ++j) {
            if(board[i][j] && board[i + 1][j] && board[i][j + 1] && board[i + 1][j + 1]) {
                ++ans;
            }
        }
    }
    
    cout << ans;

    return 0;
}

κ²°λ‘ : shit!

Copy link
Collaborator

@kokeunho kokeunho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 이 문제λ₯Ό 며칠전에 ν’€μ–΄λ΄€μŠ΅λ‹ˆλ‹€.
처음 봀을 λ•Œ 저도 λ„μ €νžˆ 이전 μ„ΈλŒ€μ˜ λͺ¨μ–‘을 μ–΄λ–»κ²Œ νšŒμ „ μ‹œμΌœμ•Όν• μ§€ λ– μ˜¬λ¦΄ 수 μ—†μ—ˆμŠ΅λ‹ˆλ‹€.

list에 이동 λ°©ν–₯을 λ‹΄μŠ΅λ‹ˆλ‹€.
μ„ΈλŒ€κ°€ λ„˜μ–΄κ°€λ©΄
이전 μ„ΈλŒ€ 이동 λ°©ν–₯ 리슀트의 λ’€μ—μ„œλΆ€ν„° μš”μ†Œλ₯Ό λΉΌμ„œ +1ν•˜κ³ 
κ·Έ 값을 이전 μ„ΈλŒ€ 이동 λ°©ν–₯ λ¦¬μŠ€νŠΈμ— μΆ”κ°€ν•©λ‹ˆλ‹€.

μž…λ ₯ 받은 μ„ΈλŒ€ gen에 λ„λ‹¬ν•˜μ˜€λ‹€λ©΄
이동 λ°©ν–₯을 따라가며 map에 λ“œλž˜κ³€μ»€λΈŒλ₯Ό ν‘œμ‹œν•©λ‹ˆλ‹€.

λ„€ 꼭짓점이 λ“œλž˜κ³€ μ»€λΈŒμ— ν•΄λ‹Ήν•˜λŠ” 칸은
map[i][j], map[i+1][j], map[i][j+1], map[i+1][j+1]의 값이
λͺ¨λ‘ 1인 경우λ₯Ό μΉ΄μš΄νŠΈν•˜λ©΄ λ©λ‹ˆλ‹€.

저도 μ‚Όμ „ 문제λ₯Ό λͺ‡κ°œ 풀어보고 μžˆλŠ”λ°
νšŒμ „μ„ 정말 μ’‹μ•„ν•˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€.
그런데 정말 λ‹€μ–‘ν•œ νšŒμ „μ„ κ΅¬ν˜„ν•΄μ•Όν•΄μ„œ νž˜λ“œλ„€μš”;

μˆ˜κ³ ν•˜μ…¨μŠ΅λ‹ˆλ‹€.

Details

import java.io.*;
import java.util.*;

public class Main {
    static int N;
    static int[][] map = new int[101][101];
    static int[] dx = {1, 0, -1, 0};
    static int[] dy = {0, -1, 0, 1};

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st = new StringTokenizer(br.readLine());
        N = Integer.parseInt(st.nextToken());

        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(br.readLine());

            int x = Integer.parseInt(st.nextToken());
            int y = Integer.parseInt(st.nextToken());
            int d = Integer.parseInt(st.nextToken());
            int gen = Integer.parseInt(st.nextToken());
            dragonCurve(x, y, d, gen);
        }
        System.out.print(checkBox());
    }
    static void dragonCurve(int x, int y, int d, int gen) {
        List<Integer> path = new ArrayList<>();
        path.add(d);

        int count = 0;
        while (count < gen) {

            for (int i = path.size()-1; i >= 0; i--) {
                path.add((path.get(i)+1) % 4);
            }

            count++;
        }

        map[y][x] = 1;
        for (int i : path) {
            x += dx[i];
            y += dy[i];
            map[y][x] = 1;
        }
    }

    static int checkBox() {
        int response = 0;

        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 100; j++) {
                if (map[i][j] == 1 && map[i+1][j] == 1 && map[i][j+1] == 1 && map[i+1][j+1] == 1) {
                    response++;
                }
            }
        }

        return response;
    }
}

@wnsmir wnsmir merged commit a3cf623 into main Nov 16, 2025
1 check passed
@kangrae-jo
Copy link
Collaborator

μ€€ λ“œλ ˆκ³€μ˜ λ“œλ ˆκ³€ 컀브 문제

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants