Search
Duplicate
๐Ÿฅˆ

ํšŒ์ „ ์ดˆ๋ฐฅ

์ฃผ์ฐจ
17
๋ฌธ์ œ๋ฒˆํ˜ธ
2531
์–ธ์–ด
Python
ํ‹ฐ์–ด
์‹ค๋ฒ„
์œ ํ˜•
ํˆฌ ํฌ์ธํ„ฐ
nj_Blog
O
nj_์ƒํƒœ
์™„๋ฃŒ
์ดํ•ด๋„
ํ’€์ด
์‚ฌ๋žŒ
์ดํ•ด๋„ 2
13 more properties

๋ฌธ์ œ๋งํฌ

https://www.acmicpc.net/problem/2531

์ฝ”๋“œ ์ œ์ถœ ๊ธฐ๋ก (๋ฉ”๋ชจ๋ฆฌ ๋ฐ ์‹œ๊ฐ„)

์ œ์ถœ ๋‚ ์งœ

@4/23/2021

๋ฉ”๋ชจ๋ฆฌ

166384 KB

์‹œ๊ฐ„

4216 ms

๋ฉ”๋ชจ

โ€ข
ํˆฌ ํฌ์ธํ„ฐ ๋ฌธ์ œ์ง€๋งŒ ํˆฌํฌ์ธํ„ฐ ์‚ฌ์šฉ์•ˆํ•˜๊ณ  ์™„์ „ํƒ์ƒ‰์œผ๋กœ ํ’€์—ˆ์Œ

๋ฌธ์ œํ’€์ด

set ๋ฐฐ์—ด
โ†’ for i in range(N):
i ๋ถ€ํ„ฐ ์—ฐ์†์œผ๋กœ k ๊ฐœ์˜ ์ดˆ๋ฐฅ์˜ ๋ฒˆํ˜ธ๋ฅผ ์ €์žฅํ•˜๋Š” ํ•จ์ˆ˜
arr ๋ฐฐ์—ด
โ†’ d ๊ฐœ์˜ 0์œผ๋กœ ์ดˆ๊ธฐํ™” ๋˜์–ด์žˆ๋Š” ๋ฐฐ์—ด
arr[set์— ๋“ค์–ด์žˆ๋Š” ํ•จ์ˆ˜์˜ ๋ฒˆํ˜ธ] = 1
โ†’ arr.count(1) : ์„œ๋กœ ๋‹ค๋ฅธ ์ดˆ๋ฐฅ์˜ ๊ฐœ์ˆ˜

Code

N, d, k, c = map(int, input().split()) sushi = [] for _ in range(N): sushi.append(int(input())) MAX = 0 for i in range(N): arr = [0 for _ in range(d+1)] kind = 0 set = [] for j in range(k): arr[sushi[(i+j) % N]] = 1 set.append(sushi[(i+j) % N]) kind += arr.count(1) # ์ฟ ํฐ๋ฒˆํ˜ธ์˜ ์ดˆ๋ฐฅ์ด set์— ํฌํ•จ๋˜์–ด์žˆ์ง€ ์•Š์œผ๋ฉด if c not in set: kind += 1 MAX = max(MAX, kind) print(MAX)
Python
๋ณต์‚ฌ