結果

問題 No.59 鉄道の旅
ユーザー aru aruaru aru
提出日時 2020-07-22 21:30:01
言語 Go
(1.23.4)
結果
TLE  
実行時間 -
コード長 1,582 bytes
コンパイル時間 14,031 ms
コンパイル使用メモリ 236,820 KB
実行使用メモリ 17,060 KB
最終ジャッジ日時 2024-06-22 13:48:25
合計ジャッジ時間 23,062 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10 TLE * 1 -- * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
func out(x ...interface{}) {
fmt.Println(x...)
}
var sc = bufio.NewScanner(os.Stdin)
func getInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
func getInts(N int) []int {
ret := make([]int, N)
for i := 0; i < N; i++ {
ret[i] = getInt()
}
return ret
}
func getString() string {
sc.Scan()
return sc.Text()
}
// min, max, asub, abs
func max(a, b int) int {
if a > b {
return a
}
return b
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func asub(a, b int) int {
if a > b {
return a - b
}
return b - a
}
func abs(a int) int {
if a >= 0 {
return a
}
return -a
}
func lowerBound(a []int, x int) int {
idx := sort.Search(len(a), func(i int) bool {
return a[i] >= x
})
return idx
}
func upperBound(a []int, x int) int {
idx := sort.Search(len(a), func(i int) bool {
return a[i] > x
})
return idx
}
func main() {
sc.Split(bufio.ScanWords)
N, K := getInt(), getInt()
w := getInts(N)
q := make([]int, 0)
for i := 0; i < N; i++ {
// out("w=", w[i])
if w[i] < 0 {
x := lowerBound(q, -w[i])
// out(x)
if x < len(q) && q[x] == -w[i] {
// out("down", q, -w[x], x)
q = append(q[:x], q[x+1:]...)
}
} else {
x := lowerBound(q, w[i])
if len(q)-x < K {
// out(x, len(q))
// if len(q) == 0 {
// q = append(q, w[i])
// } else {
q = append(q[:x],
append([]int{w[i]}, q[x:]...)...)
// }
//sort.Ints(q)
}
}
// out(q)
}
out(len(q))
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0