Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

19-wkdghdwns199 #76

Merged
merged 2 commits into from
Apr 29, 2024
Merged

19-wkdghdwns199 #76

merged 2 commits into from
Apr 29, 2024

Conversation

wkdghdwns199
Copy link
Collaborator

πŸ”— 문제 링크

인사성 밝은 곰곰이
https://www.acmicpc.net/problem/25192

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

30λΆ„ - set ν•¨μˆ˜ 쀑볡 μ œκ±°μ— νƒμ›”ν•˜λ„€μš”!

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

ENTER λ¬Έμžμ—΄μ΄ λ“€μ–΄μ˜€λŠ” μ‹œμ μ—μ„œ 뒀에 μž…λ ₯λ˜λŠ” μ‚¬μš©μž λ¬Έμžμ—΄λ“€μ˜ 수λ₯Ό μ„Έμ„œ 더해주면 λ©λ‹ˆλ‹€! ν•˜μ§€λ§Œ μ—¬κΈ°μ„œ 쑰건 ν•˜λ‚˜!

처음 μ±„νŒ…μ„ μž…λ ₯ν•˜λŠ” μ‚¬λžŒμ€ λ°˜λ“œμ‹œ κ³°κ³°ν‹°μ½˜μœΌλ‘œ 인사λ₯Ό ν•œλ‹€. κ·Έ μ™Έμ˜ 기둝은 κ³°κ³°ν‹°μ½˜μ„ 쓰지 μ•Šμ€ ν‰λ²”ν•œ μ±„νŒ… 기둝이닀.

이λ₯Ό 보면 ν•œ 번 카운트 된 μ‚¬μš©μžλŠ” λ‹€μ‹œ 카운트 되면 μ•ˆλœλ‹€λŠ” 말이닀. 즉, 쀑볡이 되면 μ•ˆλœλ‹€λŠ” λ§μž…λ‹ˆλ‹€.

μ§€κΈˆκΉŒμ§€ 쀑볡 μ œκ±°μ— λŒ€ν•΄ μ‚½μ§ˆν•˜λ‹€ κ²°κ΅­ μ²΄λ“ν•œ set() ν•¨μˆ˜λ₯Ό λ°”λ‘œ λ– μ˜¬λ €μ„œ ENTER κ°€ λ“€μ–΄μ˜¨ ν›„λŠ” 항상 set에 μ‚¬μš©μž 이름 λ¬Έμžμ—΄μ„ μ§‘μ–΄λ„£μ–΄μ„œ 쀑볡 제거λ₯Ό ν•˜μ˜€μŠ΅λ‹ˆλ‹€. 그리고 λ‹€λ₯Έ ENTER κ°€ λ“€μ–΄μ˜¬ λ•Œ λ§ˆλ‹€ set 을 μ΄ˆκΈ°ν™”ν•˜μ—¬ λ‹€μ‹œ 이λͺ¨ν‹°μ½˜μ„ μ“°λŠ” μ‚¬μš©μžλ“€μ„ 카운트 ν•΄μ€λ‹ˆλ‹€.

μ½”λ“œ μˆœμ„œ

  1. μ²˜μŒμ— 초기 set μžλ£Œν˜•μ„ λ§Œλ“ λ‹€.
  2. λ§Œμ•½ ENTER λ¬Έμžμ—΄μ΄ λ“€μ–΄μ˜€λ©΄, 처음 ENTER λ¬Έμžμ—΄μΈμ§€ ν™•μΈν•˜κ³ , 처음이면 μ΄μ œλΆ€ν„°λŠ” set에 μžˆλŠ” μ‚¬μš©μžλ“€μ„ μΉ΄μš΄νŠΈν•΄μ„œ count 에 λˆ„μ ν•œλ‹€.
  3. ENTER λ¬Έμžμ—΄μ΄ λ“€μ–΄μ˜€λ©΄ set 을 μ΄ˆκΈ°ν™”ν•΄μ€€λ‹€.
  4. λ§ˆμ§€λ§‰μ— 카운트 된 μ‚¬μš©μžλ“€μ„ μΉ΄μš΄νŠΈν•΄μ„œ count dp ν•œ 번 더 λˆ„μ ν•΄μ€€λ‹€. (λ§ˆμ§€λ§‰μ—λŠ” ENTER κ°€ μ•ˆ λ“€μ–΄μ™€μ„œ μΉ΄μš΄νŠΈκ°€ λ˜μ§€ μ•Šμ•„μ„œ)
  5. λˆ„μ  κ°’ count λ₯Ό 좜λ ₯ν•΄μ€€λ‹€.
import sys
input = sys.stdin.readline
N = int(input())
emoji_using_users = set()
time_for_emoji_use = False
emoji_use_count = 0
for _ in range(N):
    chat_string = input().rstrip()
    if chat_string == 'ENTER' :
        if time_for_emoji_use :
            emoji_use_count += len(emoji_using_users)
        else :
            time_for_emoji_use = True
        emoji_using_users = set()
    else :
        emoji_using_users.add(chat_string)

emoji_use_count+=len(emoji_using_users)
print(emoji_use_count)

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

μ΄μ œλΆ€ν„°λŠ” νƒœκ·œ λ‹˜μ΄ λΉŒλ €μ£Όμ‹œλŠ” μ•Œκ³ λ¦¬μ¦˜ μ±… 보고 곡뢀해봐야겠닀! (λ°±μ€€ μž μ‹œ μ•ˆλ…•..!)

Copy link
Collaborator

@SeongHoonC SeongHoonC left a comment

Choose a reason for hiding this comment

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

