๋‚ด ์ธ์ƒ์—์„œ ๋ฏฟ์„ ๊ฑด ์˜ค์ง ๋‚˜ ์ž์‹ ๋ฟ!

The only one you can truly trust is yourself.

๊ฒŒ์ž„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ/Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์–‘๊ถ๋Œ€ํšŒ (ํฌ๊ธฐ)

๐ŸŽฎinspirer9 2023. 2. 23. 23:04
728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ ์„ค๋ช…

์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ๊ฐ€ ์—ด๋ ธ์Šต๋‹ˆ๋‹ค.
๋ผ์ด์–ธ์€ ์ €๋ฒˆ ์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ ์šฐ์Šน์ž์ด๊ณ  ์ด๋ฒˆ ๋Œ€ํšŒ์—๋„ ๊ฒฐ์Šน์ „๊นŒ์ง€ ์˜ฌ๋ผ์™”์Šต๋‹ˆ๋‹ค. ๊ฒฐ์Šน์ „ ์ƒ๋Œ€๋Š” ์–ดํ”ผ์น˜์ž…๋‹ˆ๋‹ค.
์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ ์šด์˜์œ„์›ํšŒ๋Š” ํ•œ ์„ ์ˆ˜์˜ ์—ฐ์† ์šฐ์Šน๋ณด๋‹ค๋Š” ๋‹ค์–‘ํ•œ ์„ ์ˆ˜๋“ค์ด ์–‘๊ถ๋Œ€ํšŒ์—์„œ ์šฐ์Šนํ•˜๊ธฐ๋ฅผ ์›ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ, ์–‘๊ถ๋Œ€ํšŒ ์šด์˜์œ„์›ํšŒ๋Š” ๊ฒฐ์Šน์ „ ๊ทœ์น™์„ ์ „ ๋Œ€ํšŒ ์šฐ์Šน์ž์ธ ๋ผ์ด์–ธ์—๊ฒŒ ๋ถˆ๋ฆฌํ•˜๊ฒŒ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

  1. ์–ดํ”ผ์น˜๊ฐ€ ํ™”์‚ด n๋ฐœ์„ ๋‹ค ์œ ํ›„์— ๋ผ์ด์–ธ์ด ํ™”์‚ด n๋ฐœ์„ ์ฉ๋‹ˆ๋‹ค.
  2. ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
    1. ๊ณผ๋…ํŒ์€ ์•„๋ž˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ ์ƒ๊ฒผ์œผ๋ฉฐ ๊ฐ€์žฅ ์ž‘์€ ์›์˜ ๊ณผ๋… ์ ์ˆ˜๋Š” 10์ ์ด๊ณ  ๊ฐ€์žฅ ํฐ ์›์˜ ๋ฐ”๊นฅ์ชฝ์€ ๊ณผ๋… ์ ์ˆ˜๊ฐ€ 0์ ์ž…๋‹ˆ๋‹ค. 
    2. ๋งŒ์•ฝ, k(k๋Š” 1~10์‚ฌ์ด์˜ ์ž์—ฐ์ˆ˜)์ ์„ ์–ดํ”ผ์น˜๊ฐ€ a๋ฐœ์„ ๋งžํ˜”๊ณ  ๋ผ์ด์–ธ์ด b๋ฐœ์„ ๋งžํ˜”์„ ๊ฒฝ์šฐ ๋” ๋งŽ์€ ํ™”์‚ด์„ k์ ์— ๋งžํžŒ ์„ ์ˆ˜๊ฐ€ k ์ ์„ ๊ฐ€์ ธ๊ฐ‘๋‹ˆ๋‹ค. ๋‹จ, a = b์ผ ๊ฒฝ์šฐ๋Š” ์–ดํ”ผ์น˜๊ฐ€ k์ ์„ ๊ฐ€์ ธ๊ฐ‘๋‹ˆ๋‹ค. k์ ์„ ์—ฌ๋Ÿฌ ๋ฐœ ๋งžํ˜€๋„ k์  ๋ณด๋‹ค ๋งŽ์€ ์ ์ˆ˜๋ฅผ ๊ฐ€์ ธ๊ฐ€๋Š” ๊ฒŒ ์•„๋‹ˆ๊ณ  k์ ๋งŒ ๊ฐ€์ ธ๊ฐ€๋Š” ๊ฒƒ์„ ์œ ์˜ํ•˜์„ธ์š”. ๋˜ํ•œ a = b = 0 ์ธ ๊ฒฝ์šฐ, ์ฆ‰, ๋ผ์ด์–ธ๊ณผ ์–ดํ”ผ์น˜ ๋ชจ๋‘ k์ ์— ๋‹จ ํ•˜๋‚˜์˜ ํ™”์‚ด๋„ ๋งžํžˆ์ง€ ๋ชปํ•œ ๊ฒฝ์šฐ๋Š” ์–ด๋Š ๋ˆ„๊ตฌ๋„ k์ ์„ ๊ฐ€์ ธ๊ฐ€์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
      • ์˜ˆ๋ฅผ ๋“ค์–ด, ์–ดํ”ผ์น˜๊ฐ€ 10์ ์„ 2๋ฐœ ๋งžํ˜”๊ณ  ๋ผ์ด์–ธ๋„ 10์ ์„ 2๋ฐœ ๋งžํ˜”์„ ๊ฒฝ์šฐ ์–ดํ”ผ์น˜๊ฐ€ 10์ ์„ ๊ฐ€์ ธ๊ฐ‘๋‹ˆ๋‹ค.
      • ๋‹ค๋ฅธ ์˜ˆ๋กœ, ์–ดํ”ผ์น˜๊ฐ€ 10์ ์„ 0๋ฐœ ๋งžํ˜”๊ณ  ๋ผ์ด์–ธ์ด 10์ ์„ 2๋ฐœ ๋งžํ˜”์„ ๊ฒฝ์šฐ ๋ผ์ด์–ธ์ด 10์ ์„ ๊ฐ€์ ธ๊ฐ‘๋‹ˆ๋‹ค.
    3. ๋ชจ๋“  ๊ณผ๋… ์ ์ˆ˜์— ๋Œ€ํ•˜์—ฌ ๊ฐ ์„ ์ˆ˜์˜ ์ตœ์ข… ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
  3. ์ตœ์ข… ์ ์ˆ˜๊ฐ€ ๋” ๋†’์€ ์„ ์ˆ˜๋ฅผ ์šฐ์Šน์ž๋กœ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค. ๋‹จ, ์ตœ์ข… ์ ์ˆ˜๊ฐ€ ๊ฐ™์„ ๊ฒฝ์šฐ ์–ดํ”ผ์น˜๋ฅผ ์šฐ์Šน์ž๋กœ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

ํ˜„์žฌ ์ƒํ™ฉ์€ ์–ดํ”ผ์น˜๊ฐ€ ํ™”์‚ด n๋ฐœ์„ ๋‹ค ์œ ํ›„์ด๊ณ  ๋ผ์ด์–ธ์ด ํ™”์‚ด์„ ์  ์ฐจ๋ก€์ž…๋‹ˆ๋‹ค.
๋ผ์ด์–ธ์€ ์–ดํ”ผ์น˜๋ฅผ ๊ฐ€์žฅ ํฐ ์ ์ˆ˜ ์ฐจ์ด๋กœ ์ด๊ธฐ๊ธฐ ์œ„ํ•ด์„œ n๋ฐœ์˜ ํ™”์‚ด์„ ์–ด๋–ค ๊ณผ๋… ์ ์ˆ˜์— ๋งžํ˜€์•ผ ํ•˜๋Š”์ง€๋ฅผ ๊ตฌํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

ํ™”์‚ด์˜ ๊ฐœ์ˆ˜๋ฅผ ๋‹ด์€ ์ž์—ฐ์ˆ˜ n, ์–ดํ”ผ์น˜๊ฐ€ ๋งžํžŒ ๊ณผ๋… ์ ์ˆ˜์˜ ๊ฐœ์ˆ˜๋ฅผ 10์ ๋ถ€ํ„ฐ 0์ ๊นŒ์ง€ ์ˆœ์„œ๋Œ€๋กœ ๋‹ด์€ ์ •์ˆ˜ ๋ฐฐ์—ด info๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์ด๋•Œ, ๋ผ์ด์–ธ์ด ๊ฐ€์žฅ ํฐ ์ ์ˆ˜ ์ฐจ์ด๋กœ ์šฐ์Šนํ•˜๊ธฐ ์œ„ํ•ด n๋ฐœ์˜ ํ™”์‚ด์„ ์–ด๋–ค ๊ณผ๋… ์ ์ˆ˜์— ๋งžํ˜€์•ผ ํ•˜๋Š”์ง€๋ฅผ 10์ ๋ถ€ํ„ฐ 0์ ๊นŒ์ง€ ์ˆœ์„œ๋Œ€๋กœ ์ •์ˆ˜ ๋ฐฐ์—ด์— ๋‹ด์•„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด ์ฃผ์„ธ์š”. ๋งŒ์•ฝ, ๋ผ์ด์–ธ์ด ์šฐ์Šนํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ(๋ฌด์กฐ๊ฑด ์ง€๊ฑฐ๋‚˜ ๋น„๊ธฐ๋Š” ๊ฒฝ์šฐ)๋Š” [-1]์„ return ํ•ด์ฃผ์„ธ์š”.

