Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions sep037/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## ✏️ 기둝
## ✏️ 기둝

<img width="498" alt="스크란샷 2025-04-05 14 43 30" src="https://github.com/user-attachments/assets/6acb9b5b-e94a-46e8-9b5c-529cdd282bd8" />


| μ°¨μ‹œ | λ‚ μ§œ | λ¬Έμ œμœ ν˜• | 링크 | 풀이 |
|:----:|:---------:|:----:|:-----:|:----:|
| 1μ°¨μ‹œ | 2024.10.01 | κ΅¬ν˜„ | [μΆ”μ–΅ 점수](https://school.programmers.co.kr/learn/courses/30/lessons/176963)|https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/35|
| 1μ°¨μ‹œ | 2025.04.05 | κ΅¬ν˜„ | [숫자 μ •μ‚¬κ°ν˜•](https://www.acmicpc.net/problem/1051)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/6|
---
49 changes: 49 additions & 0 deletions sep037/κ΅¬ν˜„/BOJ_1051.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// main.swift
// 1051
//
// Created by Seungeun Park on 4/5/25.
//

import Foundation

let firstLine = readLine()!.split(separator: " ").map {Int($0)!}
let n = firstLine[0] // ν–‰
let M = firstLine[1] // μ—΄

var grid: [[Int]] = [] // μΆ”κ°€ν•΄μ•Ό ν•˜λ‹ˆκΉŒ var
for _ in 0..<n { // μ€„λ‘œ μž…λ ₯ λ°›μ•„ 2차원 λ°°μ—΄ λ§Œλ“€κΈ°
let row = readLine()!.map {Int($0)!} // 이곳이 λ°”λ‘œ 문제의 λΆ€λΆ„ !
grid.append(row)
}
Comment on lines +15 to +18
Copy link
Member

Choose a reason for hiding this comment

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

let row = readLine()!.map {Int($0)!} // 이곳이 λ°”λ‘œ 문제의 λΆ€λΆ„ !

μ—¬κΈ° λΆ€λΆ„ 였λ₯˜ μ•ˆλ‚˜μ‹œλ‚˜μš”??

let row = readLine()!.map {Int(String($0))!} // 이곳이 λ°”λ‘œ 문제의 λΆ€λΆ„ !

Int()λŠ” String νƒ€μž…λ§Œ 받을 수 μžˆλŠ”λ°, map()μ΄λ‚˜ compactMap()은 String을 λ°›κ³  각 문자λ₯Ό Character둜 λ΄μ„œ
이λ₯Ό String으둜 λ³€ν™˜μ„ ν•˜μ§€ μ•ŠμœΌλ©΄ Int()둜 λž˜ν•‘μ΄ μ•ˆλ˜λŠ”κ±Έλ‘œ μ•Œκ³ μžˆμ–΄μ„œμš”!!


스크란샷 2025-04-06 20 41 56

뭐지 ν•˜κ³  λŒλ €λ΄€λŠ”λ° μ €λŠ” 였λ₯˜κ°€ λœ¨λ„€μš”..?? λ²„μ „λ§ˆλ‹€ 차이가 μžˆλ‚˜μš” 이거.. μ•„μ‹œλŠ”λΆ„.. γ… γ… 

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ν—‰ 이거 μ œκ°€ 잘λͺ» μ˜¬λ Έμ–΄μš”
λ°±μ€€μ—λŠ” μ €λ ‡κ²Œ 풀어놓고 γ…‹γ…‹γ…‹γ…‹

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

스크란샷 2025-04-07 17 03 55 길이 맞음 .ᐟ.ᐟ

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

μ–΄λ €μ›‘

Copy link
Member

Choose a reason for hiding this comment

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

@sep037 그렇ꡰ뇨 γ…‹γ…‹γ…‹ κ΅Ώκ΅Ώ!!


func largestSquare(grid: [[Int]]) -> Int {
let n = grid.count
let m = grid[0].count
var maxLength = 1
Comment on lines +20 to +23
Copy link
Member

Choose a reason for hiding this comment

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

ν•¨μˆ˜λ‘œ λ§Œλ“ κ±΄ 쒋은데 μ΄λΆ€λΆ„μ—μ„œ
n,m을 λ‹€μ‹œ gridλ₯Ό κΈ°μ€€μœΌλ‘œ countν•΄μ„œ μ‹œκ°„μ„ 쑰금 λŠ˜λ¦¬λŠ” 것 κ°™μ•„μ„œ

차라리 λ§€κ°œλ³€μˆ˜λ‘œ λ°›κ±°λ‚˜ mainμ—μ„œ ν‘ΈλŠ”κ²Œ μ‹œκ°„λ³΅μž‘λ„κ°€ λΉ‘λΉ‘ν•œ λ¬Έμ œμ—μ„œλŠ” 쒋을 것 κ°™μ•„μš”!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

λ³΅μž‘λ„ κ΄€λ ¨ν•΄μ„œ 항상 효율적인 μ½”λ“œ μ§œλŠ” 게 μ–΄λ €μš΄ 것 κ°™μ•„μš” πŸ₯Ή
많이 ν’€μ–΄μ„œ 감을 μ˜¬λ €λ³Όκ²Œμš” , ,


for i in 0..<n {
for j in 0..<m {
for k in 1..<min(n-i, m-j){ // λ°°μ—΄ λ²—μ–΄λ‚˜λ©΄ μ•ˆλ˜λ‹ˆκΉŒ !μ΅œμ†Œν•œμ˜ μ •μ‚¬κ°ν˜• 크기 작기
let a = grid[i][j]
let b = grid[i][j+k]
let c = grid[i+k][j]
let d = grid[i+k][j+k]
// 각 꼭짓점에 μžˆλŠ” 숫자 λ‹΄κΈ°

if a == b && a == c && a == d { // λ‹€ ν™•μΈν•˜κΈ°
maxLength = max(maxLength, (k+1)*(k+1)) // μ™œ 1을 λ”ν•˜λƒλ©΄ λ³€μ˜ 길이가 2일 λ•Œ, μˆ«μžλŠ” 3κ°œκ°€ 있음 !
/*
1 1 1
1 1 1
1 1 1
λ³€μ˜ 길이가 2여도 μˆ«μžλŠ” 3개 μžˆμ–΄μ„œ ,,
*/
}
}
}
}
return maxLength
}
Comment on lines +25 to +47
Copy link
Collaborator

Choose a reason for hiding this comment

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

였 κΈ€λ‘œλ‹ˆ ! μ΅œμ†Œ 크기뢀터 ν•˜μ…¨κ΅°μš”. μ €λŠ” 사싀 μ •μ‚¬κ°ν˜•μ„ μ•Œμ•„λ‚΄λŠ”κ²Œ μ‰½μ§€μ•Šμ•„μ„œ μ—΄λ°›μ•„μ„œ μžˆλ‹€κ°€, 제일 ν°κ²ƒμ—μ„œλΆ€ν„° μ²΄ν¬ν•˜λ©΄μ„œ λ‚΄λ €μ˜€λ©΄ μ–΄λ–¨κΉŒν•΄μ„œ

min_range = min(n,m) - 1
max_value = 1
    
for i in range(n):
    for j in range(m):
        for l in range(min_range,0,-1):
            if i+l < n and j+l < m:
                if graph[i][j] == graph[i+l][j] == graph[i][j+l] == graph[i+l][j+l]:
                    max_value = max(max_value, (l+1)**2)
                    break

print(max_value)

파이썬 μ½”λ“œμ΄κΈ΄ ν•˜μ§€λ§Œ, λ¨Όμ € μ •μ‚¬κ°ν˜•μ΄ 되렀면 ν–‰κ³Ό μ—΄μ€‘μ—μ„œ 더 μž‘μ€ 숫자 바이 더 μž‘μ€ μˆ«μžν•˜λ©΄ 그게 μ•„λ§ˆ μ •μ‚¬κ°ν˜• λ³€μ˜ 졜고 μˆ˜μΉ˜μ§€μ•Šμ„κΉŒ? κ±°κΈ°μ„œλΆ€ν„° λ„“μ΄κ΅¬ν•΄μ„œ 계속 κ°±μ‹ ν•΄λ‚˜κ°€λ©΄ λ­”κ°€ 빨리 λ‚˜μ˜€μ§€ μ•Šμ„κΉŒ? ν•΄μ„œ ν–ˆλŠ”λ° μ•„λ§ˆ κ²°κ΅­μ—” μ™„νƒμœΌλ‘œ κ΅¬ν˜„μ„ ν•΄μ„œ μ–΄μ°¨ν”Ό μ²«λ²ˆμ§Έκ°€ κ°€μž₯ 큰거라면 μ•„λž«κ²ƒλ“€μ€ λΉ„κ΅ν•˜μ§€ μ•ŠλŠ”λ‹€λ©΄ μ–΄λ–¨κΉŒ μ‹Άλ„€μš”.

λ„μœ½ ... μ‰¬μš΄ 문제라고 ν•˜μ§€λ§Œ μ €ν•œν… μ–΄λ €μ› λŠ”λ° 정말 갈길이 λ©€κ΅°μš”.. 인덱슀 μž₯λ‚œκ³Ό λ§ˆμ§€λ§‰ for문의 변길이 츑정이 아이디어 λ„μΆœμ΄ 많이 μ–΄λ €μ› λ„€μš” ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

μ—„μ²­ κΉ”λ”ν•˜κ²Œ μž˜ν‘Έμ…¨λ„€μš” !
ν‘ΈλŠ” λ°©μ‹μ—μ„œ 큰 μ°¨μ΄λŠ” μ—†κ³ , 저도 λ°λ―Έμ•ˆκ³Ό 거의 λ™μΌν•œ μ½”λ“œμž…λ‹ˆλ‹€ !
μ €λŠ” λ‘˜ μ‚¬μ΄μ˜ min(N,M)을 κΈ°μ€€μœΌλ‘œ 큰 λ³€λΆ€ν„° κΉŽμ•„κ°€λ©΄μ„œ νŒλ‹¨ν•΄μ€„κ²ƒμΈμ§€, μž‘μ€κ°’λΆ€ν„° μ˜¬λΌκ°€λ©΄μ„œ νŒλ‹¨ν•΄μ€„ 것인지가 차이가 μžˆλŠ” 것 κ°™λ„€μš”! μ’€ μ½”λ“œκ°€ 정신이 없을 μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€..!

import Foundation

func solution(_ N: Int, _ M: Int, _ graph: [[Int]]) -> Int {
    let LEN = min(N, M)
    for width in stride(from: LEN - 1, to: 0, by: -1) {
        for i in 0 ..< N - width {
            for j in 0 ..< M - width {
                let standard = graph[i][j]
                if standard == graph[i][j + width] {
                    if standard == graph[i + width][j] && standard == graph[i + width][j + width] {
                        return (width + 1) * (width + 1)
                    }
                }
            }
        }
    }

    return 1
}

// μ§€λ‚œλ²ˆμ— μž…λ ₯받은 λΆ€λΆ„ μž¬ν™œμš© 

let NM = readLine()!.split(separator: " ").map { Int($0)! }
let N = NM[0]
let M = NM[1]
var arr: [[Int]] = []

for _ in 0 ..< N {
    arr.append(readLine()!.map { Int(String($0))! })
}

print(solution(N, M, arr))

Copy link
Collaborator

@MuchanKim MuchanKim Apr 9, 2025

Choose a reason for hiding this comment

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

ν•€ 제 μž…λ ₯λ°›κΈ° μŠ΅λ“ν•˜μ‹ κ±΄κ°€μš” μ „ n, m만 받도둝 ν–ˆλŠ”λ° ν•€μ²˜λŸΌν•˜λŠ”κ²Œ ν•¨μˆ˜ μ˜λ„κ°€ λͺ…ν™•ν•΄μ§€λŠ” 것 κ°™λ„€μš”. 잘 배우고 κ°‘λ‹ˆλ‹€^^
μ „ μ•„λž˜μ²˜λŸΌ ν–ˆμ–΄μš”. ν•¨μˆ˜ μ˜λ„ κ³ λ €ν•˜λ©΄μ„œ μ§œμ•Όκ² μŠ΅λ‹ˆλ‹€ λ‹€μŒλΆ€ν„°.

func solution(_ n: Int, _ m: Int) -> Int {
// μƒλž΅
let nm = readLine()!.split(separator: " ").map { Int($0)! }
let n = nm[0]
let m = nm[1]

print(solution(n, m))

Comment on lines +25 to +47
Copy link
Collaborator

Choose a reason for hiding this comment

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

저도 λ°λ―Έμ•ˆμ΄λž‘ λΉ„μŠ·ν•œ 질문인데 μž‘μ€ 것뢀터 μ²΄ν¬ν•˜μ‹  μ΄μœ κ°€ μžˆμ„κΉŒμš”?? μ €λŠ” 문제보고 λ”± 큰거뢀터 체크 ν•΄μ•Όκ² λ‹€κ³  생각이 λ“€μ—ˆκ±°λ©μš”.

μ œκ°€ 큰 κ±°λΆ€ν„° 찾은 μ΄μœ λŠ” λ¬Έμ œμ—μ„œ 'κ°€μž₯ 큰 μ •μ‚¬κ°ν˜•'을 찾으라고 ν•΄μ„œμž„μš”.(λ‹¨μˆœ)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ν—‰ κ·ΈλŸ°κ°€μš” ..! μ €λŠ” μž‘μ€ 것뢀터 μ°Ύμ•„μ„œ 더 큰 게 없을 λ•ŒκΉŒμ§€ 찾으렀고 κ·Έλƒ₯ λ°”λ‘œ 생각이 λ“€μ—ˆλŠ”λ° 큰 것뢀터 κ°€λŠ” κ±Έλ‘œλ„ ν•œ 번 ν’€μ–΄λ΄μ•Όκ² μ„œνš¨


print(largestSquare(grid: grid))