ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1024
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n, l int
fmt.Fscanln(reader, &n, &l)
start := n/l - l/2
var sum int
for {
if start < 0 {
start++
}
sum = 0
for i := start; i < start+l; i++ {
sum += i
}
if sum < n {
start++
} else if sum == n {
if start < 0 {
fmt.Fprintln(writer, -1)
return
}
break
} else if sum > n {
l++
if l > 100 {
fmt.Fprintln(writer, -1)
return
}
start = n/l - l/2
}
}
for i := start; i < start+l; i++ {
fmt.Fprintf(writer, "%d ", i)
}
fmt.Fprintln(writer, "")
}
๐จ Python3
# https://www.acmicpc.net/problem/1024
import sys
if __name__ == "__main__":
n, l = list(map(int, sys.stdin.readline().split()))
start = n//l - l//2
total = 0
is_valid = True
while True:
if start < 0:
start += 1
total = 0
for i in range(start, start+l):
total += i
if total < n:
start += 1
elif total == n:
if start < 0:
is_valid = False
break
break
elif total > n:
l += 1
if l > 100:
is_valid = False
break
start = n//l - l//2
if is_valid:
for i in range(start, start+l):
print("{} ".format(i), end='')
print()
else:
print(-1)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 2193๋ฒ / ์ด์น์ [Go][Python3] (0) | 2021.01.11 |
---|---|
BOJ / 9095๋ฒ / 1, 2, 3 ๋ํ๊ธฐ [Go][Python3] (0) | 2021.01.10 |
BOJ / 1004๋ฒ / ์ด๋ฆฐ ์์ [Go][Python3] (0) | 2021.01.08 |
BOJ / 11719๋ฒ / ๊ทธ๋๋ก ์ถ๋ ฅํ๊ธฐ 2 [Go][Python3] (0) | 2021.01.07 |
BOJ / 18243๋ฒ / Small World Network [Go][Python3] (0) | 2021.01.06 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋ฐ๋
- BFS
- BOJ
- ์๋ฐ
- ๋งฅ๋ถ
- ๋ฐฑ์ค
- Macbook pro 2012 mid 13
- go
- Algorithm
- ๋ถํ ์ ๋ณต
- ์ด๋ถํ์
- ํ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ํ๋ก์ด๋์์ฌ
- ์คํ
- Golang
- MongoDB
- ์๊ฐ๊ต์ฒด
- java
- dfs
- ballet
- AWS
- ๋ชฝ๊ณ ๋๋น
- ๋งฅ๋ถํ๋ก
- dp
- python3
- ๋ธ๋ฃจํธํฌ์ค
- ํด์๋งต
- ์๊ณ ๋ฆฌ์ฆ
- baekjoon
- Total
- Today
- Yesterday