์ œํ•œ ์‚ฌํ•ญ

  • 1 ≤ n ≤ 10
  • info์˜ ๊ธธ์ด = 11
    • 0 ≤ info์˜ ์›์†Œ ≤ n
    • info์˜ ์›์†Œ ์ดํ•ฉ = n
    • info์˜ i๋ฒˆ์งธ ์›์†Œ๋Š” ๊ณผ๋…์˜ 10 - i ์ ์„ ๋งžํžŒ ํ™”์‚ด ๊ฐœ์ˆ˜์ž…๋‹ˆ๋‹ค. ( i๋Š” 0~10 ์‚ฌ์ด์˜ ์ •์ˆ˜์ž…๋‹ˆ๋‹ค.)
  • ๋ผ์ด์–ธ์ด ์šฐ์Šนํ•  ๋ฐฉ๋ฒ•์ด ์žˆ๋Š” ๊ฒฝ์šฐ, return ํ•  ์ •์ˆ˜ ๋ฐฐ์—ด์˜ ๊ธธ์ด๋Š” 11์ž…๋‹ˆ๋‹ค.
    • 0 ≤ returnํ•  ์ •์ˆ˜ ๋ฐฐ์—ด์˜ ์›์†Œ ≤ n
    • returnํ•  ์ •์ˆ˜ ๋ฐฐ์—ด์˜ ์›์†Œ ์ดํ•ฉ = n (๊ผญ n๋ฐœ์„ ๋‹ค ์ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.)
    • returnํ•  ์ •์ˆ˜ ๋ฐฐ์—ด์˜ i๋ฒˆ์งธ ์›์†Œ๋Š” ๊ณผ๋…์˜ 10 - i ์ ์„ ๋งžํžŒ ํ™”์‚ด ๊ฐœ์ˆ˜์ž…๋‹ˆ๋‹ค. ( i๋Š” 0~10 ์‚ฌ์ด์˜ ์ •์ˆ˜์ž…๋‹ˆ๋‹ค.)
    • ๋ผ์ด์–ธ์ด ๊ฐ€์žฅ ํฐ ์ ์ˆ˜ ์ฐจ์ด๋กœ ์šฐ์Šนํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์ผ ๊ฒฝ์šฐ, ๊ฐ€์žฅ ๋‚ฎ์€ ์ ์ˆ˜๋ฅผ ๋” ๋งŽ์ด ๋งžํžŒ ๊ฒฝ์šฐ๋ฅผ return ํ•ด์ฃผ์„ธ์š”.
      • ๊ฐ€์žฅ ๋‚ฎ์€ ์ ์ˆ˜๋ฅผ ๋งžํžŒ ๊ฐœ์ˆ˜๊ฐ€ ๊ฐ™์„ ๊ฒฝ์šฐ ๊ณ„์†ํ•ด์„œ ๊ทธ๋‹ค์Œ์œผ๋กœ ๋‚ฎ์€ ์ ์ˆ˜๋ฅผ ๋” ๋งŽ์ด ๋งžํžŒ ๊ฒฝ์šฐ๋ฅผ return ํ•ด์ฃผ์„ธ์š”.
      • ์˜ˆ๋ฅผ ๋“ค์–ด, [2,3,1,0,0,0,0,1,3,0,0]๊ณผ [2,1,0,2,0,0,0,2,3,0,0]๋ฅผ ๋น„๊ตํ•˜๋ฉด [2,1,0,2,0,0,0,2,3,0,0]๋ฅผ return ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
      • ๋‹ค๋ฅธ ์˜ˆ๋กœ, [0,0,2,3,4,1,0,0,0,0,0]๊ณผ [9,0,0,0,0,0,0,0,1,0,0]๋ฅผ ๋น„๊ตํ•˜๋ฉด[9,0,0,0,0,0,0,0,1,0,0]๋ฅผ return ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ๋ผ์ด์–ธ์ด ์šฐ์Šนํ•  ๋ฐฉ๋ฒ•์ด ์—†๋Š” ๊ฒฝ์šฐ, return ํ•  ์ •์ˆ˜ ๋ฐฐ์—ด์˜ ๊ธธ์ด๋Š” 1์ž…๋‹ˆ๋‹ค.
    • ๋ผ์ด์–ธ์ด ์–ด๋–ป๊ฒŒ ํ™”์‚ด์„ ์˜๋“  ๋ผ์ด์–ธ์˜ ์ ์ˆ˜๊ฐ€ ์–ดํ”ผ์น˜์˜ ์ ์ˆ˜๋ณด๋‹ค ๋‚ฎ๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด [-1]์„ return ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ์ œํ•œ์‹œ๊ฐ„ ์•ˆ๋‚ด
    • ์ •ํ™•์„ฑ ํ…Œ์ŠคํŠธ : 10์ดˆ

์ž…์ถœ๋ ฅ ์˜ˆ

n info result
5 [2,1,1,1,0,0,0,0,0,0,0] [0,2,2,0,1,0,0,0,0,0,0]
1 [1,0,0,0,0,0,0,0,0,0,0] [-1]
9 [0,0,1,2,0,1,1,1,1,1,1] [1,1,2,0,1,2,2,0,0,0,0]
10 [0,0,0,0,0,0,0,0,3,4,3] [1,1,1,1,1,1,1,1,0,0,2]

์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช…

์ž…์ถœ๋ ฅ ์˜ˆ #1

์–ดํ”ผ์น˜์™€ ๋ผ์ด์–ธ์ด ์•„๋ž˜์™€ ๊ฐ™์ด ํ™”์‚ด์„ ๋งžํž ๊ฒฝ์šฐ,

๊ณผ๋… ์ ์ˆ˜ ์–ดํ”ผ์น˜๊ฐ€ ๋งžํžŒ ํ™”์‚ด ๊ฐœ์ˆ˜ ๋ผ์ด์–ธ์ด ๋งžํžŒ ํ™”์‚ด ๊ฐœ์ˆ˜ ๊ฒฐ๊ณผ
10 2 3 ๋ผ์ด์–ธ์ด 10์  ํš๋“
9 1 2 ๋ผ์ด์–ธ์ด 9์  ํš๋“
8 1 0 ์–ดํ”ผ์น˜๊ฐ€ 8์  ํš๋“
7 1 0 ์–ดํ”ผ์น˜๊ฐ€ 7์  ํš๋“
6 0 0  
5 0 0  
4 0 0  
3 0 0  
2 0 0  
1 0 0  
0 0 0  

์–ดํ”ผ์น˜์˜ ์ตœ์ข… ์ ์ˆ˜๋Š” 15์ , ๋ผ์ด์–ธ์˜ ์ตœ์ข… ์ ์ˆ˜๋Š” 19์ ์ž…๋‹ˆ๋‹ค. 4์  ์ฐจ์ด๋กœ ๋ผ์ด์–ธ์ด ์šฐ์Šนํ•ฉ๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ, ๋ผ์ด์–ธ์ด ์•„๋ž˜์™€ ๊ฐ™์ด ํ™”์‚ด์„ ๋งžํž ๊ฒฝ์šฐ ๋” ํฐ ์ ์ˆ˜ ์ฐจ๋กœ ์šฐ์Šนํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ณผ๋… ์ ์ˆ˜ ์–ดํ”ผ์น˜๊ฐ€ ๋งžํžŒ ํ™”์‚ด ๊ฐœ์ˆ˜ ๋ผ์ด์–ธ์ด ๋งžํžŒ ํ™”์‚ด ๊ฐœ์ˆ˜ ๊ฒฐ๊ณผ
10 2 0 ์–ดํ”ผ์น˜๊ฐ€ 10์  ํš๋“
9 1 2 ๋ผ์ด์–ธ์ด 9์  ํš๋“
8 1 2 ๋ผ์ด์–ธ์ด 8์  ํš๋“
7 1 0 ์–ดํ”ผ์น˜๊ฐ€ 7์  ํš๋“
6 0 1 ๋ผ์ด์–ธ์ด 6์  ํš๋“
5 0 0  
4 0 0  
3 0 0  
2 0 0  
1 0 0  
0 0 0  

์–ดํ”ผ์น˜์˜ ์ตœ์ข… ์ ์ˆ˜๋Š” 17์ , ๋ผ์ด์–ธ์˜ ์ตœ์ข… ์ ์ˆ˜๋Š” 23์ ์ž…๋‹ˆ๋‹ค. 6์  ์ฐจ์ด๋กœ ๋ผ์ด์–ธ์ด ์šฐ์Šนํ•ฉ๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ [0,2,2,0,1,0,0,0,0,0,0]์„ return ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ #2

๋ผ์ด์–ธ์ด 10์ ์„ ๋งžํ˜€๋„ ์–ดํ”ผ์น˜๊ฐ€ 10์ ์„ ๊ฐ€์ ธ๊ฐ€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ, ๋ผ์ด์–ธ์€ ์šฐ์Šนํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— [-1]์„ return ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ #3

์–ดํ”ผ์น˜์™€ ๋ผ์ด์–ธ์ด ์•„๋ž˜์™€ ๊ฐ™์ด ํ™”์‚ด์„ ๋งžํž ๊ฒฝ์šฐ,

๊ณผ๋… ์ ์ˆ˜ ์–ดํ”ผ์น˜๊ฐ€ ๋งžํžŒ ํ™”์‚ด ๊ฐœ์ˆ˜ ๋ผ์ด์–ธ์ด ๋งžํžŒ ํ™”์‚ด ๊ฐœ์ˆ˜ ๊ฒฐ๊ณผ
10 0 1 ๋ผ์ด์–ธ์ด 10์  ํš๋“
9 0 1 ๋ผ์ด์–ธ์ด 9์  ํš๋“
8 1 2 ๋ผ์ด์–ธ์ด 8์  ํš๋“
7 2 3 ๋ผ์ด์–ธ์ด 7์  ํš๋“
6 0 0  
5 1 2 ๋ผ์ด์–ธ์ด 5์  ํš๋“
4 1 0 ์–ดํ”ผ์น˜๊ฐ€ 4์  ํš๋“
3 1 0 ์–ดํ”ผ์น˜๊ฐ€ 3์  ํš๋“
2 1 0 ์–ดํ”ผ์น˜๊ฐ€ 2์  ํš๋“
1 1 0 ์–ดํ”ผ์น˜๊ฐ€ 1์  ํš๋“
0 1 0 ์–ดํ”ผ์น˜๊ฐ€ 0์  ํš๋“

์–ดํ”ผ์น˜์˜ ์ตœ์ข… ์ ์ˆ˜๋Š” 10์ , ๋ผ์ด์–ธ์˜ ์ตœ์ข… ์ ์ˆ˜๋Š” 39์ ์ž…๋‹ˆ๋‹ค. 29์  ์ฐจ์ด๋กœ ๋ผ์ด์–ธ์ด ์šฐ์Šนํ•ฉ๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๋ผ์ด์–ธ์ด ์•„๋ž˜์™€ ๊ฐ™์ด ํ™”์‚ด์„ ๋งžํž ๊ฒฝ์šฐ,

๊ณผ๋… ์ ์ˆ˜ ์–ดํ”ผ์น˜๊ฐ€ ๋งžํžŒ ํ™”์‚ด ๊ฐœ์ˆ˜ ๋ผ์ด์–ธ์ด ๋งžํžŒ ํ™”์‚ด ๊ฐœ์ˆ˜ ๊ฒฐ๊ณผ
10 0 1 ๋ผ์ด์–ธ์ด 10์  ํš๋“
9 0 1 ๋ผ์ด์–ธ์ด 9์  ํš๋“
8 1 2 ๋ผ์ด์–ธ์ด 8์  ํš๋“
7 2 0 ์–ดํ”ผ์น˜๊ฐ€ 7์  ํš๋“
6 0 1 ๋ผ์ด์–ธ์ด 6์  ํš๋“
5 1 2 ๋ผ์ด์–ธ์ด 5์  ํš๋“
4 1 2 ๋ผ์ด์–ธ์ด 4์  ํš๋“
3 1 0 ์–ดํ”ผ์น˜๊ฐ€ 3์  ํš๋“
2 1 0 ์–ดํ”ผ์น˜๊ฐ€ 2์  ํš๋“
1 1 0 ์–ดํ”ผ์น˜๊ฐ€ 1์  ํš๋“
0 1 0 ์–ดํ”ผ์น˜๊ฐ€ 0์  ํš๋“

