結果

問題 No.346 チワワ数え上げ問題
ユーザー yukirinyukirin
提出日時 2016-02-27 17:17:50
言語 Go
(1.22.1)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 11,646 ms
コンパイル使用メモリ 240,464 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 06:18:47
合計ジャッジ時間 12,833 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 19 ms
5,376 KB
testcase_11 AC 15 ms
5,376 KB
testcase_12 AC 24 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 20 ms
5,376 KB
testcase_16 AC 27 ms
5,376 KB
testcase_17 AC 20 ms
5,376 KB
testcase_18 AC 19 ms
5,376 KB
testcase_19 AC 36 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 62 ms
5,376 KB
testcase_22 AC 63 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func main() {
	s := readLine()
	r := regexp.MustCompile(`[^cw]`)
	s = r.ReplaceAllString(s, "")

	t := 0
	for i, v := range s {
		if v != 'c' {
			continue
		}

		w := strings.Count(s[i+1:], "w")
		if w < 2 {
			break
		}
		t += ncr(w, 2)

	}
	fmt.Println(t)
}

func ncr(n, r int) int {
	if n < 0 || r < 0 || r > n {
		return 0
	}
	k := r
	if k > n/2 {
		k = n - r
	}

	ret := int(1)
	for i := int(1); i <= k; i++ {
		ret *= n - i + 1
		ret /= i
	}
	return ret
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
0