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

22-LJEDD2 #88

Merged
merged 2 commits into from
Mar 9, 2024
Merged

22-LJEDD2 #88

merged 2 commits into from
Mar 9, 2024

Conversation

LJEDD2
Copy link
Collaborator

@LJEDD2 LJEDD2 commented Mar 5, 2024

πŸŽƒ SQLD μ‹œν—˜ 이슈둜 ... μ‰¬μš΄ μˆ˜ν•™λ¬Έμ œλ₯Ό ν’€μ—ˆμŠ΄λ‹ˆλ‹€ 😭😭😭 μ£„μ†‘ν•¨λ‹ˆλ‹€

πŸ”— 문제 링크

λ°±μ€€ - μˆ˜ν•™ | λ”ν•˜κΈ°

문제 μ„€λͺ…

  • μ •μˆ˜λ‘œ κ΅¬μ„±λœ μˆ˜μ—΄ A_1, A_2 , .. , A_N이 주어진닀. μš°λ¦¬λŠ” 이 μˆ˜μ—΄μ— μ•„λž˜ 연산을 μ›ν•˜λŠ” 만큼 λ°˜λ³΅ν•  수 μžˆλ‹€.
  • μΈμ ‘ν•œ μ„Έ 값을 1μ”© μ¦κ°€μ‹œν‚¨λ‹€.
  • 이 연산을 μ΅œμ†Œν•œμœΌλ‘œ μ‚¬μš©ν•΄ μˆ˜μ—΄μ˜ ν™€μˆ˜ 번째 μœ„μΉ˜μ˜ ν•©κ³Ό 짝수 번째 μœ„μΉ˜μ˜ 합을 κ°™κ²Œ λ§Œλ“ λ‹€.
  • μ΅œμ†Œ λͺ‡ 번의 연산을 ν•΄μ•Ό ν™€μˆ˜ 번째 μœ„μΉ˜μ™€ 짝수 번째 μœ„μΉ˜μ˜ 합이 κ°™μ•„μ§€λŠ”μ§€ κ³„μ‚°ν•œλ‹€.
  • ν™€μˆ˜ 번째 μœ„μΉ˜μ˜ ν•©κ³Ό 짝수 번째 μœ„μΉ˜μ˜ 합을 κ°™κ²Œ λ§Œλ“€ 수 μ—†λ‹€λ©΄ -1을 좜λ ₯ν•œλ‹€.

μ œν•œ 쑰건

  • N은 3λΆ€ν„° 10λ§ŒκΉŒμ§€

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

50λΆ„

✨ μˆ˜λ„ μ½”λ“œ

1. 문제 지문 읽기

  • μΈμ ‘ν•œ 3개의 숫자λ₯Ό 1μ”© μ˜¬λ¦¬λŠ” 과정을 μ΅œμ†Œλ‘œ λ°˜λ³΅ν•˜μ—¬ 합이 κ°™κ²Œ λ§Œλ“€μ–΄μ•Ό ν•œλ‹€.
  • 연산을 1번 ν•  λ•Œλ§ˆλ‹€ 짝수의 ν•© + 2 & ν™€μˆ˜μ˜ ν•© + 1 λ˜λŠ” 짝수의 ν•© +1 & ν™€μˆ˜μ˜ ν•© +2 λ₯Ό λΉ„κ΅ν•˜λ©΄ λœλ‹€.
    β†’ ν™€μˆ˜μ˜ ν•©κ³Ό 짝수의 합을 κ°™κ²Œ λ§Œλ“œλŠ” λ¬Έμ œμ΄λ‹€.

λ”°λΌμ„œ μ§μˆ˜ν•©κ³Ό ν™€μˆ˜ν•©μ˜ 차이만큼 연산을 λ°˜λ³΅ν•΄μ£Όλ©΄ λ˜λŠ”λ°, λ§Œμ•½ μ„Έ 개 숫자만 μžˆλ‹€λ©΄ 짝수의 ν•© + 1 κ³Ό ν™€μˆ˜μ˜ ν•© +2의 경우만 κ°€λŠ₯ν•˜λ‹€.
β†’ N = 3μΌλ•Œμ—λŠ” ν™€μˆ˜μ˜ 합이 더 크닀면 κ°™κ²Œ λ§Œλ“€ 수 μ—†λ‹€.

예λ₯Ό λ“€μžλ©΄,
μ„Έ 개의 μˆ«μžκ°€ 각각 [1, 2, 3]이라고 κ°€μ •ν•  λ•Œ.
이 경우 ν™€μˆ˜μ˜ 합은 1 + 3 = 4이고, 짝수의 합은 2κ°€ λœλ‹€.