์–ดํ”ผ์น˜์˜ ์ตœ์ข… ์ ์ˆ˜๋Š” 13์ , ๋ผ์ด์–ธ์˜ ์ตœ์ข… ์ ์ˆ˜๋Š” 42์ ์ž…๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ๋„ 29์  ์ฐจ์ด๋กœ ๋ผ์ด์–ธ์ด ์šฐ์Šนํ•ฉ๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ, ์ฒซ ๋ฒˆ์งธ ๊ฒฝ์šฐ์™€ ๋‘ ๋ฒˆ์งธ ๊ฒฝ์šฐ๋ฅผ ๋น„๊ตํ–ˆ์„ ๋•Œ, ๋‘ ๋ฒˆ์งธ ๊ฒฝ์šฐ๊ฐ€ ๋‘ ๊ฒฝ์šฐ ์ค‘ ๊ฐ€์žฅ ๋‚ฎ์€ ์ ์ˆ˜์ธ 4์ ์„ ๋” ๋งŽ์ด ๋งžํ˜”๊ธฐ ๋•Œ๋ฌธ์— [1,1,2,3,0,2,0,0,0,0,0]์ด ์•„๋‹Œ [1,1,2,0,1,2,2,0,0,0,0]์„ return ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ #4

๊ฐ€์žฅ ํฐ ์ ์ˆ˜ ์ฐจ์ด๋กœ ์ด๊ธฐ๋Š” ๊ฒฝ์šฐ ์ค‘์—์„œ ๊ฐ€์žฅ ๋‚ฎ์€ ์ ์ˆ˜๋ฅผ ๊ฐ€์žฅ ๋งŽ์ด ๋งžํžŒ, 10~3์ ์„ ํ•œ ๋ฐœ์”ฉ ๋งžํžˆ๊ณ  ๋‚˜๋จธ์ง€ ๋‘ ๋ฐœ์„ 0์ ์— ๋งžํžˆ๋Š” ๊ฒฝ์šฐ์ธ [1,1,1,1,1,1,1,1,0,0,2]๋ฅผ return ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

ํ’€์ด

  • ๋ฌธ์ œ๋Š” ๋˜๊ฒŒ ์‰ฌ์šด ๊ฑฐ ๊ฐ™์€๋ฐ, ์ฝ์„ ์ˆ˜๋ก ์•„๋ฆฌ์†ก ํ•˜๋‹ค.
    • ์ˆ˜ํ•™ ๋ฌธ์ œ์ธ๊ฐ€?
  • ์–ดํ”ผ์น˜๊ฐ€ ๋งžํžŒ ํ™”์‚ด ๊ฐœ์ˆ˜๊ฐ€ 2๊ฐœ ์ด์ƒ์ด๋ฉด 1๊ฐœ ๋‚ญ๋น„ํ•œ๊ฑฐ. ์™œ๋ƒ? ๋ผ์ด์–ธ์€ ๊ฑฐ๊ธฐ ์•ˆ ์ ๊ฑฐ๊ฑฐ๋“ 
    • ์ฆ‰, ์–ด์น˜ํ”ผ ์ด์ ์€ ๋งžํžŒ ํ™”์‚ด์ด ์žˆ๋Š” ๊ณณ๋งŒ ์–ดํ”ผ์น˜ ์ ์ˆ˜์ž„.
      • ์˜ˆ๋ฅผ ๋“ค์–ด 10์ ์— 10๋ฐœ ๋งž์ท„๋‹ค.
        • ๊ทธ๋Ÿฌ๋ฉด ๋ผ์ด์–ธ์€ 0์ ๋ถ€ํ„ฐ 9์ ๊นŒ์ง€ 1๋ฐœ์”ฉ๋งŒ ์ด๋„ 45์ ์œผ๋กœ ์ตœ๊ณ ์   ๋จน์Œ
    • ๋นˆ์นธ์— ๋จผ์ € ์˜๊ณ , ์ ์€ ๊ฒƒ๋ถ€ํ„ฐ ๋นผ์•—์œผ๋ฉด ๋˜์ง€ ์•Š๋‚˜?
  • ์–ดํ”ผ์น˜๊ฐ€ 10x2, 9x2, 8x2, 7x2, 6x2 ์ด๋ ‡๊ฒŒ 10๋ฐœ ์ˆ๋‹ค ์น˜๋ฉด = 40์ 
    • 5,4,3,2,1์— ํ•œ๋ฐœ์”ฉ ์˜๊ณ  = 15์ 
    • ๋‚˜๋จธ์ง€ 5๋ฐœ๋กœ, 10์ ์— 3๋ฐœ ์˜๋ฉด... 10์ ํ•ด์„œ 25์ . ์–ดํ”ผ์น˜๋Š” 30์ .
      • ์ž‰? ์•„๋‹ˆ๊ตฌ๋งŒ
    • 10์  3๋ฐœ, 9์  3๋ฐœ ์˜๋ฉด 19์ . ์–ดํ”ผ์น˜๋Š” 8+7+6 ์ (21์ )
      • 2๋ฐœ ๋‚จ์€ ๊ฑธ๋กœ, 5+4 = 9์ . ํ•˜๋ฉด 19+9 = 28์ 
      • ์ด๊ฑธ ์–ด๋–ป๊ฒŒ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ๋งŒ๋“ค์–ด...
  • ์–ดํ”ผ์น˜๊ฐ€ 10x2, 9x2, 8x2, 7x2, 6x2 ์ด๋ ‡๊ฒŒ 10๋ฐœ ์ˆ๋‹ค ์น˜๋ฉด = 40์ 
    • ๋ผ์ด์–ธ์€ ๋น„์–ด์žˆ๋Š” ์นธ๋ถ€ํ„ฐ ์ฑ„์šด๋‹ค. 5,4,3,2,1 ๊ทธ๋ฆฌ๊ณ  5๋ฐœ ๋‚จ์œผ๋ฉด ์–ด์ฐจํ”ผ์˜ ์ œ์ผ ๋†’์€ ์ ์ˆ˜๋ถ€ํ„ฐ ๊น๋‹ค.
    • ์–ดํ”ผ์น˜ : 9x2, 8x2, 7x2, 6x2 = 30์ 
    • ๋ผ์ด์–ธ : 10x3, 5,4,3,2,1 = 25์ . ๋‚จ์€ ํ™”์‚ด 2๊ฐœ
      • 1์ ์— ์žˆ๋Š” ํ™”์‚ด 1๊ฐœ ๋ฝ‘์•„์„œ 9์ ์— 3๋ฐœ ์˜๋ฉด...
        • ์–ดํ”ผ์น˜ : 8x2, 7x2, 6x2 = 21์ 
        • ๋ผ์ด์–ธ : 10x3, 9x3, 5,4,3,2 = 34์ . ๋‚จ์€ ํ™”์‚ด 0๊ฐœ. ์ ์ˆ˜์ฐจ 13์ 
          • ๋‚ฎ์€ ์ ์ˆ˜ ํ™”์‚ด 4๊ฐœ ๋” ๋ฝ‘์•„์„œ, 7์ด๋ž‘ 6 ๋ฌด๋ ฅํ™” ์‹œํ‚ค๋ฉด
            • ์–ดํ”ผ์น˜ 0์ .
            • ๋ผ์ด์–ธ 10x3, 9x3 = 19์ . ์ ์ˆ˜์ฐจ 19์ 
  • ์•„๋ฌด๋ฆฌ ํ•ด๋„ ๋จธ๋ฆฌ๊ฐ€ ์•ˆ๋Œ์•„๊ฐ€๋Š”๋ฐ... ์—ฌ๊ธฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์—†๋Š”๊ฑฐ ์•„๋‹๊นŒ?
    • ๊ทธ๋ƒฅ ๋žœ๋ค์œผ๋กœ ํ•ด๋ณด๊ฑฐ๋‚˜ ์ „๋ถ€ ๋‹ค ํ•ด๋ณด๋Š” ๋ฐฉ๋ฒ• ๋ฐ–์— ์—†๋Š”๊ฑด๊ฐ€...;;;
      • ์–ด์ฐจํ”ผ ํ™”์‚ด n์€ 1~10์ด๊ณ . ์ ์ˆ˜ํŒ info์˜ ๊ธธ์ด๋Š” 11.
    • ์•„๋‹Œ๋ฐ ๊ทธ๋Ÿผ ์–ด์ฐจํ”ผ ์ ์ˆ˜๋Š” ์™œ ์คฌ๊ฒ ์–ด?
      • ๋ญ”๊ฐ€ ์žˆ๊ฒŸ์ง€???
      • ํ‘ํ‘ํ‘...
#์•„์šฐ ๋ชฐ?๋ฃจ...

def solution(n, info):
    infolen = 11
    ryan = [0 for _ in range(infolen)]
    
    def compare_sum():
        sum_info, sum_ryan = 0, 0
        for i in range(infolen):
            if info[i] > ryan[i]:
                sum_info += i
            elif info[i] < ryan[i]:
                sum_ryan += i
        return (sum_info, sum_ryan)
    
    while n > 0:
        for i in range(infolen):
            if info[i]+1 > ryan[i] and n>0:
                ryan[i] += 1
                n -= 1
            sum_info, sum_ryan = compare_sum()
            print("์–ดํ”ผ์น˜:", info, "=", sum_info)
            print("๋ผ์ด์–ธ:", ryan, "=", sum_ryan, "(๋‚จ์€ ํ™”์‚ด:",n,")")
        
    return ryan
    
ํ…Œ์ŠคํŠธ 1
์ž…๋ ฅ๊ฐ’ ใ€‰	5, [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[0, 2, 2, 0, 1, 0, 0, 0, 0, 0, 0]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [1,1,1,1,1,0,0,0,0,0,0]์ด ๊ธฐ๋Œ“๊ฐ’ [0,2,2,0,1,0,0,0,0,0,0]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 6
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 4 )
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 5
๋ผ์ด์–ธ: [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 3 )
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 3
๋ผ์ด์–ธ: [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 2 )
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 1 )
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0] = 4 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0] = 4 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0] = 4 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0] = 4 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0] = 4 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0] = 4 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0] = 4 (๋‚จ์€ ํ™”์‚ด: 0 )

