상세 컨텐츠

본문 제목

[Softeer] PYTHON | 연습문제 풀이 Lv2(2) 지동 자동 구축 ~

취준/2. 코딩테스트

by ranlan 2024. 6. 30. 15:46

본문

728x90

이전 포스팅과 이어서 Softeer 연습문제 Level2 풀기 .. 😩

 

지도 자동 구축

https://softeer.ai/practice/6280

import sys

n = int(input())

res=2
for i in range(1,n+1):
    res += 2**(i-1)
    
print(res*res)

단계가 거듭될 때마다 한 변의 점이 늘어나는 데에 규칙이 있다.

# 0 > 2
# 1 > 3= 2+1 = 2+2^0
# 2 > 5= 3+2 = 3+2^1
# 3 > 9= 5+4 = 5+2^2

 

 

[21년 재작자 대회 예선] 비밀 메뉴

https://softeer.ai/practice/6269

실패한 내 풀이

import sys

m, n, k = map(int, input().split())
m_list = list(map(int, input().split())) # 비밀 메뉴 조작법
m_len = len(m_list)
n_list = list(map(int, input().split())) # 사용자 버튼 조작

index = [i for i in range(len(n_list)) if m_list[0] == n_list[i]]

def funtion1(m_list, n_list) :
    if len(n_list) < len(m_list) : return 'normal'
    if len(index) == 0: return 'normal'
    
    res = "secret"
    for i in range(len(index)): # 처음 시작 인덱스
        idx = index[i]
        for j in range(m_len): # 전체 같은지 비교
            res="secret"
            # print(i, j, idx, m_list[j], n_list[j+idx])
            if m_list[j] != n_list[j+idx] :
                res = "normal"
                break
            
        if (j==m_len-1) : return res
            
    return res
    
print(funtion1(m_list, n_list))

Subtask 1은 모두 통과하였으나 Subtask 2에서는 테케 3개, 3에서는 10개정도 통과하지 못함

뭔가 내가 놓친 예외상황이 하나 있는거 같은데.... 이것저것 수정했다가 고쳐지기는 커녕 런타임 에러만 나길래 포기함

 

구글링해서 찾은 데크(dequeue) 활용 풀이

import sys
input = sys.stdin.readline
from collections import deque


M, N, K = map(int, input().split())
secret = deque(list(map(int, input().split())))
user = deque(list(map(int, input().split())))
queue = deque()

while user:
    queue.append(user.popleft())
    if len(queue) > M: queue.popleft()
    if queue == secret: break
print('secret' if secret == queue else 'normal')

 


 

여기서부터는 아직 못 푼 문제들.. 최근에 코테한테 씨게 맞아서 여력이 된다면 추가 예정 🧐

 

GBC

https://softeer.ai/practice/6270

 

[21년 재직자 대회 예선]] 전광판

https://softeer.ai/practice/6268

 

[21년 재직자 대회 예선] 회의실 예약

https://softeer.ai/practice/6266

 

728x90

관련글 더보기

댓글 영역