๐Ÿ’ฃ ๋ฌธ์ž์—ด ํญ๋ฐœ

๋ฐฑ์ค€ Class4 Gold4

solved_ac[Class4] ๋ฌธ์ž์—ด ํญ๋ฐœ

๋ฌธ์ œ


์ƒ๊ทผ์ด๋Š” ๋ฌธ์ž์—ด์— ํญ๋ฐœ ๋ฌธ์ž์—ด์„ ์‹ฌ์–ด ๋†“์•˜๋‹ค. ํญ๋ฐœ ๋ฌธ์ž์—ด์ด ํญ๋ฐœํ•˜๋ฉด ๊ทธ ๋ฌธ์ž๋Š” ๋ฌธ์ž์—ด์—์„œ ์‚ฌ๋ผ์ง€๋ฉฐ, ๋‚จ์€ ๋ฌธ์ž์—ด์€ ํ•ฉ์ณ์ง€๊ฒŒ ๋œ๋‹ค.

ํญ๋ฐœ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์œผ๋กœ ์ง„ํ–‰๋œ๋‹ค.

  • ๋ฌธ์ž์—ด์ด ํญ๋ฐœ ๋ฌธ์ž์—ด์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ๊ฒฝ์šฐ์—, ๋ชจ๋“  ํญ๋ฐœ ๋ฌธ์ž์—ด์ด ํญ๋ฐœํ•˜๊ฒŒ ๋œ๋‹ค. ๋‚จ์€ ๋ฌธ์ž์—ด์„ ์ˆœ์„œ๋Œ€๋กœ ์ด์–ด ๋ถ™์—ฌ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋งŒ๋“ ๋‹ค.
  • ์ƒˆ๋กœ ์ƒ๊ธด ๋ฌธ์ž์—ด์— ํญ๋ฐœ ๋ฌธ์ž์—ด์ด ํฌํ•จ๋˜์–ด ์žˆ์„ ์ˆ˜๋„ ์žˆ๋‹ค.
  • ํญ๋ฐœ์€ ํญ๋ฐœ ๋ฌธ์ž์—ด์ด ๋ฌธ์ž์—ด์— ์—†์„ ๋•Œ๊นŒ์ง€ ๊ณ„์†๋œ๋‹ค.

์ƒ๊ทผ์ด๋Š” ๋ชจ๋“  ํญ๋ฐœ์ด ๋๋‚œ ํ›„์— ์–ด๋–ค ๋ฌธ์ž์—ด์ด ๋‚จ๋Š”์ง€ ๊ตฌํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค. ๋‚จ์•„์žˆ๋Š” ๋ฌธ์ž๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ์ด๋•Œ๋Š” โ€œFRULAโ€๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

ํญ๋ฐœ ๋ฌธ์ž์—ด์€ ๊ฐ™์€ ๋ฌธ์ž๋ฅผ ๋‘ ๊ฐœ ์ด์ƒ ํฌํ•จํ•˜์ง€ ์•Š๋Š”๋‹ค.

์ž…๋ ฅ


์ฒซ์งธ ์ค„์— ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 1,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค.

๋‘˜์งธ ์ค„์— ํญ๋ฐœ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ๊ธธ์ด๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 36๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค.

๋‘ ๋ฌธ์ž์—ด์€ ๋ชจ๋‘ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž์™€ ๋Œ€๋ฌธ์ž, ์ˆซ์ž 0, 1, โ€ฆ, 9๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค.

์ถœ๋ ฅ


์ฒซ์งธ ์ค„์— ๋ชจ๋“  ํญ๋ฐœ์ด ๋๋‚œ ํ›„ ๋‚จ์€ ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1

mirkovC4nizCC44
C4

์˜ˆ์ œ ์ถœ๋ ฅ 1

mirkovniz

์˜ˆ์ œ ์ž…๋ ฅ 2

12ab112ab2ab
12ab

์˜ˆ์ œ ์ถœ๋ ฅ 2

FRULA

๐Ÿ“– ์ž๋ฃŒ๊ตฌ์กฐ

[๋ฌธ์ž์—ด์—์„œ ํŠน์ • ๋ฌธ์ž์—ด์„ ์—ฐ์†์ ์œผ๋กœ ์ œ๊ฑฐํ•ด๋‚˜๊ฐˆ๋•Œ ์Šคํƒ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.]

์Šคํƒ์„ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ์‚ฌ์‹ค์„ ์•Œ์•„์ฐจ๋ฆฌ์ง€ ๋ชป ํ•˜๋ฉด ํ’€๊ธฐ๊ฐ€ ์ƒ๋‹นํžˆ ๊นŒ๋‹ค๋กญ๋‹ค.

๋ฌด๋ ค 3์‹œ๊ฐ„ ๋™์•ˆ ์‚ฝ์งˆ์„ ํ–ˆ๋‹ค โ€ฆ ๐Ÿ˜ญ

TRY 1

แ„‹แ…งแ†ซแ„‰แ…ณแ†ธแ„Œแ…กแ†ผ-23