ํ…Œ์ŠคํŠธ 2
์ž…๋ ฅ๊ฐ’ ใ€‰	1, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[-1]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [1,0,0,0,0,0,0,0,0,0,0]์ด ๊ธฐ๋Œ“๊ฐ’ [-1]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 0 )

ํ…Œ์ŠคํŠธ 3
์ž…๋ ฅ๊ฐ’ ใ€‰	9, [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[1, 1, 2, 0, 1, 2, 2, 0, 0, 0, 0]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [1,1,1,1,1,1,1,1,1,0,0]์ด ๊ธฐ๋Œ“๊ฐ’ [1,1,2,0,1,2,2,0,0,0,0]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 50
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 8 )
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 50
๋ผ์ด์–ธ: [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 1 (๋‚จ์€ ํ™”์‚ด: 7 )
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 48
๋ผ์ด์–ธ: [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0] = 1 (๋‚จ์€ ํ™”์‚ด: 6 )
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 48
๋ผ์ด์–ธ: [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 1 (๋‚จ์€ ํ™”์‚ด: 5 )
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 48
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0] = 5 (๋‚จ์€ ํ™”์‚ด: 4 )
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 43
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0] = 5 (๋‚จ์€ ํ™”์‚ด: 3 )
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 37
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0] = 5 (๋‚จ์€ ํ™”์‚ด: 2 )
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 30
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0] = 5 (๋‚จ์€ ํ™”์‚ด: 1 )
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 22
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0] = 5 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 22
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0] = 5 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 22
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0] = 5 (๋‚จ์€ ํ™”์‚ด: 0 )

ํ…Œ์ŠคํŠธ 4
์ž…๋ ฅ๊ฐ’ ใ€‰	10, [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 2]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [1,1,1,1,1,1,1,1,1,1,0]์ด ๊ธฐ๋Œ“๊ฐ’ [1,1,1,1,1,1,1,1,0,0,2]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
๋ผ์ด์–ธ: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 9 )
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
๋ผ์ด์–ธ: [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 1 (๋‚จ์€ ํ™”์‚ด: 8 )
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
๋ผ์ด์–ธ: [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0] = 3 (๋‚จ์€ ํ™”์‚ด: 7 )
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
๋ผ์ด์–ธ: [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 6 (๋‚จ์€ ํ™”์‚ด: 6 )
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0] = 10 (๋‚จ์€ ํ™”์‚ด: 5 )
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0] = 15 (๋‚จ์€ ํ™”์‚ด: 4 )
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0] = 21 (๋‚จ์€ ํ™”์‚ด: 3 )
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0] = 28 (๋‚จ์€ ํ™”์‚ด: 2 )
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0] = 28 (๋‚จ์€ ํ™”์‚ด: 1 )
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0] = 28 (๋‚จ์€ ํ™”์‚ด: 0 )
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
๋ผ์ด์–ธ: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0] = 28 (๋‚จ์€ ํ™”์‚ด: 0 )
  • ์ƒ๊ฐํ•ด๋ณด๋‹ˆ๊นŒ... ์–ดํ”ผ์น˜์˜ ์ ์ˆ˜๋ฅผ ๋นผ์•—์œผ๋ ค๋ฉด ํ™”์‚ด ๊ฐฏ์ˆ˜๋งŒํผ ๋‚˜๋ˆ„๊ณ  1์„ ๋”ํ•ด์•ผ ๋˜๋„ค...
  • ๊ทธ๋ฆฌ๊ณ  ์–ดํ”ผ์น˜๊ฐ€ ํ™”์‚ด ์•ˆ ์œ ๊ณณ์€ ์ ์ˆ˜ ๊ทธ๋Œ€๋กœ๊ณ ...?
def solution(n, info):
    infolen = 11
    ryan = [0 for _ in range(infolen)]
    effc = []
    # info๋Š” ๊ณผ๋…์— ๊ฝ‚ํžŒ ํ™”์‚ด ์ˆ˜
    # ryan์€ ๊ณผ๋…์— ๊ฝ‚์„ ํ™”์‚ด์„ ๋งž์ถ”๋Š”...
    # effc์€ ํšจ์œจ ๊ณ„์‚ฐ
    
    def compare_sum(): # ์ ์ˆ˜ ๋น„๊ต์šฉ
        sum_info, sum_ryan = 0, 0
        for i in range(infolen):
            if info[i] > ryan[i]:
                sum_info += i
            elif info[i] < ryan[i]:
                sum_ryan += i
        return (sum_info, sum_ryan)
    
    def calc_effecient(): # ํšจ์œจ ๊ณ„์‚ฐ
        eff2 = []
        point = 10
        for i in range(infolen):
            eff2.append(point / (info[i]+1))
            if info[i] != 0:
                eff2[i] *= 2
            point -= 1
        return eff2
    
    effc = calc_effecient()
    sum_info, sum_ryan = compare_sum()
    print("์–ดํ”ผ์น˜:", info, "=", sum_info)
    print("ํšจ__์œจ:", effc,)
    print("๋ผ์ด์–ธ:", ryan, "=", sum_ryan, "(๋‚จ์€ ํ™”์‚ด:",n,")")

    while n > 0:
        for i in range(infolen):
            if info[i]+1 > ryan[i] and n>0:
                ryan[i] += 1
                n -= 1
            sum_info, sum_ryan = compare_sum()
        
    return ryan
    
ํ…Œ์ŠคํŠธ 1
์ž…๋ ฅ๊ฐ’ ใ€‰	5, [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[0, 2, 2, 0, 1, 0, 0, 0, 0, 0, 0]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [1,1,1,1,1,0,0,0,0,0,0]์ด ๊ธฐ๋Œ“๊ฐ’ [0,2,2,0,1,0,0,0,0,0,0]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	
์–ดํ”ผ์น˜: [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0] = 6
ํšจ__์œจ: [6.666666666666667, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0]
๋ผ์ด์–ธ: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 5 )

ํ…Œ์ŠคํŠธ 2
์ž…๋ ฅ๊ฐ’ ใ€‰	1, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[-1]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [1,0,0,0,0,0,0,0,0,0,0]์ด ๊ธฐ๋Œ“๊ฐ’ [-1]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	
์–ดํ”ผ์น˜: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0
ํšจ__์œจ: [10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0]
๋ผ์ด์–ธ: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 1 )

ํ…Œ์ŠคํŠธ 3
์ž…๋ ฅ๊ฐ’ ใ€‰	9, [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[1, 1, 2, 0, 1, 2, 2, 0, 0, 0, 0]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [1,1,1,1,1,1,1,1,1,0,0]์ด ๊ธฐ๋Œ“๊ฐ’ [1,1,2,0,1,2,2,0,0,0,0]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	
์–ดํ”ผ์น˜: [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1] = 50
ํšจ__์œจ: [10.0, 9.0, 8.0, 4.666666666666667, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0]
๋ผ์ด์–ธ: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 9 )

ํ…Œ์ŠคํŠธ 4
์ž…๋ ฅ๊ฐ’ ใ€‰	10, [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 2]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [1,1,1,1,1,1,1,1,1,1,0]์ด ๊ธฐ๋Œ“๊ฐ’ [1,1,1,1,1,1,1,1,0,0,2]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	
์–ดํ”ผ์น˜: [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3] = 27
ํšจ__์œจ: [10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 1.0, 0.4, 0.0]
๋ผ์ด์–ธ: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] = 0 (๋‚จ์€ ํ™”์‚ด: 10 )
  • ํšจ์œจ์ด ๋†’์€ ์ˆœ์œผ๋กœ ์ ์ˆ˜๋ฅผ ๋นผ์•—์œผ๋ฉด ๋˜๊ณ ,
    • ์ ์ˆ˜๊ฐ€ ๋” ๋†’์•„์ง€์ง€ ์•Š์œผ๋ฉด ํ™”์‚ด์„ 0์  ์žˆ๋Š” ๊ณณ ๊นŒ์ง€ ๋ณด๋‚ด์„œ ๋‚ฎ์€ ์ ์ˆ˜๋ฅผ ๋งŽ์ด ๋งžํžˆ๋„๋ก ํ•˜๋ฉด ๋œ๋‹ค. ๋˜๋‚˜?
      • ํšจ์œจ๋กœ๋„ ์–ด๋ ค์›€.
  • ๊ทธ๋ž˜์„œ... re:zero๋กœ๋ถ€ํ„ฐ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜๋Š” ใ…‹ใ…‹ใ…‹
    • ์š”๋ฒˆ ์•„์ด๋””์–ด๋Š” 11์นธ์— ํ™”์‚ด n๊ฐœ ๋ฐ•์•„๋„ฃ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ์ „๋ถ€ ๋งŒ๋“ค์–ด์„œ ์ ์ˆ˜ ๋น„๊ตํ•ด๋ฒ„๋ฆฌ๋Š” ๊ฑฐ...
      • ๋ญ... ์–ผ๋งˆ ์•ˆ๊ฑธ๋ฆฌ๊ฒ ์ง€?
def solution(n, info):
    #n : ํ™”์‚ด ์ˆ˜. 1~10 ์‚ฌ์ด. ๋ฐœ์ˆ˜๊ฐ€ 10๊ฐœ ๋ฐ–์— ์•ˆ๋จ
    #info :๊ณผ๋…์˜_์ ์ˆ˜์นธ 11 ๊ณ ์ •.
    ๋ผ์ด์–ธ์˜_๊ณผ๋… = [0 for _ in range(len(info))]
    return ๋ผ์ด์–ธ์˜_๊ณผ๋…
  • k๊ฐœ์˜ ์ƒ์ž์— n๊ฐœ์˜ ๊ตฌ์Šฌ์„ ๋ช‡๊ฐœ์”ฉ ๋„ฃ๋Š”.. ๊ฒฝ์šฐ์˜ ์ˆ˜๋Š” ์–ด๋–ป๊ฒŒ ๊ตฌํ•˜๋”๋ผ?
    • ์ƒ์ž ๊ตฌ๋ถ„x, ๋นˆ ์ƒ์ž ํ—ˆ์šฉ
      • ๊ณผ๋…์ ์ˆ˜์นธ(k) = 11, ๋นˆ ์ƒ์ž ํ—ˆ์šฉ
      • ํ™”์‚ด(n) = 5 (1~10)
        • ๊ฒฝ์šฐ์˜ ์ˆ˜ P(n,i), i๋Š” 1~k = P(n,1) + P(n,2) + P(n,3) + ... P(n,k)
          • ๊ฐ€ ์•„๋‹ˆ๋‹ค.
    • ์ƒ์ž ๊ตฌ๋ถ„o, ๋นˆ ์ƒ์ž ํ—ˆ์šฉ
      • kHn (์ค‘๋ณต ์กฐํ•ฉ) 11H5
 

