반응형

1.문제 소개

 

2.코드



def solution():
    n = int(input().strip())
    for i in range(n):
        a ,b  = map(int,input().split(" "))
        x = a
        number_rules = []
        number_rules += [x%10]
        
        # 1의 자리 숫자의 규칙을 찾기 위한 루프
        for i in range(10):
            x = x * a
            x = x % 10
            number_rules += [x%10]


        # 중복을 제거하고 순서를 보장하기 위한 리스트로 전처리
        distinct_rules = []
        for v in number_rules:
            if v not in distinct_rules:
                distinct_rules.append(v)


        # 결과의 위치를 구하기
        idx = b % len(distinct_rules) -1

        # 0번의 경우 10번 컴퓨터를 의미하므로 정답 출력 보정
        if distinct_rules[idx] == 0:
            answer = 10
        else:
            answer = distinct_rules[idx]
        print(answer)



if __name__ == '__main__':
    solution()

 

3.코멘트

  • 브론즈 문제임에도 단순하게 푼다면 시간 제한에 걸릴 수 있다.
  • a**b 의 범위가 10억 대 범위라서, 반복문으로 구현했다가는 시간제한에 걸린다. 
  • 컴퓨터 번호 이하의 숫자를 pow 연산 범위 안에서 발생하는 규칙을 구한 다음, 정답 인덱스를 구해서 출력했다.
반응형
반응형

 

1.문제 소개

 

2.코드

# Main Idea
# 1) 입력 테스트 케이스의 데이트 문자열 타입을 처리하기 편한 초 단위로 변환
# 2) 점수를 낸 로그를 반복문으로 돌면서, 점수를 낸 직전 스코어의 승자 팀이 있는 경우 1팀과 2팀의 이긴 시간을 누적 저장
# 3) 마지막에는 승팀의 존재 여부를 확인하고, 이긴 시간을 추가 보정

# 입력 데이터 파싱
def set_test_case():
    n = int(input())
    score_log = []
    for i in range(n):
        input_str= input().split(" ")
        team = int(input_str[0])
        score_time_str = input_str[1].split(":")
        minutes = int(score_time_str[0])
        seconds = int(score_time_str[1])

        total_seconds = minutes * 60 + seconds
        score_log += [[team,total_seconds]]

    return score_log
def get_winner(a_score,b_score):
    return 0 if a_score > b_score else 1

def get_format_answer(seconds):
    minutes = seconds //60
    seconds = seconds % 60
    return f"{minutes:02d}:{seconds:02d}"
def solution():
    score_log  = set_test_case()
    current_score = [0,0] # 1, 2팀의 누적 점수
    last_winner = -1
    answer = [0,0] # 1,2 팀의 정답출력을 위한 리스트

    for idx,t in enumerate(score_log):

        # 이전 스코어가 동점이 아닌경우 계산
        if current_score[0] != current_score[1] :
            last_winner = get_winner(current_score[0], current_score[1])
            answer[last_winner] += t[1]-score_log[idx-1][1]

        # 누적 점수 저장
        if t[0] == 1:
            current_score[0] +=1
        else:
            current_score[1] +=1

    if current_score[0] != current_score[1]:
        last_winner = get_winner(current_score[0], current_score[1])
        answer[last_winner] += 60*48 - score_log[-1][1]

    print(get_format_answer(answer[0]))
    print(get_format_answer(answer[1]))

if __name__=='__main__':
    solution()

3.코멘트

  • 승팀을 구하기 위해 점수를 누계하는 순서가 중요했다. 
  • 최근 러닝을 하고 있는데 뛰다가 멈추면 다시 뛰기 힘들다. 알고리즘 스터디도 마찬가지였다. 안 하면 까먹는다. 
 
 
반응형
반응형

최근 커뮤니티에서 Ollama 라는 로컬에 LLM 을 쉽게 번들링 해주는 도구를 알게 되서, 호기심에 설치해봤다. 

 

쉽게 얘기해서 ChatGPT 와 같은 언어 모델을 내 컴퓨터에 로컬로 설치해서 사용하는 것이다.

 

장점이라고 한다면 오프라인으로 오픈소스 LLM(대규모 언어 모델)을 무료로 사용할 수 있고, 데이터 유출이 되지 않기 때문에 보안성이 높을 것이다. 

단점은 뭐 상용 모델보다는 답변의 퀄리티, 속도, 최신화된 정보의 답변을 받을 수 없다는 것들이 있을 수 있겠다.

 

ollama 를 설치하는 것만으로도 LLM 을 사용할 수 있다. 하지만 나는 웹 기반의 UI 가 익숙하므로 오픈 소스 open-webui 를 이용해 설치해봤다.

 

ollama 는 여기 https://github.com/ollama/ollama open-webui 는 여기에 자세한 가이드가 나와있다.

https://github.com/open-webui/open-webui

 

GitHub - open-webui/open-webui: User-friendly WebUI for LLMs (Formerly Ollama WebUI)

User-friendly WebUI for LLMs (Formerly Ollama WebUI) - open-webui/open-webui

github.com

 

관심있어 하는 분들이 있을 것 같아, 퀵스타트 구축을 포스팅해보겠다.

 

 

1. 사전 준비

  • Docker 가 설치된 환경
  • Mac , Linux 기반 환경

2. Set Up 


# set dir for volume mount
mkdir data
mkdir open-webui

# image pull and docker run
docker run -d -p 3000:8080 -v data:/root/.ollama -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:ollama

실행 과정
컨테이너가 실행을 확인

 

http://localhost:3000 접속

 

3. Model Import

모델 추가 및 다운로딩 과정

 

여러 특징에 맞게 학습된 모델들이 있을 것이다. 목적에 맞게 모델을 선택하면 되고, 중요한 것은 컴퓨터 사양이 받쳐줘야 한다. ( 내 경우에는 일부 모델이 실행되지 않았다.. 노트북 사고 싶다.. ) 

 

4. Test

간단하게 버블 정렬을 구현한 파이썬 코드를 보여달라고 해봤다.

 

배치 크기나 토큰 크기도 조절이 가능하다.

 

 

5.마무리

오픈 소스다 보니 사용자들이 학습한 모델을 올릴 수 있고, 공유할 수 가 있다. 컴퓨터 사양이 좋거나 GPU 가 있으면, 이미지 생성도 가능하다. 

 

https://openwebui.com/#open-webui-community

 

 

오늘은 여기까지.. 

 

끝.

 

 

 

 

 
 
반응형

+ Recent posts