저도 거의 λ˜‘κ°™μ΄ ν’€μ—ˆλ„€μš”

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()
    var set = mutableSetOf<String>()
    var answer = 0
    for (i in 0 until n) {
        val input = br.readLine()
        if (input == "ENTER") {
            answer += set.size
            set = mutableSetOf()
            continue
        }
        set.add(input)
    }
    answer += set.size
    println(answer)
}

for _ in range(N):
chat_string = input().rstrip()
if chat_string == 'ENTER' :
if time_for_emoji_use :
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

@wkdghdwns199 wkdghdwns199 Apr 10, 2024

Choose a reason for hiding this comment

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

이거 μ±„νŒ… 기둝을 ν•œ 쀄 μ”© λ°›μ•„μ„œ λ§Œμ•½ ENTER 이면 μ΄μ œλΆ€ν„° 밑에 μžˆλŠ” μ±„νŒ… 기둝은 μ „λΆ€ 곰곰이 이λͺ¨ν‹°μ½˜μ„ μ“°λŠ” μ‚¬λžŒλ“€μ΄λ‹€! 라고 μ²΄ν¬ν•˜λŠ” κ²λ‹ˆλ‹€μš” πŸ₯Ή

@9kyo-hwang
Copy link

제발 정석적인 문제λ₯Ό ν’€μ–΄μ£Όμ„Έμš”
ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€ 고득점 kit
μ½”λ”©ν…ŒμŠ€νŠΈ λŒ€λΉ„ λ¬Έμ œμ§‘ with Baekjoon

@alstjr7437
Copy link
Member

image image

이 κ³°κ³°μ»΅ λ§Œλ“  μ‚¬λžŒ λ³€νƒœμΈκ°€μš”?

@alstjr7437
Copy link
Member

set의 clear()ν•¨μˆ˜λ‘œ μ΄λ ‡κ²Œ κ°„λ‹¨ν•œ μ½”λ“œλ‘œ κ°€λŠ₯ν•  것 κ°™λ„€μš”!!

n = int(input())
gom = set()
result = 0

for i in range(n):
    word = input()

    if word != "ENTER":
        if word not in gom:
            result += 1
            gom.add(word)
    else:
        gom.clear()

print(result)

@alstjr7437
Copy link
Member

그리고 개인적으둜 문제λ₯Ό ν’€λ•Œ λ³€μˆ˜κ°€ λ„ˆλ¬΄ κΈΈκ³  μ–΄λ €μš°λ©΄ μ €λŠ” μžλ™μ™„μ„±μ„ 많이 μ“°μ§€λŠ” μ•Šμ•„μ„œ λ³΅μ‚¬ν•˜κ±°λ‚˜ μΉ λ•Œκ°€ λ§Žμ•„μ„œ κ°„λ‹¨ν•˜κ²Œ μ΄ν•΄λŠ” 되게 ν•˜λŠ” 편인데 μ›λž˜ λ³€μˆ˜λͺ…을 κ·Έλ ‡κ²Œ μ§€μœΌμ‹œλŠ”κ±΄κ°€μš”!?

λ‹¨μˆœ κΆκΈˆμ¦μž…λ‹ˆλ‹€..

emoji_use_count += len(emoji_using_users)
else :
time_for_emoji_use = True
emoji_using_users = set()
Copy link
Member

Choose a reason for hiding this comment

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

μƒˆλ‘œ μ„ μ–Έν•˜λŠ”κ²ƒλ„ μ’‹μ§€λ§Œ emoji_using_users.clear() 방법도 μžˆμ„ 것 κ°™μ•„μš”!

Copy link
Member

@fnzksxl fnzksxl left a comment

Choose a reason for hiding this comment

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

저도 κ°„λ‹¨ν•˜κ²Œ set을 μ΄μš©ν•΄μ„œ κ΅¬ν˜„ν•΄λ΄€μŠ΅λ‹ˆλ‹€!

import sys

input = sys.stdin.readline

N = int(input())

counter = "ENTER"
is_gom = set()
cnt = 0

for _ in range(N):
    _new = input().rstrip()
    if _new == counter:
        is_gom.clear()
        continue
    
    if _new not in is_gom:
        cnt += 1
        is_gom.add(_new)

print(cnt)

@wkdghdwns199
Copy link
Collaborator Author

그리고 개인적으둜 문제λ₯Ό ν’€λ•Œ λ³€μˆ˜κ°€ λ„ˆλ¬΄ κΈΈκ³  μ–΄λ €μš°λ©΄ μ €λŠ” μžλ™μ™„μ„±μ„ 많이 μ“°μ§€λŠ” μ•Šμ•„μ„œ λ³΅μ‚¬ν•˜κ±°λ‚˜ μΉ λ•Œκ°€ λ§Žμ•„μ„œ κ°„λ‹¨ν•˜κ²Œ μ΄ν•΄λŠ” 되게 ν•˜λŠ” 편인데 μ›λž˜ λ³€μˆ˜λͺ…을 κ·Έλ ‡κ²Œ μ§€μœΌμ‹œλŠ”κ±΄κ°€μš”!?

λ‹¨μˆœ κΆκΈˆμ¦μž…λ‹ˆλ‹€..

λ„€ 이게 λœ»μ„ λ„£μ–΄μ„œ λ³€μˆ˜λͺ… μ λŠ” κ±Έ μ’‹μ•„ν•΄μ„œ κ·Έλ ‡κ²Œ ν•˜λŠ”λ°, μ½”ν…Œ μΉ λ•ŒλŠ” μ’€ μ•ˆ μ’‹μ„κΉŒμš”?

@wkdghdwns199 wkdghdwns199 merged commit e530845 into main Apr 29, 2024
@wkdghdwns199 wkdghdwns199 deleted the 19-wkdghdwns199 branch April 29, 2024 09:02
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