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

42-gjsk132 #231

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

42-gjsk132 #231

wants to merge 1 commit into from

Conversation

gjsk132
Copy link
Member

@gjsk132 gjsk132 commented Oct 8, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

๋ฐฑ์ค€1034 : ๋žจํ”„

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

20๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๐ŸŽฏ ๋ฌธ์ œ ์ดํ•ด

๋ฌธ์ œ ์š”์•ฝ
ํƒ์ž์˜ ๊ฐ€๋กœ ์„ธ๋กœ๊ฐ€ ์ฃผ์–ด์ง€๊ณ , ๊ทธ ์œ„์— ์ „๊ตฌ๊ฐ€ ์ผœ์กŒ๋Š”์ง€ ์•„๋‹Œ์ง€๋ฅผ ์ฃผ์–ด์ง„๋‹ค.
์Šค์œ„์น˜๋ฅผ ์ผœ๊ณ  ๋„๋Š”๋ฐ, ์ฃผ์–ด์ง„ ํšŸ์ˆ˜๋งŒํผ ํ•œ ์—ด์˜ ์Šค์œ„์น˜ ์ƒํƒœ๋ฅผ ๋ฐ˜๋Œ€๋กœ ๋ฐ”๊พผ๋‹ค.
์ „๊ตฌ๊ฐ€ ๋ชจ๋‘ ์ผœ์ ธ์žˆ๋Š” ํ–‰์˜ ์ตœ๋Œ€๊ฐ’์„ ๊ตฌํ•˜๋ฉด ๋œ๋‹ค.

ํ•œ ๋ฒˆ ๋ฐ”๊ฟ€ ๋•Œ, ํ•˜๋‚˜์˜ ์—ด์˜ ๋ชจ๋“  ์ „๊ตฌ์˜ ์ƒํƒœ๊ฐ€ ๋ฐ”๋€๋‹ค.
image

๋กœ์ง์„ ์•Œ๊ณ ๋‚˜๋ฉด ๊ฐ„๋‹จํ•˜๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋‹ค.

์—ด์˜ ์ƒํƒœ๊ฐ€ ๋‹ค๋ฅด๋ฉด, ์ „๊ตฌ๋ฅผ ๋ช‡ ๋ฒˆ ํ‚ค๋”๋ผ๋„ ๋‘˜ ๋‹ค ์ผœ์ง€๋Š” ์ƒํƒœ๊ฐ€ ๋  ์ˆ˜ ์—†๋‹ค.
์‰ฝ๊ฒŒ ๋งํ•ด
[1, 0, 0]๊ณผ [0,1,0]์ด ์žˆ์„ ๋•Œ,
ํ•˜๋‚˜๋ฅผ [1,1,1]๋กœ ๋งŒ๋“ค๋ฉด ๋‹ค๋ฅธ ํ•˜๋‚˜๋Š” ๋‹ค ํ‚ฌ ์ˆ˜ ์—†๋‹ค๋Š” ๋ง์ด๋‹ค.
๋”ฐ๋ผ์„œ, ์—ด์˜ ์ƒํƒœ๊ฐ€ ๊ฐ™์€ ๊ฒƒ๋“ค๋ผ๋ฆฌ ๋ฌถ์–ด์„œ ํ™•์ธํ•˜๋ฉด ๋œ๋‹ค.

๊ทธ ํ›„์— ๊ฐฏ์ˆ˜๊ฐ€ ๋งŽ์€ ๊ฒƒ๋ถ€ํ„ฐ ํ™•์ธํ•˜๋ฉด์„œ, ํ•ด๋‹น ์ƒํƒœ๊ฐ€ ํšŸ์ˆ˜๋ฅผ ๋‹ค ์ผ์„ ๋•Œ, ์ „์› ๋‹ค ํ‚ฌ ์ˆ˜ ์žˆ๋Š”์ง€๋งŒ ํ™•์ธํ•˜๋ฉด ๋œ๋‹ค.

๐Ÿ”์ฝ”๋“œ ์„ค๋ช…

table = defaultdict(int)

for _ in range(n):
    row = input().rstrip()
    table[row] += 1

๊ฐ ์—ด ์ •๋ณด๋ฅผ ๋ฐ›๊ณ , ์—ด์„ key๋กœ ํ•˜๋Š” dict์˜ value์— +1 ํ•ด์ฃผ์–ด, ์ƒํƒœ๋ฅผ ์นด์šดํŠธํ•ด์ค€๋‹ค.

table = list(table.items())
table.sort(key=lambda x: -x[1])

dict๋ฅผ list๋กœ ๋ฐ”๊พธ๊ณ , ๋นˆ๋„๊ฐ€ ๋” ๋†’์€ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌํ•ด์ค€๋‹ค.

for row, cnt in table:
    need_switch_on = m - sum(list(map(int,row)))
    
    if turn_on_off_cnt < need_switch_on:
        continue
    
    if (turn_on_off_cnt - need_switch_on)%2==1:
        continue
    
    answer = cnt
    break

๋นˆ๋„๊ฐ€ ๋†’์€ ์ˆœ์œผ๋กœ ์ˆœํšŒํ•œ๋‹ค.
๋งŒ์•ฝ ์ „๊ตฌ ์ƒํƒœ๊ฐ€ ์ „์›์„ ๋‹ค ํ‚ค๊ธฐ ์œ„ํ•œ ํšŸ์ˆ˜๊ฐ€ ๋ถ€์กฑํ•˜๋‹ค๋ฉด, ๋‹ค์Œ ์ „๊ตฌ ์ƒํƒœ๋ฅผ ํ™•์ธํ•œ๋‹ค.
๋˜, ์ „๊ตฌ ๋‹ค ํ‚ค๊ณ  ๋‚จ์€ ํšŸ์ˆ˜๊ฐ€ ํ™€์ˆ˜๋ผ๋ฉด, ์ „์›์€ ๋‹ค ํ‚ฌ ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์—, ๋‹ค์Œ ์ „๊ตฌ ์ƒํƒœ๋ฅผ ํ™•์ธํ•œ๋‹ค.

๋งจ ์ฒ˜์Œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜จ ๊ฐ’์ด ๊ฐ€์žฅ ํฐ ๊ฐ’์ด๊ธฐ ๋•Œ๋ฌธ์— answer์— ๊ฐ’์„ ๋„ฃ๊ณ  for๋ฌธ์€ breakํ•ด์ค€๋‹ค.

๊ทธ ์ดํ›„ ์ •๋‹ต์„ ์ถœ๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

from collections import defaultdict

input = open(0).readline

n, m = map(int,input().split())

answer = 0

table = defaultdict(int)

for _ in range(n):
    row = input().rstrip()
    table[row] += 1
    
turn_on_off_cnt = int(input())

table = list(table.items())
table.sort(key=lambda x: -x[1])

for row, cnt in table:
    need_switch_on = m - sum(list(map(int,row)))
    
    if turn_on_off_cnt < need_switch_on:
        continue
    
    if (turn_on_off_cnt - need_switch_on)%2==1:
        continue
    
    answer = cnt
    break

print(answer)

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

์˜ค๋žœ๋งŒ์— ๋ณต๊ท€... ๐Ÿซ 

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.

1 participant