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

32-alstjr7437 #231

Merged
merged 2 commits into from
Aug 19, 2024
Merged

32-alstjr7437 #231

merged 2 commits into from
Aug 19, 2024

Conversation

alstjr7437
Copy link
Member

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

๊ณผ์ผ ํƒ•ํ›„๋ฃจ

image

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

30๋ถ„

โŒ ํ‹€๋ฆฐ ์ฝ”๋“œ(์‹œ๊ฐ„ ์ดˆ๊ณผ)

์•„๋ž˜์™€ ๊ฐ™์ด

์ด์ค‘ ๋ฐ˜๋ณต๋ฌธ์„ ์‚ฌ์šฉ

  1. ์ฒ˜์Œ ์‹œ์ž‘์ ์„ ์ฐพ๋Š” i ๋ฐ˜๋ณต๋ฌธ
  2. ๋๊นŒ์ง€ ์ˆœํšŒํ•˜๋Š” j ๋ฐ˜๋ณต๋ฌธ(kind ์ข…๋ฅ˜๊ฐ€ 2๊ฐœ ์ด์ƒ์ด ๋˜๋ฉด ํƒˆ์ถœ)

์ด๋ ‡๊ฒŒ ์ด์ค‘ ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ํ•˜๋‹ˆ ์‹œ๊ฐ„ ์ดˆ๊ณผ๊ฐ€ ๋‚˜๋”๊ตฐ์š”..

N = input()
tanghuru = list(map(int, input().split()))
result = 0

for i in range(len(tanghuru)):
    temp = set()
    temp_result = 0
    for j in range(i, len(tanghuru)):
        temp.add(tanghuru[j])
        if len(temp) > 2 :
            break
        temp_result += 1

    result = max(result, temp_result)

print(result)

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

ํ•˜๋‚˜์˜ ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ๋ณ€๊ฒฝ

  1. left,right ํˆฌ ํฌ์ธํ„ฐ ์ถ”๊ฐ€
  2. ๊ณผ์ผ ์ข…๋ฅ˜๋Š” ์ตœ๋Œ€ 10๊ฐœ์ด๋ฏ€๋กœ ๋ฐฐ์—ด ์ƒ์„ฑ(set์—์„œ ๋ณ€๊ฒฝ)
  3. ์ข…๋ฅ˜ ๋ณ€์ˆ˜ ์ถ”๊ฐ€
  4. end๊ฐ€ ๋งˆ์ง€๋ง‰ ์ง€์ ๊นŒ์ง€ ๋ฐ˜๋ณต๋ฌธ ๋Œ๊ธฐ
  5. ๋งŒ์•ฝ ๊ณผ์ผ ์ข…๋ฅ˜์— ๊ณผ์ผ์ด ์—†์œผ๋ฉด ์ถ”๊ฐ€ํ•˜๊ธฐ(kind ์ถ”๊ฐ€)
  6. Kind > 2(๊ณผ์ผ ์ข…๋ฅ˜๊ฐ€ 2 ์ข…๋ฅ˜๋ฅผ ๋„˜์œผ๋ฉด) ์‹œ์ž‘ ์ง€์  ๊ณผ์ผ ๋นผ๋ฒ„๋ฆฌ๊ธฐ
  7. ์‹œ์ž‘์ง€์  ๊ณผ์ผ์ด 0๊ฐœ๊ฐ€ ๋˜๋ฉด ์ข…๋ฅ˜๋„ ๋นผ๋ฒ„๋ฆฌ๊ธฐ
N = int(input())
tanghuru = list(map(int, input().split()))
fruit = [0] * 10
kind = 0
start, end = 0, 0

while True:
    # 4
    if end == N:
        print(end - start)
        break
    # 5
    if fruit[tanghuru[end]] == 0:
        kind += 1
    fruit[tanghuru[end]] += 1
    end += 1

    # 6
    if kind > 2:
        fruit[tanghuru[start]] -= 1
        # 7
        if fruit[tanghuru[start]] == 0:
            kind -= 1
        start += 1

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

์Šฌ๋ผ์ด๋”ฉ ์™ผ๋„์šฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜

@9kyo-hwang
Copy link

๋„ค๋ถ€์บ ์—์„œ ์‚ด์•„๋Œ์•„์™”๊ตฌ๋‚˜ ๋ฏผํƒœ์‹์ด

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

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

ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ ๊ทธ๋ฆผ ๊ฐœ์›ƒ๊ธฐ๋„น