17. ์„œ๋กœ (๊ฐ™์€/๋‹ค๋ฅธ) ์ƒ์ž์— ์„œ๋กœ (๊ฐ™์€/๋‹ค๋ฅธ) ๊ตฌ์Šฌ์„ ๋„ฃ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜

์•„๋ž˜ ํ‘œ๋Š” ๊ตฌ์Šฌ์˜ ๊ฐฏ์ˆ˜๋ฅผ n๊ฐœ๋ผ ํ•˜๊ณ , ์ƒ์ž์˜ ๊ฐฏ์ˆ˜๋ฅผ k๊ฐœ๋ผ ํ•˜์˜€์„ ๋•Œ์˜ ์ƒ์ž์— ๊ตฌ์Šฌ์„ ๋‹ด์„ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ...

blog.naver.com

  • ๊ทธ๋ฆฌ๊ณ  ์ค‘๋ณต์กฐํ•ฉ์€ itertools
    • ๋งค๋ฒˆ ๊ฒ€์ƒ‰ํ•˜์ง€ ๋ง๊ณ , ๋‚˜๋„ ๋ธ”๋กœ๊ทธ์— ์ •๋ฆฌํ•ด๋†”์•ผ์ง€
 

[Python] ์ˆœ์—ด, ์กฐํ•ฉ, ์ค‘๋ณต์ˆœ์—ด, ์ค‘๋ณต์กฐํ•ฉ(itertools๋ฅผ ํ™œ์šฉํ•œ ๊ตฌํ˜„)

์ˆœ์—ด, ์กฐํ•ฉ, ์ค‘๋ณต์ˆœ์—ด, ์ค‘๋ณต์กฐํ•ฉ์˜ ์ •์˜์™€ ์ฐจ์ด๋ฅผ ๋น„๊ตํ•˜๊ณ  itertool ํŒจํ‚ค์ง€๋ฅผ ํ™œ์šฉํ•ด python์œผ๋กœ ๊ตฌํ˜„ํ•ด๋ณธ๋‹ค.

velog.io

  • ์ค‘๋ณต์กฐํ•ฉ ๊ธฐ๋ณธ ๊ตฌ์กฐ
    • ๊ทผ๋ฐ ์‹œ๊ฐ„์ดˆ๊ณผ ๋‚  ๊ฒƒ ๊ฐ™์€ ๋Š๋‚Œ์ด๋‹ค.
from itertools import combinations_with_replacement

def solution(n, info):
    #n : ํ™”์‚ด ์ˆ˜. 1~10 ์‚ฌ์ด. ๋ฐœ์ˆ˜๊ฐ€ 10๊ฐœ ๋ฐ–์— ์•ˆ๋จ
    #info :๊ณผ๋…์˜_์ ์ˆ˜์นธ 11 ๊ณ ์ •.
    ๋ผ์ด์–ธ์˜_๊ณผ๋… = [i for i in range(len(info))]

    comb = combinations_with_replacement(๋ผ์ด์–ธ์˜_๊ณผ๋…, n)

    i = 0
    for c in comb:
        print(c)
        i += 1
        if i > 5:
            break

    return ๋ผ์ด์–ธ์˜_๊ณผ๋…
    