주어진 연산을 μ‚¬μš©ν•˜μ—¬ μ„Έ 개의 숫자λ₯Ό κ°™κ²Œ λ§Œλ“€λ €κ³  해도, ν™€μˆ˜μ˜ 합이 κ³„μ†ν•΄μ„œ 더 컀지기 λ•Œλ¬Έμ— 짝수의 합이 λ”°λΌμž‘μ„ 수 μ—†λ‹€.

λ”°λΌμ„œ ν•΄λ‹Ή 쑰건을 μΆ”κ°€ν•΄μ€€ λ’€ μ§μˆ˜ν•©κ³Ό ν™€μˆ˜ν•©μ˜ 차이 (μ ˆλŒ“κ°’)λ₯Ό 좜λ ₯ν•΄μ£Όλ©΄ λœλ‹€.

1-1. πŸŽƒ κΏ€νŒ

  • 파이썬의 리슀트 μŠ¬λΌμ΄μ‹±μ˜ κ°€λŠ₯ λ²”μœ„λŠ” ν•œ 단계도 κ°€λŠ₯ν•˜κ³  징검닀리 μ‹μœΌλ‘œλ„ λ²”μœ„λ₯Ό 지정할 수 μžˆλ‹€.
  • ν™€μˆ˜ 번째, 짝수 번째λ₯Ό κ°„λ‹¨νžˆ μŠ¬λΌμ΄μ‹±μœΌλ‘œ μΆ”μΆœν•˜μ—¬ 합계λ₯Ό ꡬ해볼 수 μžˆλ‹€ !
diff = sum(n_list[1::2]) - sum(n_list[::2])

2. 전체 μ½”λ“œ

n = int(input())
n_list = list(map(int,input().split()))

diff = sum(n_list[1::2]) - sum(n_list[::2])

# N=3이고 ν™€μˆ˜ν•©μ΄ 더 λ§Žλ‹€λ©΄ λΆˆκ°€λŠ₯
if n == 3 and diff < 0 :
    print(-1)
# κ·Έ μ™Έμ—λŠ” μ ˆλŒ“κ°’μ˜ 차이 만큼 +1
else:
    print(abs(diff))

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@Hwangyerin
Copy link
Collaborator

γ„·γ„±γ„·γ„±γ„·γ„± ‼️

Copy link
Collaborator

@Hwangyerin Hwangyerin left a comment

Choose a reason for hiding this comment

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

μ½”λ“œκ°€ μ•„μ£Ό κΉ”-κΌΌν•˜λ„€μš”!
SQLD μ‹œν—˜ νŒŒμ΄νŒ…μž…λ‹ˆλ‹€ :)

Copy link
Member

@janghw0126 janghw0126 left a comment

Choose a reason for hiding this comment

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

ꡰ더더기 μ—†λŠ” κΉ”κΏˆν•œ μ½”λ“œλ„€μš”!
νŒŒμ΄μ¬μ—μ„œ 리슀트 μŠ¬λΌμ΄μ‹± κ°€λŠ₯ λ²”μœ„λ₯Ό 징검닀리 μ‹μœΌλ‘œ 지정할 수 μžˆλ‹€λŠ” 것도 λ‹€μ‹œ ν•œλ²ˆ μ œλŒ€λ‘œ 되짚고 κ°‘λ‹ˆλ‹€πŸ‘€

μ‹œν—˜ λ½œμ΄νŒ…μž…λ‹ˆλ‹·πŸ˜† λ‹€ λΏŒμ…”λ²„λ €μš”!πŸ‘ŠπŸ‘Š

Copy link
Member

@avocado-13 avocado-13 left a comment

Choose a reason for hiding this comment

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

μ΄λ ‡κ²Œ κ°„κ²°ν•˜κ²Œ ν’€ 수 μžˆλŠ” λ¬Έμ œμ˜€λ‹€λ‹ˆ!! 😲🀩
SQLD μ‹œν—˜ 찒어버리십쇼 πŸ€πŸ€

@@ -0,0 +1,10 @@
n = int(input())
n_list = list(map(int,input().split()))
diff = sum(n_list[1::2]) - sum(n_list[::2])
Copy link
Member

Choose a reason for hiding this comment

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

이것도 정말 GOAT ν•œλ°μš”!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

λΉ„κ²¨λ²„λ Έλ„€μš” ν”Όμ•Œνƒ€μž„ ν•˜κ² μŠ΅λ‹ˆλ‹€ μ  -μž₯

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