ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/5883
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
var b = make([]int, n)
keyMap := map[int]bool{}
for i := 0; i < n; i++ {
fmt.Fscanln(reader, &b[i])
keyMap[b[i]] = true
}
var maxContinuousCount = 1
for key := range keyMap {
keyToDelete := key
var newLine []int
for i := 0; i < n; i++ {
if b[i] != keyToDelete {
newLine = append(newLine, b[i])
}
}
if len(newLine) == 0 {
maxContinuousCount = 0
break
}
var prev = newLine[0]
var continuousCount = 1
for i := 1; i < len(newLine); i++ {
var cur = newLine[i]
if cur == prev {
continuousCount++
if maxContinuousCount < continuousCount {
maxContinuousCount = continuousCount
}
} else {
continuousCount = 1
}
prev = cur
}
}
fmt.Fprintln(writer, maxContinuousCount)
}
๐จ Python3
# https://www.acmicpc.net/problem/5883
import sys
if __name__ == "__main__":
n = int(sys.stdin.readline())
b = []
keys = {}
for _ in range(n):
input = int(sys.stdin.readline())
b.append(input)
keys[input] = True
max_continuous_count = 1
for key_to_delete in keys:
new_line = []
for i in range(n):
if b[i] != key_to_delete:
new_line.append(b[i])
if len(new_line) == 0:
max_continuous_count = 0
break
prev = new_line[0]
continuous_count = 1
for i in range(1, len(new_line)):
cur = new_line[i]
if cur == prev:
continuous_count += 1
max_continuous_count = max(max_continuous_count, continuous_count)
else:
continuous_count = 1
prev = cur
print(max_continuous_count)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 7576๋ฒ / ํ ๋งํ [Go][Python3] (0) | 2021.03.16 |
---|---|
BOJ / 11140๋ฒ / LOL [Go][Python3] (0) | 2021.03.15 |
BOJ / 14606๋ฒ / ํผ์ (Small) [Go][Python3] (0) | 2021.03.13 |
BOJ / 2847๋ฒ / ๊ฒ์์ ๋ง๋ ๋์ค์ด [Go][Python3] (0) | 2021.03.12 |
BOJ / 15828๋ฒ / Router [Go][Python3] (0) | 2021.03.11 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋ชฝ๊ณ ๋๋น
- dp
- MongoDB
- Algorithm
- ์๋ฐ
- ์ด๋ถํ์
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋ฐ๋
- ์๊ณ ๋ฆฌ์ฆ
- ๋ธ๋ฃจํธํฌ์ค
- ๋ถํ ์ ๋ณต
- ๋ฐฑ์ค
- ๋งฅ๋ถํ๋ก
- ํ
- dfs
- baekjoon
- Golang
- BOJ
- ์๊ฐ๊ต์ฒด
- AWS
- ํ๋ก์ด๋์์ฌ
- go
- Macbook pro 2012 mid 13
- BFS
- ballet
- ๋งฅ๋ถ
- java
- python3
- ํด์๋งต
- ์คํ
- Total
- Today
- Yesterday