user-img
java ํ’€์ด 2
thumbnail
[๋ฐฑ์ค€] ๋‘ ์šฉ์•ก java ์‰ฌ์šด ํ’€์ด^^
1. ๋ฌธ์ œ ์„ค๋ช… ๐Ÿ“Œ๋ฌธ์ œ ๋งํฌ์šฉ์•ก๋งˆ๋‹ค ํŠน์ˆ˜๊ฐ’์ด ์กด์žฌ๋‘ ์šฉ์•ก์„ ๊ณจ๋ผ์„œ ๋‘˜์˜ ํŠน์ˆ˜ ๊ฐ’์„ ํ•ฉํ–ˆ์„ ๋•Œ, ๊ทธ ํ•ฉ์ด 0์— ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์กฐํ•ฉ์„ ๊ตฌํ•˜์—ฌ๋ผ2. ์ ‘๊ทผ ๋ฐฉ์‹ ๐Ÿ—ƒ๏ธKEY WORD: Two way Two pointer์šฉ์•ก์˜ ํŠน์ˆ˜๊ฐ’์„ 1์ฐจ์› ๋ฐฐ์—ด์— ์ž…๋ ฅ๋ฐ›๊ณ , ํ•ด๋‹น ๋ฐฐ์—ด์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.index = 0์— L ํฌ์ธํ„ฐ, index = N-1์— R ํฌ์ธํ„ฐ๋ฅผ ๋‘”๋‹คL+R > 0 ์ผ ๊ฒฝ์šฐ, R ํฌ์ธํ„ฐ๋ฅผ ํ•œ ์นธ ํ›„์ง„ ์‹œ์ผœ์„œ ํ•ฉ์„ ํ•˜ํ–ฅ์กฐ์ •ํ•œ๋‹ค.L-R ์ผ ๊ฒฝ์šฐ, L ํฌ์ธํ„ฐ๋ฅผ ํ•œ ์นธ ์ „์ง„ ์‹œ์ผœ์„œ ํ•ฉ์„ ์ƒํ–ฅ์กฐ์ •ํ•œ๋‹ค.0์— ๊ฐ€๊นŒ์šด ๊ฐ’์„ ๊ตฌํ•ด์•ผํ•จ์œผ๋กœ, ๋‘˜ ์‚ฌ์ด์˜ ํ•ฉ์˜ ์ ˆ๋Œ€๊ฐ’์ด ์ตœ์†Œ์ธ ๊ฒฝ์šฐ๋ฅผ ์ฐพ์œผ๋ฉด ๋œ๋‹ค.(์™œ๋ƒํ•˜๋ฉด, ๋‘ ํฌ์ธํ„ฐ ์‚ฌ์ด์˜ ํ•ฉ์˜ ์ ˆ๋Œ€๊ฐ’์ด ์ปค์งˆ์ˆ˜๋ก 0์—์„œ ๋ฉ€์–ด์ง€๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.)(1) ๋‹จ๋ฑกํ•ญ ํˆฌ ํฌ์ธํ„ฐ๋กœ ๋‹ต์„ ๊ตฌํ•  ์ˆ˜ ์—†๋Š” ..
2024.12.23
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด
thumbnail
[๋ฐฑ์ค€] 3020 ๊ฐœ๋˜ฅ๋ฒŒ๋ ˆ java ์™„๋ฒฝ ํ’€์ด!
1. ๋ฌธ์ œ ์„ค๋ช… ๐Ÿ“Œ๋ฌธ์ œ ๋งํฌ2. ์ ‘๊ทผ ๋ฐฉ์‹ ๐Ÿ—ƒ๏ธKEY WORD: ๋ˆ„์  ํ•ฉ, ์ด๋ถ„ ํƒ์ƒ‰๋™๊ตด์˜ ๋†’์ด์ธ H์™€ ๊นŠ์ด์ธ N์ด ๊ฐ๊ฐ \(10^{5}\)์ด๋ฏ€๋กœ, ์™„์ „ ํƒ์ƒ‰์œผ๋กœ ํ•˜๋‚˜์˜ ํ–‰๋งˆ๋‹ค ๋ชจ๋“  ์—ด์„ ์กฐํšŒํ•œ๋‹ค๋ฉด 1์ดˆ์— \(10^{10}\)๋ฒˆ ์ด์ƒ์˜ ์—ฐ์‚ฐ์„ ํ•ด์•ผํ•ด์„œ ์‹œ๊ฐ„ ์ดˆ๊ณผ๊ฐ€ ๋‚  ๊ฒƒ์ด๋‹ค.ํ•ด๋‹น ๋ฌธ์ œ๋Š” *๊ฑฐ๊พธ๋กœ ๋งค๋‹ฌ๋ ค ์žˆ๋Š” ์ข…์œ ์„์„ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•  ๊ฒƒ์ธ๊ฐ€?* ์— ๋Œ€ํ•œ ๋ช…ํ™•ํ•œ ๊ฐ€์ด๋“œ๋ผ์ธ๋งŒ ๊ณ„ํšํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด๋‹ค. ์ข…์œ ์„ ์ฒ˜๋ฆฌ๋ฐฉ๋ฒ•์— ๋”ฐ๋ผ ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋Š”๋ฐ, ํ•˜๋‚˜๋Š” ๋ˆ„์  ํ•ฉ์ด๊ณ  ๋‹ค๋ฅธ ํ•˜๋‚˜๋Š” ์ด๋ถ„ ํƒ์ƒ‰์ด๋‹ค.(1) ๋ˆ„์ ํ•ฉa. ๊ฒฐ๋ก  ๋จผ์ €1. "์„์ˆœ๊ณผ ์ข…์œ ์„ ์ž…๋ ฅ์„ ๋ถ„๋ฅ˜ํ•˜์—ฌ Y์ถ• ์œ„์น˜์— ๋”ฐ๋ฅธ ๊ฐ ์‚ฐ๋ฌผ์˜ ์œ„์น˜๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐฐ์—ด ๊ตฌํ˜„"2. "๊ฐ ๋ฐฐ์—ด์˜ ๋ˆ„์ ํ•ฉ ๊ตฌํ•˜๊ธฐ (์„์ˆœ ๋ˆ„์ ํ•ฉ ๋ฐฐ์—ด์„ sum_S[i], ..
2024.12.19
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด