結果

問題 No.59 鉄道の旅
ユーザー 184184
提出日時 2014-11-07 01:05:21
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 878 bytes
コンパイル時間 10,507 ms
コンパイル使用メモリ 209,760 KB
実行使用メモリ 11,428 KB
最終ジャッジ日時 2023-08-26 05:29:27
合計ジャッジ時間 17,168 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,584 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func Scan() (input string) {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		input = scanner.Text()
	}
	return
}

func Sign(n int) (int, string) {
	if n >= 0 {
		return n, "+"
	} else {
		ns := []byte(strconv.Itoa(n))
		n, _ := strconv.Atoi(string(ns[1:]))
		return n, "-"
	}
}

func Sum(xs ...int) (s int) {
	for _, x := range xs {
		s += x
	}
	return
}

func main() {
	list := make([]int, 1000001)

	NK := strings.Split(Scan(), " ")
	N, _ := strconv.Atoi(NK[0])
	K, _ := strconv.Atoi(NK[1])

	for i := 0; i < N; i++ {
		W, _ := strconv.Atoi(Scan())
		W, s := Sign(W)

		if s == "+" {
			if Sum(list[W:]...) < K {
				list[W] += 1
			}
		} else if s == "-" {
			if list[W] > 0 {
				list[W] -= 1
			}
		}
	}
	fmt.Println(Sum(list...))
}
0