๐Ÿ‘‰๐Ÿป TLE

join ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ string ํ˜•ํƒœ๋ฅผ ์œ ์ง€ํ•˜๋ฉฐ ๋ฌธ์ž์—ด์„ ์ œ๊ฑฐํ•ด๋‚˜๊ฐ€๋Š” ๋ฐฉ์‹์ด๋‹ค.

join ํ•จ์ˆ˜๋Š” ๋†’์€ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ๊ฐ–๊ธฐ ๋•Œ๋ฌธ์— ์‹œ๊ฐ„ ์ดˆ๊ณผ์— ๊ฑธ๋ฆฌ๊ฒŒ ๋œ๋‹ค.

TRY 2

แ„‹แ…งแ†ซแ„‰แ…ณแ†ธแ„Œแ…กแ†ผ-24

๐Ÿ‘‰๐Ÿป ๊ตฌํ˜„ ๋ชป ํ•˜์˜€์Œ.

์˜ˆ์ œ๋ฅผ ์‚ดํŽด๋ณด์ž.

์›๋ณธ ๋ฌธ์ž์—ด: 12ab112ab2ab , ํญํƒ„ ๋ฌธ์ž์—ด: 12ab

  • ๋ฌธ์ž์—ด์„ ๋ฆฌ์ŠคํŠธ ํ˜•ํƒœ๋กœ ๋ฐ”๊พผ๋‹ค.
  • ์›๋ณธ ๋ฆฌ์ŠคํŠธ๋ฅผ ํญํƒ„ ๋ฆฌ์ŠคํŠธ์™€ ๋น„๊ตํ•ด๋ณด๋ฉด์„œ ๊ฒน์น˜๋Š” ๋ถ€๋ถ„์„ ๊ณต๋ฐฑ์œผ๋กœ ์น˜ํ™˜
  • ์ด๋ฅผ ๋ฐ˜๋ณต
  • ์ตœ์ข… ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ (join ํ•จ์ˆ˜๋ฅผ ํ•œ ๋ฒˆ๋งŒ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋ผ ํŒ๋‹จ)

2๋ฒˆ ๋‹จ๊ณ„์—์„œ 3๋ฒˆ ๋‹จ๊ณ„๋กœ ๋„˜์–ด๊ฐ€๋Š” ๊ฒƒ์„ ๊ตฌํ˜„ํ•˜๊ธฐ๊ฐ€ ์–ด๋ ค์›Œ ํฌ๊ธฐํ•จ.

TRY 3

แ„‹แ…งแ†ซแ„‰แ…ณแ†ธแ„Œแ…กแ†ผ-25

๐Ÿ‘‰๐Ÿป ์ •๋‹ต

์›๋ณธ ๋ฌธ์ž์—ด์—์„œ ๋ฌธ์ž๋ฅผ ํ•˜๋‚˜์”ฉ ๊บผ๋‚ด์–ด ์Šคํƒ์— ๋‹ด์•„๊ฐ€๋ฉด์„œ ํญํƒ„ ๋ฌธ์ž์—ด์ด ์™„์„ฑ๋์„ ๋•Œ POP์„ ์‹œํ‚จ๋‹ค.

๊ทธ๋ ‡๊ฒŒ ํ•˜์—ฌ ์ตœ์ข… ์Šคํƒ์„ ๋ฌธ์ž์—ด ํ˜•ํƒœ๋กœ ์ถœ๋ ฅํ•˜๋ฉด ์ •๋‹ต!

๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป CODE

TRY 1

### ๋ฌธ์ œ ์กฐ๊ฑด ###
string = input()
bomb = input()
######


def bomb_check(i,string,bomb):
    for c in bomb:
        if string[i] != c:
            return False
        i += 1
    return True

while True:
    save_string = string
    # ๋ฌธ์ž์—ด ํญ๋ฐœ๋ถ€
    for i in range(len(string)):
        if string[i] == bomb[0]:
            if bomb_check(i,string,bomb):
                temp = list(string)
                for j in range(len(bomb)):
                    temp[i+j] = " "
                string = "".join(temp)
    string = string.replace(" ","")

    if save_string == string:
        break

if string == "":
    print("FRULA")
else:
    print(string)

TRY 3

### ๋ฌธ์ œ ์กฐ๊ฑด ###
string = []
temp = input()
for i in range(len(temp)):
    string.append(temp[i])
bomb = []
temp = input()
for i in range(len(temp)):
    bomb.append(temp[i])
######

stack = []
count = 0

for i in range(len(string)):
    stack.append(string[i])
    count += 1

    if count >= len(bomb):
        for j in range(count-len(bomb),count):
            if stack[j] != bomb[j-count]:
                break
        else:
            for k in range(len(bomb)):
                stack.pop()
                count -= 1

if not stack:
    print("FRULA")
else:
    print("".join(stack))

ยฉ 2022. All rights reserved.

Powered by Hydejack v9.1.6