일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Whatever
- BFS
- eks비용
- 커뮤니티
- GithubActions
- kubecost
- GDSC
- 비용최적화
- Python
- 파이썬
- 쿠버네티스
- CI
- GDGCampusKorea
- homelab
- ekskubecost
- GDG
- 프로그래머스
- AWS
- AwsCloudClubs
- 코테
- CUK
- ci/cd
- 설치
- kubecostinstall
- kubecost설치
- karpenter
- 나동빈
- k8s
- eks
- DFS
Archives
- Today
- Total
촬리의늘솔길
[BOJ/1244] 구현 문제 본문
리스트 컴프리헨션..편한데 어렵당..
https://chpark5667.tistory.com/58
진즉볼걸
배열
- 1차원 배열
a = [ 값 for _ in range(N)]
- 2차원 배열
m,n = 5,4
a = [[0]*m for _ in range(n)]
[0]*m 에 대해 for 문을 n 번반복함
for문을 이용한 N번 입력
answer = [int(input()) for _ in range(N)]
N은 사용자가 임의로 지정할 수 있습니다.
N이 5이면, 원소가 다섯개인 리스트를 생성할 수 있습니다.
내가 짠 개떡같은코드
(여전히 index bound,시간복잡도, 20개씩 끊어 출력하는거 그런것들 ^^ 생각못함)
N = int(input())
switch = [int(N) for _ in input().split()]
num = int(input())
student = [list(map(int,input().split())) for _ in range(num)]
for x, y in student:
if x == 1:
for i in range(len(switch)):
if switch[y * i] == 0:
switch[y * i] = 1
else:
switch[y * i] = 0
else:
for i in range(len(switch)):
if switch[y - i] == switch[y + i]:
if switch[y - i] == 0:
switch[y - i] = switch[y + i] = 1
else:
switch[y - i] = switch[y + i] = 0
else:
if switch[y] == 0:
switch[y] = 1
else:
switch[y] = 0
그래서 여러 알고리즘 참고해서
N = int(input())
switch = [0] + list(map(int, input().split()))
for _ in range(int(input())):
sex, idx = map(int, input().split())
i = 1
if sex == 1:
while idx * i <= N:
switch[idx * i] = int(not switch[idx * i])
i += 1
elif sex == 2:
switch[idx] = int(not switch[idx])
while 1 <= idx - i and idx + 1 <= N and switch[idx - i] == switch[idx + 1]:
switch[idx - i] = int(not switch[idx - i])
switch[idx + i] = int(not switch[idx + i])
i += 1
for i in range(1, N + 1):
print(switch[i], end=" ")
if i % 20 == 0:
print()
이러헥 바꿨는데 런타임에러났다..
이번엔 뭐가문제냐..
흠...........
사실 여기서 더 다른점은
change 함수를 만들지않았다는점?
그거 말고는 잘 모르겠다.......해결.......실패.......
참고
728x90
'✍️2023 > Algorithm' 카테고리의 다른 글
[프로그래머스] - 정렬 : K번째 수 (0) | 2023.09.13 |
---|---|
[이코테] DFS/BFS (0) | 2023.07.05 |
[BOJ/20053] 구현 기초문제 (0) | 2023.04.23 |
[BOJ/2891]번 그리디 문제 (0) | 2023.04.23 |
[프로그래머스/그리디] - 체육복 (0) | 2023.04.22 |