Submission #13533919


Source Code Expand

package main

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

func main() {
	nextReader = newScanner()
	n := nextInt()
	s := nextString()

	var r, g, b int
	for _, c := range s {
		switch c {
		case 'R':
			r++
		case 'G':
			g++
		case 'B':
			b++
		}
	}
	ans := r * g * b
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			k := 2*j - i
			if k >= n {
				continue
			}
			if s[i] != s[j] && s[j] != s[k] && s[k] != s[i] {
				ans--
			}
		}
	}
	fmt.Println(ans)
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}

Submission Info

Submission Time
Task D - RGB Triplets
User hidapple
Language Go (1.14.1)
Score 400
Code Size 1149 Byte
Status AC
Exec Time 41 ms
Memory 1776 KiB

Judge Result

Set Name All Sample
Score / Max Score 400 / 400 0 / 0
Status
AC × 21
AC × 2
Set Name Test Cases
All sample_01, sample_02, testcase_0, testcase_1, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_2, testcase_3, testcase_4, testcase_5, testcase_6, testcase_7, testcase_8, testcase_9
Sample sample_01, sample_02
Case Name Status Exec Time Memory
sample_01 AC 2 ms 1740 KiB
sample_02 AC 1 ms 1736 KiB
testcase_0 AC 1 ms 1740 KiB
testcase_1 AC 2 ms 1748 KiB
testcase_10 AC 2 ms 1740 KiB
testcase_11 AC 1 ms 1760 KiB
testcase_12 AC 2 ms 1756 KiB
testcase_13 AC 4 ms 1744 KiB
testcase_14 AC 3 ms 1744 KiB
testcase_15 AC 30 ms 1772 KiB
testcase_16 AC 18 ms 1752 KiB
testcase_17 AC 41 ms 1776 KiB
testcase_18 AC 16 ms 1756 KiB
testcase_2 AC 3 ms 1752 KiB
testcase_3 AC 11 ms 1752 KiB
testcase_4 AC 1 ms 1740 KiB
testcase_5 AC 2 ms 1756 KiB
testcase_6 AC 3 ms 1756 KiB
testcase_7 AC 2 ms 1740 KiB
testcase_8 AC 1 ms 1736 KiB
testcase_9 AC 2 ms 1752 KiB