1065 : ํ•œ์ˆ˜

1065 : ํ•œ์ˆ˜#

  • https://d2gd6pc034wcta.cloudfront.net/tier/7.svg ์‹ค๋ฒ„ 4

์‹œ๊ฐ„์ œํ•œ

๋ฉ”๋ชจ๋ฆฌ์ œํ•œ

์ •๋‹ต๋น„์œจ

2์ดˆ

128MB

54.286%

๋ฌธ์ œ#

์–ด๋–ค ์–‘์˜ ์ •์ˆ˜ X์˜ ๊ฐ ์ž๋ฆฌ๊ฐ€ ๋“ฑ์ฐจ์ˆ˜์—ด์„ ์ด๋ฃฌ๋‹ค๋ฉด, ๊ทธ ์ˆ˜๋ฅผ ํ•œ์ˆ˜๋ผ๊ณ  ํ•œ๋‹ค. ๋“ฑ์ฐจ์ˆ˜์—ด์€ ์—ฐ์†๋œ ๋‘ ๊ฐœ์˜ ์ˆ˜์˜ ์ฐจ์ด๊ฐ€ ์ผ์ •ํ•œ ์ˆ˜์—ด์„ ๋งํ•œ๋‹ค. N์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , N๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ํ•œ์ˆ˜์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

input#

0 < n <= 1000

output#

1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , n๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ํ•œ์ˆ˜์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅ

think#

๋”ฑ ๋ณด์•„ํ•˜๋‹ˆ n ์ดํ•˜์˜ ์ž‘์—…๋ฌผ๋“ค์„ ๊ธฐ๋กํ•˜๋ฉด์„œ ๊ฐ€์•ผํ•  dp๋ฌธ์ œ๋กœ ๋ณด์ธ๋‹ค. ์ ํ™”์‹์„ ์จ๋ณด์žโ€ฆ ๊ณ  ํ–ˆ์œผ๋‚˜ ํ’€๊ณ  ๋ณด๋‹ˆ, dp๋กœ ํ‘ธ๋Š” ๋ฌธ์ œ ๊ฐ™์ง€๋งŒ ์‚ฌ์‹ค์ƒ ์‚ฌ๋žŒ๋“ค์€ brute force๋กœ ์™„์ „ํƒ์ƒ‰ํ•˜๋ฉด์„œ ํ–ˆ๋˜๋ฐ ๊ทธ๊ฒŒ ํ›จ์”ฌ ๋น ๋ฅธ ๊ฒƒ ๊ฐ™๋‹ค. ๊ตณ์ด dp๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•  ํ•„์š”๋Š” ์—†๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ธ๋‹ค.

python#

import sys, os

problem_num = "1065"

path = os.getcwd() + f"\\txt\\{problem_num}" + ".txt"
sys.stdin = open(path, "r")
input = sys.stdin.readline
n = int(input())
from typing import List
def spliting(x:int) -> List[int]:
    '''
    make a x:int to list of elements
    '''
    return [int(i) for i in str(x)]

class Hansu:
    def __init__(self,n):
        self.dp = [i for i in range(1,n+1)]
        
    def arithmetic_sequence(self):
        bool_list = []
        for i in self.dp:
            if (i < 100) or (spliting(i)[2] - spliting(i)[1] == spliting(i)[1] - spliting(i)[0]):
                bool_list.append(True)
            else:
                bool_list.append(False)
                    
        return bool_list.count(True)
            
print(Hansu(n).arithmetic_sequence())
144