from collections import defaultdict, deque
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())
fruits = list(input().split())

deq = deque()
counter = defaultdict(int)
start = 0
end = 0
max_fruits = 0
while start <= N-1:
    if start == end: 
        end += 1
        deq.append(fruits[start])
        counter[fruits[start]] += 1

    elif len(counter) > 2:
        start += 1
        popped_fruit = deq.popleft()
        counter[popped_fruit] -= 1
        if counter[popped_fruit] == 0: del counter[popped_fruit]

    else:
        if end == N: break
        end += 1
        deq.append(fruits[end-1])
        counter[fruits[end-1]] += 1
    
    if len(counter) <= 2 and max_fruits < len(deq):
        max_fruits = len(deq)
        
print(max_fruits)

๋ฏผ์„์„ ๋ฐฐ ๋„ค๋ถ€์บ  ์ถ”์นด๋“œ๋ฆฌ๊ตฌ

๋งˆ๋ผํƒ•์—๋‹ค๊ฐ€ ํƒ•ํ›„๋ฃจ๊นŒ์ง€ ๋ถ€ํƒ๋“œ๋žด์—ผ~~

Copy link
Collaborator

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

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

ํˆฌํฌ์ธํ„ฐ๋Š” ์ƒ๊ฐ๋„ ๋ชปํ–ˆ๋„ค์š” ,, pr ์ฝ๊ณ  ๋ถ€๋ถ„ํ•ฉ ๋‹ค์‹œ ๋ณด๊ณ  ์™”์Šต๋‹ˆ๋‹ค..!!

์—ฐ์†๋œ ๊ตฌ๊ฐ„ - ํˆฌํฌ์ธํ„ฐ ์—ฐ๊ฒฐ๊ณ ๋ฆฌ ๋‹ค์‹œ ๋จธ๋ฆฌ์— ๋„ฃ๊ณ  ๊ฐ‘๋‹ˆ๋‹ค!!
๋„ค๋ถ€์บ  ์ถ•ํ•˜๋“œ๋ฆฝ๋‹ˆ๋‹ค ~~ ๐Ÿฅณ๐Ÿฅณ

import sys
from collections import defaultdict

def input() : return sys.stdin.readline().rstrip()

N = int(input())
fruits = list(map(int, input().split()))
set_fruits = set(fruits)
left = 0
right = 0
fruit_count = defaultdict(int)
length = 0

while right < N:
    fruit_count[fruits[right]] += 1
    
    while len(fruit_count) > 2:
        fruit_count[fruits[left]] -= 1
        if fruit_count[fruits[left]] == 0:
            del fruit_count[fruits[left]]
        left += 1
    
    length = max(length, right-left+1)
    right += 1

@alstjr7437
Copy link
Member Author

ํˆฌํฌ์ธํ„ฐ๋Š” ์ƒ๊ฐ๋„ ๋ชปํ–ˆ๋„ค์š” ,, pr ์ฝ๊ณ  ๋ถ€๋ถ„ํ•ฉ ๋‹ค์‹œ ๋ณด๊ณ  ์™”์Šต๋‹ˆ๋‹ค..!!

์—ฐ์†๋œ ๊ตฌ๊ฐ„ - ํˆฌํฌ์ธํ„ฐ ์—ฐ๊ฒฐ๊ณ ๋ฆฌ ๋‹ค์‹œ ๋จธ๋ฆฌ์— ๋„ฃ๊ณ  ๊ฐ‘๋‹ˆ๋‹ค!! ๋„ค๋ถ€์บ  ์ถ•ํ•˜๋“œ๋ฆฝ๋‹ˆ๋‹ค ~~ ๐Ÿฅณ๐Ÿฅณ

์–ด๋ฉ‹ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค~~~
ํˆฌํฌ์ธํ„ฐ๋„ ํ•œ๋ฒˆ์”ฉ ์ด๋ ‡๊ฒŒ ๋‚˜์˜ค๋Š” ๊ฒƒ ๊ฐ™์•„์„œ ๋‹ค์‹œ ํ•™์Šตํ•˜๊ธฐ ์ข‹์•˜์–ด์š”!

@alstjr7437 alstjr7437 merged commit efeee08 into main Aug 19, 2024
8 checks passed
@alstjr7437 alstjr7437 deleted the 32-alstjr7437 branch August 19, 2024 15:03
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.

4 participants