์‹คํ–‰ ๊ฒฐ๊ณผ
ํ…Œ์ŠคํŠธ 1
์ž…๋ ฅ๊ฐ’ ใ€‰	5, [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[0, 2, 2, 0, 1, 0, 0, 0, 0, 0, 0]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [0,1,2,3,4,5,6,7,8,9,10]์ด ๊ธฐ๋Œ“๊ฐ’ [0,2,2,0,1,0,0,0,0,0,0]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	(0, 0, 0, 0, 0)
(0, 0, 0, 0, 1)
(0, 0, 0, 0, 2)
(0, 0, 0, 0, 3)
(0, 0, 0, 0, 4)
(0, 0, 0, 0, 5)

ํ…Œ์ŠคํŠธ 2
์ž…๋ ฅ๊ฐ’ ใ€‰	1, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[-1]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [0,1,2,3,4,5,6,7,8,9,10]์ด ๊ธฐ๋Œ“๊ฐ’ [-1]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	(0,)
(1,)
(2,)
(3,)
(4,)
(5,)

ํ…Œ์ŠคํŠธ 3
์ž…๋ ฅ๊ฐ’ ใ€‰	9, [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[1, 1, 2, 0, 1, 2, 2, 0, 0, 0, 0]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [0,1,2,3,4,5,6,7,8,9,10]์ด ๊ธฐ๋Œ“๊ฐ’ [1,1,2,0,1,2,2,0,0,0,0]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	(0, 0, 0, 0, 0, 0, 0, 0, 0)
(0, 0, 0, 0, 0, 0, 0, 0, 1)
(0, 0, 0, 0, 0, 0, 0, 0, 2)
(0, 0, 0, 0, 0, 0, 0, 0, 3)
(0, 0, 0, 0, 0, 0, 0, 0, 4)
(0, 0, 0, 0, 0, 0, 0, 0, 5)

ํ…Œ์ŠคํŠธ 4
์ž…๋ ฅ๊ฐ’ ใ€‰	10, [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 2]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [0,1,2,3,4,5,6,7,8,9,10]์ด ๊ธฐ๋Œ“๊ฐ’ [1,1,1,1,1,1,1,1,0,0,2]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
(0, 0, 0, 0, 0, 0, 0, 0, 0, 2)
(0, 0, 0, 0, 0, 0, 0, 0, 0, 3)
(0, 0, 0, 0, 0, 0, 0, 0, 0, 4)
(0, 0, 0, 0, 0, 0, 0, 0, 0, 5)
  • ํ˜น์‹œ ๋ชฐ๋ผ์„œ ์ฑ„์  ๋Œ๋ ค๋ดค๋Š”๋ฐ... ๊ดœ์ฐฎ์€ ๊ฑธ๊นŒ?
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	์‹คํŒจ (0.00ms, 10.3MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	์‹คํŒจ (0.00ms, 10.3MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	์‹คํŒจ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	์‹คํŒจ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	์‹คํŒจ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	์‹คํŒจ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	์‹คํŒจ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	์‹คํŒจ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	์‹คํŒจ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	์‹คํŒจ (0.00ms, 10.3MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	์‹คํŒจ (0.00ms, 10.3MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	์‹คํŒจ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	์‹คํŒจ (0.00ms, 10.5MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	์‹คํŒจ (0.00ms, 10.3MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	์‹คํŒจ (0.00ms, 10.5MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	์‹คํŒจ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	์‹คํŒจ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	์‹คํŒจ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	์‹คํŒจ (0.00ms, 10.3MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	์‹คํŒจ (0.00ms, 10.3MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	์‹คํŒจ (0.00ms, 10.3MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	์‹คํŒจ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	์‹คํŒจ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	์‹คํŒจ (0.00ms, 10.3MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰	์‹คํŒจ (0.00ms, 10.3MB)
  • ์ฝ”๋”ฉ ํ•˜๋‹ค๋ณด๋‹ˆ๊นŒ ์ค‘๋ณต ์กฐํ•ฉ ์ž˜ ๋ชป ๋งŒ๋“ค์—ˆ๋„ค ใ…‹ใ…‹ใ…‹
    • ์ด๋ ‡๊ฒŒ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค. 
      • ๋ผ์ด์–ธ์˜_๊ณผ๋… = [i for i in range(n+1)]
      • comb = combinations_with_replacement(๋ผ์ด์–ธ์˜_๊ณผ๋…, 11)
    • ์›๋ž˜ answer=[]๋ฅผ ์ด๋ฆ„๋ฐ”๊พผ๊ฑฐ๋ผ์„œ ์ ์ˆ˜ ์กฐํ•ฉ์ธ๋ฐ ๊ณผ๋… ์นธ์œผ๋กœ ์ƒ๊ฐํ–ˆ๋‹ค.
    • ๊ทผ๋ฐ ๊ทธ๊ฑฐ ์•„๋‹ˆ๋”๋ผ๋„ ๋ฉ์ฒญ์ด์ธ๊ฒŒ...
      • 0~5๊นŒ์ง€ ์ˆซ์ž๋ฅผ ๋„ฃ๋Š”๊ฒŒ ์ค‘์š”ํ•œ๊ฒŒ ์•„๋‹ˆ๋ผ....
        • ์•„ ํ•ฉ์ด 5๋„˜์–ด๊ฐ€๋ฉด ์ œ๊ฑฐํ•ด๋ฒ„๋ฆฌ๋ฉด ๋˜๋Š”๊ตฌ๋‚˜?
from itertools import combinations_with_replacement

def solution(n, info):
    #n : ํ™”์‚ด ์ˆ˜. 1~10 ์‚ฌ์ด. ๋ฐœ์ˆ˜๊ฐ€ 10๊ฐœ ๋ฐ–์— ์•ˆ๋จ
    #info :๊ณผ๋…์˜_์ ์ˆ˜์นธ 11 ๊ณ ์ •.
    ๋ผ์ด์–ธ์˜_๊ณผ๋… = [i for i in range(n+1)]
    comb = combinations_with_replacement(๋ผ์ด์–ธ์˜_๊ณผ๋…, 11)
    
    #์ ์ˆ˜๋น„๊ต. ์ค‘๋ณต ์กฐํ•ฉ์—์„œ ํ•˜๋‚˜์”ฉ ๊บผ๋‚ด์„œ ์ ์ˆ˜๋ฅผ ๋จผ์ € ๊ณ„์‚ฐํ•œ๋‹ค.
    ๋ผ์ด์–ธ_์ตœ๋Œ€์ ์ˆ˜ = 0
    ๋ผ์ด์–ธ_๊ณผ๋…๋ฐฐ์—ด = [0 for i in range(11)]
    
    for c in comb:
        ๋ผ์ด์–ธ์ ์ˆ˜ = 0
        ์–ดํ”ผ์น˜์ ์ˆ˜ = 0
        for i in range(len(info)):
            if info[i] > c[i]:
                ์–ดํ”ผ์น˜์ ์ˆ˜ += 10-i
            elif info[i] < c[i]:
                ๋ผ์ด์–ธ์ ์ˆ˜ += 10-i
        if ๋ผ์ด์–ธ_์ตœ๋Œ€์ ์ˆ˜ < ๋ผ์ด์–ธ์ ์ˆ˜ - ์–ดํ”ผ์น˜์ ์ˆ˜:
            ๋ผ์ด์–ธ_์ตœ๋Œ€์ ์ˆ˜ = ๋ผ์ด์–ธ์ ์ˆ˜ - ์–ดํ”ผ์น˜์ ์ˆ˜
            ๋ผ์ด์–ธ_๊ณผ๋…๋ฐฐ์—ด.clear()
            ๋ผ์ด์–ธ_๊ณผ๋…๋ฐฐ์—ด = list(c)
            
    return ๋ผ์ด์–ธ_๊ณผ๋…๋ฐฐ์—ด
    
ํ…Œ์ŠคํŠธ 1
์ž…๋ ฅ๊ฐ’ ใ€‰	5, [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[0, 2, 2, 0, 1, 0, 0, 0, 0, 0, 0]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [3,3,3,3,3,3,3,3,3,3,3]์ด ๊ธฐ๋Œ“๊ฐ’ [0,2,2,0,1,0,0,0,0,0,0]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
ํ…Œ์ŠคํŠธ 2
์ž…๋ ฅ๊ฐ’ ใ€‰	1, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[-1]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [1,1,1,1,1,1,1,1,1,1,1]์ด ๊ธฐ๋Œ“๊ฐ’ [-1]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
ํ…Œ์ŠคํŠธ 3
์ž…๋ ฅ๊ฐ’ ใ€‰	9, [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[1, 1, 2, 0, 1, 2, 2, 0, 0, 0, 0]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [1,1,2,3,3,3,3,3,3,3,3]์ด ๊ธฐ๋Œ“๊ฐ’ [1,1,2,0,1,2,2,0,0,0,0]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
ํ…Œ์ŠคํŠธ 4
์ž…๋ ฅ๊ฐ’ ใ€‰	10, [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3]
๊ธฐ๋Œ“๊ฐ’ ใ€‰	[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 2]
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	์‹คํ–‰ํ•œ ๊ฒฐ๊ด๊ฐ’ [1,1,1,1,1,1,1,1,4,5,5]์ด ๊ธฐ๋Œ“๊ฐ’ [1,1,1,1,1,1,1,1,0,0,2]๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
  • ์ค‘๋ณต ์กฐํ•ฉ์„ ์ง์ ‘ ๋งŒ๋“ค๊นŒ ํ•˜๋‹ค๊ฐ€... ํŒŒ์ด์ฌ ๋ชจ๋“ˆ ๋ณด๋‹ค ๋น ๋ฅผ๋ฆฌ ์—†๋‹ค๋ฉฐ ํฌ๊ธฐ
    • ๊ทธ๋ƒฅ for๋ฌธ ๋Œ๋ ค ใ…‹ใ…‹ใ…‹
    • ์ด๋Ÿฌ๋ฉด ๋˜๊ฒ ์ง€?

  • ์ž˜ ๋˜๋„ค

  • ๋’ค์— ์•ˆ๋จ.
    • ๊ฒ€์ƒ‰ํ•ด๋ณด๋‹ˆ๊นŒ...
      • ๋ฆฌ์ŠคํŠธ ๊ธธ์ด๊ฐ€ ๊ธธ์–ด์„œ ๋ฉˆ์ถฐ๋ฒ„๋ฆฌ๋Š” ๊ฒƒ ๊ฐ™๋‹ค.
        • 999,999,999 ํ•˜๋ฉด ๋ฉ”๋ชจ๋ฆฌ์—๋Ÿฌ
        • ์ฒœ๋งŒ๋ถ€ํ„ฐ ๋Š๋ ค์ง€๊ณ 
        • 2์–ต๊นŒ์ง€ ๊ฐ€๋Šฅ
        • 3์–ต๋ถ€ํ„ฐ ๋ฉ”๋ชจ๋ฆฌ์—๋Ÿฌ
        • ๋ฐฑ๋งŒ๊นŒ์ง€ ์Šค๋ฌด์Šคํ•˜๊ฒŒ ๋น ๋ฅด๊ฒŒ ์ƒ์„ฑ ๊ฐ€๋Šฅ
        • 100,000,000 (์ผ์–ต)์ด 381 MB ํฌ๊ธฐ
    • ์—ญ์‹œ ์ง์ ‘ ๋งŒ๋“ค์–ด์•ผ...?
      • ์•„๋‹ˆ์•ผ ์ง์ ‘ ๋งŒ๋“ค ํ•„์š”์—†๊ณ , 
        • combinations_with_replacement ํ•œ๋ฒˆ ํ•˜๊ณ , permutation ํ•œ๋ฒˆ ํ•˜๊ณ  ๊ฒฐ๊ณผ ๊ฐ™์€ ๊ฑด ๊ฑธ๋Ÿฌ๋‚ด๋ฉด ๋˜๋Š”๋ฐ, ์†๋„ ๋ฌด์ง„์žฅ ์•ˆ๋‚˜์˜จ๋‹ค. ํฌ๊ธฐ... ๋‹ค์‹œ ์ฒ˜์Œ ๋ฐฉ์‹์œผ๋กœ ใ…‹ใ…‹ใ…‹
import itertools

def solution(n, info):
    #n : ํ™”์‚ด ์ˆ˜. 1~10 ์‚ฌ์ด. ๋ฐœ์ˆ˜๊ฐ€ 10๊ฐœ ๋ฐ–์— ์•ˆ๋จ
    #info :๊ณผ๋…์˜_์ ์ˆ˜์นธ 11 ๊ณ ์ •.
    ๋ผ์ด์–ธ์˜_๊ณผ๋… = [i for i in range(n+1)]
    comb = itertools.combinations_with_replacement(๋ผ์ด์–ธ์˜_๊ณผ๋…, 11)
    comb = [list(c) for c in comb if sum(c) == n]
    
    print(comb)
    perm = []
    for c in comb:
        all_permutations = itertools.permutations(c)
        for ap in all_permutations:
            if list(ap) not in perm:
                perm.append(list(ap))
    
    i = 2
    for p in perm:
        print(p)
        i -= 1
        if i<0 :
            break
    #    for pp in p:
    #       print(pp)
    ##   i += 1
    #  if i > 1:
    #       break
    #์ ์ˆ˜๋น„๊ต. ์ค‘๋ณต ์กฐํ•ฉ์—์„œ ํ•˜๋‚˜์”ฉ ๊บผ๋‚ด์„œ ์ ์ˆ˜๋ฅผ ๋จผ์ € ๊ณ„์‚ฐํ•œ๋‹ค.
    ๋ผ์ด์–ธ_์ตœ๋Œ€์ ์ˆ˜ = 0
    ๋ผ์ด์–ธ_๊ณผ๋…๋ฐฐ์—ด = [0 for i in range(11)]
    
    for c in comb:
        ๋ผ์ด์–ธ์ ์ˆ˜ = 0
        ์–ดํ”ผ์น˜์ ์ˆ˜ = 0
        if c == (0,2,2,0,1,0,0,0,0,0,0):
            print("์ฐพ์•˜๋‹ค ์š”๋†ˆ")
        for i in range(len(info)):
            if info[i] > c[i]:
                ์–ดํ”ผ์น˜์ ์ˆ˜ += 10-i
            elif info[i] < c[i]:
                ๋ผ์ด์–ธ์ ์ˆ˜ += 10-i
        if ๋ผ์ด์–ธ_์ตœ๋Œ€์ ์ˆ˜ < ๋ผ์ด์–ธ์ ์ˆ˜ - ์–ดํ”ผ์น˜์ ์ˆ˜:
            ๋ผ์ด์–ธ_์ตœ๋Œ€์ ์ˆ˜ = ๋ผ์ด์–ธ์ ์ˆ˜ - ์–ดํ”ผ์น˜์ ์ˆ˜
            #print(๋ผ์ด์–ธ_๊ณผ๋…๋ฐฐ์—ด,c)
            ๋ผ์ด์–ธ_๊ณผ๋…๋ฐฐ์—ด = c
    if ๋ผ์ด์–ธ_์ตœ๋Œ€์ ์ˆ˜ <= 0:
        return [-1]
    
    return ๋ผ์ด์–ธ_๊ณผ๋…๋ฐฐ์—ด

print(solution(5, [1,1,1,1,1,0,0,0,0,0,0]))
  • ๋‹ค์‹œ... ใ…‹ใ…‹ใ…‹
    • ํ…Œ์ผ€๋Š” ์„ฑ๊ณต
import itertools

def solution(n, info):
    arrow_n_score = []
    ryan_arrow = [0 for i in range(11)]
    for i in range(len(info)):
        ์ ์ˆ˜์œ„์น˜ = i
        ํ•„์š”ํ™”์‚ด = info[i]+1 #์ด๊ธฐ๋ ค๋ฉด ํ•„์š”ํ•œ ํ™”์‚ด
        ์ ์ˆ˜ํšจ์œจ = (10-i)/ํ•„์š”ํ™”์‚ด
        if info[i] > 0:
            ์ ์ˆ˜ํšจ์œจ *= 2
        arrow_n_score.append([์ ์ˆ˜์œ„์น˜, ์ ์ˆ˜ํšจ์œจ, ํ•„์š”ํ™”์‚ด])
        
    arrow_n_score.sort(key=lambda x:(-x[1],x[2]))
    print(arrow_n_score)
    index = 0
    while n > 0:
        print("์ฒซ๋ฒˆ์งธ", arrow_n_score[index])
        if arrow_n_score[index][2] <= n:
            ryan_arrow[arrow_n_score[index][0]] = arrow_n_score[index][2]
            n -= arrow_n_score[index][2]
        else:
            if index == 10:
                ryan_arrow[arrow_n_score[10][0]] = n
                n = 0
        index += 1
    
    # ์ ์ˆ˜๊ณ„์‚ฐํ•ด์„œ... ๋ชป ๋„˜์–ด๊ฐ€๋ฉด [-1] ๋ฆฌํ„ด
    sum_info, sum_ryan = 0, 0
    for i in range(len(info)):
        if info[i] > ryan_arrow[i]:
            sum_info += 10-i
        elif info[i] < ryan_arrow[i]:
            sum_ryan += 10-i
            
    if sum_info < sum_ryan:
        return ryan_arrow
    else:
        return [-1]
  • ์ฑ„์ ์€?
    • ์‹คํŒจ...
    • ๋‹ค์‹œ ์›์ ์ด๋„ค ใ…‹ใ…‹ใ…‹ใ…‹
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.6MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	์‹คํŒจ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	์‹คํŒจ (0.02ms, 10.2MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	์‹คํŒจ (0.02ms, 10.3MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.3MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	์‹คํŒจ (0.02ms, 10.5MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.6MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	์‹คํŒจ (0.02ms, 10.3MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.2MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	์‹คํŒจ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.5MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	์‹คํŒจ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	์‹คํŒจ (0.02ms, 10.5MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	์‹คํŒจ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.5MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.5MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	์‹คํŒจ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.3MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.6MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.3MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.3MB)
  • ์ˆ˜์ • = ์‹คํŒจ
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.5MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.5MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.5MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	์‹คํŒจ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	์‹คํŒจ (0.05ms, 10.5MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	์‹คํŒจ (0.04ms, 10.4MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	์‹คํŒจ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.6MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.4MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	์‹คํŒจ (0.03ms, 10.6MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	์‹คํŒจ (0.04ms, 10.6MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	์‹คํŒจ (0.05ms, 10.5MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	์‹คํŒจ (0.04ms, 10.4MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.3MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
  • ๊ทผ๋ฐ... ์–ด๋ž?
    • ์•ผ... ์ด๊ฑฐ? ์ด๊ฑฐ!?!?!? ์ด๊ฑฐ...
      • ํ‚ค๋ฉ”๋ผ ์ „๋žต ๊ฐ„๋‹ค. ใ…‹ใ…‹ใ…‹

  • ํ‚ค๋ฉ”๋ผ ์ฝ”๋”ฉ ์ „๋žต = ํ†ต๊ณผํ•˜๋Š” ์ฝ”๋“œ 2๊ฐœ๋ฅผ ํ•ฉ์ณ์„œ ์ •๋‹ต์„ ์ถœ๋ ฅํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์„ ๋งํ•จ.
    • ์•„... ์  ์žฅ!
      • 21๋ฒˆ์€ A,B ๋‘˜๋‹ค ํ†ต๊ณผ ๋ชป ํ–ˆ๋„ค?
  • ์  ์žฅ!
import itertools

def solution(n, info):
    nn = n
    arrow_n_score = [] #๊ณต๊ฒฉ
    arrow_n_score2 = [] #๋ฐฉ์–ด
    ryan_arrow = [0 for i in range(11)]
    ryan_arrow2 = [0 for i in range(11)]
    for i in range(len(info)):
        ์ ์ˆ˜์œ„์น˜ = i
        ํ•„์š”ํ™”์‚ด = info[i]+1 #์ด๊ธฐ๋ ค๋ฉด ํ•„์š”ํ•œ ํ™”์‚ด
        ์ ์ˆ˜ํšจ์œจ1 = (10-i)/ํ•„์š”ํ™”์‚ด
        ์ ์ˆ˜ํšจ์œจ2 = (10-i)/ํ•„์š”ํ™”์‚ด
        if info[i] > 0:
            ์ ์ˆ˜ํšจ์œจ1 += 10-i
            ์ ์ˆ˜ํšจ์œจ2 *= 2
        arrow_n_score.append([์ ์ˆ˜์œ„์น˜, ์ ์ˆ˜ํšจ์œจ1, ํ•„์š”ํ™”์‚ด])
        arrow_n_score2.append([์ ์ˆ˜์œ„์น˜, ์ ์ˆ˜ํšจ์œจ2, ํ•„์š”ํ™”์‚ด])
        
    arrow_n_score.sort(key=lambda x:(-x[1],x[2]))
    index = 0
    while n > 0:
        if arrow_n_score[index][2] <= n:
            ryan_arrow[arrow_n_score[index][0]] = arrow_n_score[index][2]
            n -= arrow_n_score[index][2]
        else:
            if index == 10:
                ryan_arrow[arrow_n_score[10][0]] = n
                n = 0
        index += 1
        
    arrow_n_score2.sort(key=lambda x:(-x[1],x[2]))
    
    n = nn
    index = 0
    while n > 0:
        if arrow_n_score2[index][2] <= n:
            ryan_arrow2[arrow_n_score2[index][0]] = arrow_n_score2[index][2]
            n -= arrow_n_score2[index][2]
        else:
            if index == 10:
                ryan_arrow2[arrow_n_score2[10][0]] = n
                n = 0
        index += 1
        
    sum_info, sum_ryan = 0, 0
    for i in range(len(info)):
        if info[i] > ryan_arrow[i]:
            sum_info += 10-i
        elif info[i] < ryan_arrow[i]:
            sum_ryan += 10-i

    sum_info2, sum_ryan2 = 0, 0
    for i in range(len(info)):
        if info[i] > ryan_arrow2[i]:
            sum_info2 += 10-i
        elif info[i] < ryan_arrow2[i]:
            sum_ryan2 += 10-i
            
    arrow_n_score.sort(key=lambda x:(x[0]))
    arrow_n_score2.sort(key=lambda x:(x[0]))
    sum1 = sum_ryan - sum_info
    sum2 = sum_ryan2 - sum_info2
    #print(sum1, ryan_arrow)
    #print(sum2, ryan_arrow2)
    
    if sum_ryan2 <= sum_info2 and sum_ryan <= sum_info: # ์ ์ˆ˜๊ณ„์‚ฐํ•ด์„œ... ๋ชป ๋„˜์–ด๊ฐ€๋ฉด [-1] ๋ฆฌํ„ด
        return [-1]
    elif sum_ryan2 - sum_info2 > sum_ryan - sum_info:
        return ryan_arrow2
    elif sum_ryan2 - sum_info2 < sum_ryan - sum_info:
        return ryan_arrow
    else:
        for i in reversed(range(len(info))):
            if ryan_arrow[i] > ryan_arrow2[i]:
                return ryan_arrow
            else:
                return ryan_arrow2
        return [0]
        
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.6MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.3MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.5MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.5MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.4MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.6MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.5MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.5MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.5MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.5MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.2MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.6MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	์‹คํŒจ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.5MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.5MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
  • ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค 21๋ฒˆ ๋ญ๋ƒ???
    • ์‚ด๋ ค์ค˜์š”. ใ… .ใ… 
      • ์•„.. ์™œ 21๋ฒˆ ์‹คํŒจํ•œ ๊ฑธ ๋ชป ๋ดค์ง€?
        • ์‹œ๊ฐ„๋งŒ ๋‚ญ๋น„ํ–ˆ๋„ค...
  • ๋ฆฌ์–ผ ๋ฉ์ฒญ์ด์˜ ์žฌ๋„์ „.
    • ์Šคํƒ€ํŠธ!
      • ํ™”์‚ด ํšจ์œจ + ๊ณต๊ฒฉ / ๋ฐฉ์–ด ๊ตฌ๋ถ„ ํ•ด์„œ ํ•˜๋‚˜์˜ ๋ฆฌ์ŠคํŠธ๋กœ ๊ด€๋ฆฌ
        • ์ด์ƒํ•˜๋‹ค... ใ… .ใ… 
  • ๋ฌธ์ œ์— ๊ฐ€์žฅ ํฐ ์ ์ˆ˜ ์ฐจ์ด๋กœ ์šฐ์Šน...์ธ๋ฐ... ์ด ๋ฌธ์ œ๋Š” ํฌ๊ธฐ๋‹ค.

  • ์ด ๋ฌธ์ œ๋Š” ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค.
    • ์ง„์งœ ์นด์นด์˜ค๋ž‘ ๋‚˜๋ž‘์€ ์•ˆ๋งž๋Š” ๋“ฏ... ใ…ก.ใ…ก;;;
      • ๋‚˜์ค‘์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค 1๋ฒˆ ๋‹ต์ด ์™œ 6์  ์ฐจ์ด๋กœ ์ด๊ธฐ๋Š” ๊ฒŒ ์ •๋‹ต์ธ์ง€ ๋“ฃ๊ณ  ๋‚˜์„œ ๋‹ค์‹œ ๋„์ „ํ•˜๊ธฐ๋กœ...
  • ์ผ์ฃผ์ผ์ด ์ง€๋‚ฌ๊ณ , ๋‚˜๋Š” ๋‚ด๊ฐ€ ์ฃผํ™”์ž…๋งˆ์— ๋น ์ ธ์žˆ์—ˆ๋‹ค๋Š” ์‚ฌ์‹ค์„ ์•Œ๊ฒŒ ๋˜์—ˆ๋‹ค.
    • ๋ถ„๋ช…ํžˆ ์ฒ˜์Œ ์ง  ์ฝ”๋“œ์—๋Š” ์ด๋ ‡๊ฒŒ ๋˜์–ด ์žˆ์—ˆ๋Š”๋ฐ...
    • ์ƒˆ๋กœ ์งœ๋ฉด์„œ ์ด๋Ÿฐ ๋ถ€๋ถ„์„ ๊นŒ๋จน์–ด๋ฒ„๋ ธ๋‹ค.
      • ๋งŒ์•ฝ, k(k๋Š” 1~10์‚ฌ์ด์˜ ์ž์—ฐ์ˆ˜)์ ์„ ์–ดํ”ผ์น˜๊ฐ€ a๋ฐœ์„ ๋งžํ˜”๊ณ  ๋ผ์ด์–ธ์ด b๋ฐœ์„ ๋งžํ˜”์„ ๊ฒฝ์šฐ
      • ๋” ๋งŽ์€ ํ™”์‚ด์„ k์ ์— ๋งžํžŒ ์„ ์ˆ˜๊ฐ€ k ์ ์„ ๊ฐ€์ ธ๊ฐ‘๋‹ˆ๋‹ค.
      • ๋‹จ, a = b์ผ ๊ฒฝ์šฐ๋Š” ์–ดํ”ผ์น˜๊ฐ€ k์ ์„ ๊ฐ€์ ธ๊ฐ‘๋‹ˆ๋‹ค.
      • k์ ์„ ์—ฌ๋Ÿฌ ๋ฐœ ๋งžํ˜€๋„ k์  ๋ณด๋‹ค ๋งŽ์€ ์ ์ˆ˜๋ฅผ ๊ฐ€์ ธ๊ฐ€๋Š” ๊ฒŒ ์•„๋‹ˆ๊ณ  k์ ๋งŒ ๊ฐ€์ ธ๊ฐ€๋Š” ๊ฒƒ์„ ์œ ์˜ํ•˜์„ธ์š”.
      • ๋˜ํ•œ a = b = 0 ์ธ ๊ฒฝ์šฐ, ์ฆ‰, ๋ผ์ด์–ธ๊ณผ ์–ดํ”ผ์น˜ ๋ชจ๋‘ k์ ์— ๋‹จ ํ•˜๋‚˜์˜ ํ™”์‚ด๋„ ๋งžํžˆ์ง€ ๋ชปํ•œ ๊ฒฝ์šฐ๋Š” ์–ด๋Š ๋ˆ„๊ตฌ๋„ k์ ์„ ๊ฐ€์ ธ๊ฐ€์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
import itertools

def solution(n, info):
    arrow_n_score = [] # ๋ช…๋ น ์šฐ์„  ์ˆœ์œ„
    ryan_arrow = [0 for i in range(11)]
    
    for i in range(11):
        ์ ์ˆ˜์œ„์น˜ = i
        ํ•„์š”ํ™”์‚ด = info[i] # ์ƒ๋Œ€ ์ ์ˆ˜๋ฅผ ๋ฌด๋ ฅํ™” ์‹œํ‚ค๋ ค๋ฉด ํ•„์š”ํ•œ ํ™”์‚ด
        if ํ•„์š”ํ™”์‚ด == 0:
            arrow_n_score.append([์ ์ˆ˜์œ„์น˜, 10-i, 1, "๋ฌดํ˜ˆ์ž…์„ฑ"])
        else:
            #์ ์ˆ˜ํšจ์œจ = (10-i)/ํ•„์š”ํ™”์‚ด
            #arrow_n_score.append([์ ์ˆ˜์œ„์น˜, ์ ์ˆ˜ํšจ์œจ, ํ•„์š”ํ™”์‚ด, "๋ฌด๋ ฅํ™”"])  #๋ฌด๋ ฅํ™”๊ฐ€ ์•„๋‹ˆ๋ผ ์–ดํ”ผ์น˜๊ฐ€ ์ ์ˆ˜๋ฅผ ๊ฐ€์ ธ๊ฐ.
            ์ ์ˆ˜ํšจ์œจ = ((10-i)+(10-i)/(ํ•„์š”ํ™”์‚ด+1) + 2*(10-i)/(ํ•„์š”ํ™”์‚ด+1))/2
            arrow_n_score.append([์ ์ˆ˜์œ„์น˜, ์ ์ˆ˜ํšจ์œจ, ํ•„์š”ํ™”์‚ด+1, "๋นผ์•—๊ธฐ"])
        
    arrow_n_score.sort(key=lambda x:(-x[1],x[2],-x[0]))
    
    index = 0
    while n > 0 and len(arrow_n_score) > index:
        print("์Šคํƒ€ํŠธ:",arrow_n_score)
        print(ryan_arrow)
        arrows = arrow_n_score[index][2]
        points = arrow_n_score[index][0]
        if arrows <= n:
            ryan_arrow[points] = arrows
            n -= arrows
            for i in range(len(arrow_n_score)):
                if arrow_n_score[i][0] == points:
                    arrow_n_score.pop(i)
                    arrow_n_score.insert(0,[])
            arrow_n_score= [a for a in arrow_n_score if len(a) != 0]
            index = 0
        else:
            index += 1
        print(ryan_arrow)
        
    if n > 0:
        ryan_arrow[10] = n
    
    sum_info, sum_ryan = 0, 0
    for i in range(11):
        if info[i] > ryan_arrow[i]:
            sum_info += 10-i
        elif info[i] < ryan_arrow[i]:
            sum_ryan += 10-i
            
    arrow_n_score.sort(key=lambda x:(x[0]))
    sum1 = sum_ryan - sum_info
    print(sum_info, info)
    print(sum_ryan, ryan_arrow)
    
    if sum_ryan <= sum_info: # ์ ์ˆ˜๊ณ„์‚ฐํ•ด์„œ... ๋ชป ๋„˜์–ด๊ฐ€๋ฉด [-1] ๋ฆฌํ„ด
        return [-1]
    else:
        return ryan_arrow
  • ๋  ๊ฑฐ ๊ฐ™๊ธฐ๋™? ใ…‹ใ…‹ใ…‹
import itertools

def solution(n, info):
    arrow_n_score = [] # ๋ช…๋ น ์šฐ์„  ์ˆœ์œ„
    arrow_n_score2 = []
    arrow_n_score3 = []
    ryan_arrow = [0 for i in range(11)]
    ryan_arrow2 = [0 for i in range(11)]
    ryan_arrow3 = [0 for i in range(11)]
    
    for i in range(11):
        ์ ์ˆ˜์œ„์น˜ = i
        ํ•„์š”ํ™”์‚ด = info[i] # ์ƒ๋Œ€ ์ ์ˆ˜๋ฅผ ๋ฌด๋ ฅํ™” ์‹œํ‚ค๋ ค๋ฉด ํ•„์š”ํ•œ ํ™”์‚ด
        if ํ•„์š”ํ™”์‚ด == 0:
            arrow_n_score.append([์ ์ˆ˜์œ„์น˜, 10-i, 1]) #, "๋ฌดํ˜ˆ์ž…์„ฑ"
        else:
            ์ ์ˆ˜ํšจ์œจ = (10-i)/ํ•„์š”ํ™”์‚ด * 2
            arrow_n_score.append([์ ์ˆ˜์œ„์น˜, -์ ์ˆ˜ํšจ์œจ, ํ•„์š”ํ™”์‚ด, "๋ฌด์“ธ๋ชจ"])  #๋ฌด๋ ฅํ™”๊ฐ€ ์•„๋‹ˆ๋ผ ์–ดํ”ผ์น˜๊ฐ€ ์ ์ˆ˜๋ฅผ ๊ฐ€์ ธ๊ฐ. ๋ฌด์“ธ๋ชจ
            ์ ์ˆ˜ํšจ์œจ = (10-i)/ํ•„์š”ํ™”์‚ด + (10-i)/(ํ•„์š”ํ™”์‚ด+1)
            arrow_n_score.append([์ ์ˆ˜์œ„์น˜, ์ ์ˆ˜ํšจ์œจ, ํ•„์š”ํ™”์‚ด+1]) #, "๋นผ์•—๊ธฐ"
            ์ ์ˆ˜ํšจ์œจ2 = (10-i)/ํ•„์š”ํ™”์‚ด + (10-i)
            arrow_n_score2.append([์ ์ˆ˜์œ„์น˜, ์ ์ˆ˜ํšจ์œจ, ํ•„์š”ํ™”์‚ด+1]) #, "๋ฒ ๋ฆฌ์—์ด์…˜2"
            ์ ์ˆ˜ํšจ์œจ3 = 2 * (10-i)/ํ•„์š”ํ™”์‚ด
            arrow_n_score3.append([์ ์ˆ˜์œ„์น˜, ์ ์ˆ˜ํšจ์œจ, ํ•„์š”ํ™”์‚ด+1]) #, "๋ฒ ๋ฆฌ์—์ด์…˜3"
            
    arrow_n_score.sort(key=lambda x:(-x[1],x[2],-x[0]))
    arrow_n_score2.sort(key=lambda x:(-x[1],x[2],-x[0]))
    arrow_n_score3.sort(key=lambda x:(-x[1],x[2],-x[0]))
    n2 = n
    n3 = n
    
    index = 0
    while n > 0 and len(arrow_n_score) > index:
        arrows = arrow_n_score[index][2]
        points = arrow_n_score[index][0]
        if arrows <= n:
            ryan_arrow[points] = arrows
            n -= arrows
            for i in range(len(arrow_n_score)):
                if arrow_n_score[i][0] == points:
                    arrow_n_score.pop(i)
                    arrow_n_score.insert(0,[])
            arrow_n_score= [a for a in arrow_n_score if len(a) != 0]
            index = 0
        else:
            index += 1
    if n > 0:
        ryan_arrow[10] = n

    index = 0
    while n2 > 0 and len(arrow_n_score2) > index:
        arrows2 = arrow_n_score2[index][2]
        points2 = arrow_n_score2[index][0]
        if arrows2 <= n2:
            ryan_arrow2[points] = arrows2
            n2 -= arrows2
            for i in range(len(arrow_n_score2)):
                if arrow_n_score2[i][0] == points2:
                    arrow_n_score2.pop(i)
                    arrow_n_score2.insert(0,[])
            arrow_n_score2= [a for a in arrow_n_score2 if len(a) != 0]
            index = 0
        else:
            index += 1
    if n2 > 0:
        ryan_arrow2[10] = n2


    index = 0
    while n3 > 0 and len(arrow_n_score3) > index:
        arrows3 = arrow_n_score3[index][2]
        points3 = arrow_n_score3[index][0]
        if arrows3 <= n3:
            ryan_arrow3[points] = arrows3
            n3 -= arrows3
            for i in range(len(arrow_n_score3)):
                if arrow_n_score3[i][0] == points3:
                    arrow_n_score3.pop(i)
                    arrow_n_score3.insert(0,[])
            arrow_n_score3= [a for a in arrow_n_score3 if len(a) != 0]
            index = 0
        else:
            index += 1
    if n3 > 0:
        ryan_arrow3[10] = n3
    
    sum_info1, sum_ryan1 = 0, 0
    for i in range(11):
        if info[i] > ryan_arrow[i]:
            sum_info1 += 10-i
        elif info[i] < ryan_arrow[i]:
            sum_ryan1 += 10-i
    sum1 = sum_ryan1 - sum_info1
    
    sum_info2, sum_ryan2 = 0, 0
    for i in range(11):
        if info[i] > ryan_arrow2[i]:
            sum_info2 += 10-i
        elif info[i] < ryan_arrow2[i]:
            sum_ryan2 += 10-i
    sum2 = sum_ryan2 - sum_info2
    
    sum_info3, sum_ryan3 = 0, 0
    for i in range(11):
        if info[i] > ryan_arrow3[i]:
            sum_info3 += 10-i
        elif info[i] < ryan_arrow3[i]:
            sum_ryan3 += 10-i
    sum3 = sum_ryan3 - sum_info3
    
    if sum_ryan1 <= sum_info1 and sum_ryan2 <= sum_info2 and sum_ryan3 <= sum_info3: # ์ ์ˆ˜๊ณ„์‚ฐํ•ด์„œ... ๋ชป ๋„˜์–ด๊ฐ€๋ฉด [-1] ๋ฆฌํ„ด
        return [-1]
    elif sum1 > sum2 and sum1 > sum3:
        return ryan_arrow
    elif sum2 > sum1 and sum2 > sum3:
        return ryan_arrow2
    elif sum3 > sum1 and sum3 > sum2:
        return ryan_arrow3
    else:
        for i in reversed(range(len(info))):
            if ryan_arrow[i] > ryan_arrow2[i] and ryan_arrow[i] > ryan_arrow3[i] :
                return ryan_arrow
            elif ryan_arrow2[i] > ryan_arrow[i] and ryan_arrow2[i] > ryan_arrow3[i] :
                return ryan_arrow2
            else:
                return ryan_arrow3
            return [0]
  • 3๊ฐœ๋ฅผ ์„ž์ž!

728x90
๋ฐ˜์‘ํ˜•