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

[박장우] 11주차 과제 제출합니다. #17

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Lisiant
Copy link
Collaborator

@Lisiant Lisiant commented May 21, 2022

  • 1953
  • 11578
  • 14497
  • 14575
  • 20313 (실패)
  • 20955
  • 23888
  • 24391

20313번은 계속 틀렸습니다가 뜨는 이유를 모르겠습니다.
^ 반례 주신거 보고 풀어보려 했는데 감이 안잡히네요..

14497번 BFS로 해결했습니다.
14575, 23888 해결했습니다.

nx = x + dx[i]
ny = y + dy[i]

if (nx < 0 or ny < 0 or nx >= n or ny >= m) or vis[nx][ny] != -1:
Copy link

Choose a reason for hiding this comment

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

파이썬은 0<=nx<n 같은 문법이 가능합니다.

Comment on lines +17 to +18
for _ in range(n):
graph.append(list(map(str, input().strip())))
Copy link

Choose a reason for hiding this comment

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

graph = [list(input().strip()) for i in range(n)]
으로 줄일 수 있습니다.

if graph[nx][ny] == '1' or graph[nx][ny] == '#':
vis[nx][ny] = vis[x][y] + 1
graph[nx][ny] = '0'
q.append((nx, ny))
Copy link

Choose a reason for hiding this comment

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

'#'일때 리턴하면 살짝 빠르게 끝낼수 있어요.

@@ -0,0 +1,65 @@
# 20313: 출퇴근
# 실패: 틀렸습니다가 계속 뜨는데 이유를 모르겠습니다.
Copy link

Choose a reason for hiding this comment

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

반례하나 드릴게요.
input
3 2 1 3
1 2 1
2 3 6
2
10 4
10 1

answer
2

건물을 하나 이동하고 나서 마법을 사용할 수 있습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

반례 정말정말 감사합니다!! 근데 반례를 알고도 고치는 방법이 잘 떠오르지가 않네요..

Comment on lines +45 to +48
if vis[cur] == 1:
vis[person] = -1
elif vis[cur] == -1:
vis[person] = 1
Copy link

Choose a reason for hiding this comment

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

vis[person] = -vis[cur]
로 줄일 수는 있습니다.
숏코딩에 관심있으면 해보는걸 추천드려요. ㅎㅎ

Comment on lines +15 to +18
for i in range(1, n+1):
data = list(map(int, input().split()))
for j in range(1, data[0]+1):
graph[i].append(data[j])
Copy link

Choose a reason for hiding this comment

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

이 부분을 줄일 수 있을까요?

exit()


def bfs(start):
Copy link

Choose a reason for hiding this comment

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

함수 정말 잘짰네요. 👍

Comment on lines +64 to +65
team[0].sort()
team[1].sort()
Copy link

Choose a reason for hiding this comment

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

team이 추가되는걸 봤을때 정렬을 안해도 될 것 같아요.

@kth990303 kth990303 requested a review from CJY-kor May 26, 2022 06:20
Copy link
Owner

@kth990303 kth990303 left a comment

Choose a reason for hiding this comment

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

지나가다가 남깁니다~
다른 문제도 화이팅 👍

input = sys.stdin.readline


def gcd(a, b):
Copy link
Owner

Choose a reason for hiding this comment

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

👍👍
이제 유클리드 호제법을 배운지도 꽤 지났네요.

math 내장함수의 gcd를 사용해봐도 좋을 것 같아요


# 30점 받은 코드: int 형변환 문제?
# s_l = (2 * a + (l - 1) * d) * l / 2
# s_r = (2 * a + (r - 1) * d) * r / 2
Copy link
Owner

Choose a reason for hiding this comment

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

나누는 행위는 항상 조심해야 돼요.
실제로 이 문제에선 홀*짝/2 -> 무조건 자연수이기 때문에 식을 조작하면 더 안전하게 쓸 수 있어요. (장우님께서 써주신 식이 훨씬 깔끔하지만, 오차 나기엔 더 좋다는 점 😅 )

간단한 예시를 들자면 s_l * 2와 s_r * 2의 값이 각각 8, 5라 해보죠! 100점 코드와 30점 코드에는 각각 어떤 차이가 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

나누는 행위는 항상 조심해야 돼요. 실제로 이 문제에선 홀*짝/2 -> 무조건 자연수이기 때문에 식을 조작하면 더 안전하게 쓸 수 있어요. (장우님께서 써주신 식이 훨씬 깔끔하지만, 오차 나기엔 더 좋다는 점 😅 )

간단한 예시를 들자면 s_l * 2와 s_r * 2의 값이 각각 8, 5라 해보죠! 100점 코드와 30점 코드에는 각각 어떤 차이가 있을까요?

100점 코드에서는 정수 부분끼리 계산했을 때 s_r = 4, s_l = 2로 계산되어 답이 4 - 2 + a_l 로 출력되겠지만
30점 코드에서는 s_r - s_l = 4 - 2.5 = 1.5 로 계산되어 최종 답이 int(1.5) + a_l = 1 + a_l이 되겠네요.
나누는 행위에서 소수를 고려하지 않았었던 것 같아요. 감사합니다!

Copy link
Owner

@kth990303 kth990303 left a comment

Choose a reason for hiding this comment

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

14575번까지 수고하셨습니다~
approve 하겠습니다.

Comment on lines +44 to +46
if min_num > t or max_num < t:
print(-1)
exit()
Copy link
Owner

Choose a reason for hiding this comment

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

아예 불가능한 경우를 빠르게 처리하셨네요 👍
이 부분은 없어도 돌아가긴 하겠지만, 장우님께서 하신 전처리 방법이 더 좋아보이네요

Comment on lines +18 to +19
if arr[i][0] > s:
return False
Copy link
Owner

Choose a reason for hiding this comment

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

이 부분도 마찬가지 👍
없어도 돌아가긴 하지만 빠른 전처리에 해당됩니다~

Comment on lines +26 to +28
if remain >= t - min_sum:
return True

Copy link
Owner

Choose a reason for hiding this comment

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

따로 이렇게 처리하셨군요.
저는 min_sum과 max_sum을 각각 구한 후에, 해당 값 사이에 T가 포함되면 true를 반환하게 했답니다 😄
두 방법 모두 괜찮네요

# 14575 뒤풀이
import sys
input = sys.stdin.readline
INF = int(1e9)
Copy link
Owner

Choose a reason for hiding this comment

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

이 문제에선 크게 상관없지만, INF는 2e9나 INT_MAX값으로 잡아두면 더 좋습니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants