Submission #7339839


Source Code Expand

Copy
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInt64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	var n, m int

	n = nextInt()
	m = nextInt()

	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
		if i != 0 {
			a[i] += a[i-1]
		}
		a[i] %= m
	}

	var ans int64
	mp := make(map[int]int)

	for i := 0; i < n; i++ {
		mp[a[i]]++
		if a[i] == 0 {
			ans += int64(mp[0])
		} else {
			ans += int64(mp[a[i]]) - 1
		}
	}
	fmt.Println(ans)
}

Submission Info

Submission Time
Task D - Candy Distribution
User kira924age
Language Go (1.6)
Score 400
Code Size 779 Byte
Status
Exec Time 40 ms
Memory 7296 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01, sample_02, sample_03
All 400 / 400 0_min0, 0_min1, 1_small0, 1_small1, 1_small2, 2_large0, 2_large1, 2_large2, 2_large3, 2_large4, 2_large5, 2_large6, 2_large7, 2_large8, 2_large9, 3_max0, 3_max1, 3_max2, 3_max3, 3_max4, 3_max5, 3_max6, 3_max7, sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_min0 1 ms 640 KB
0_min1 1 ms 640 KB
1_small0 1 ms 640 KB
1_small1 1 ms 640 KB
1_small2 1 ms 640 KB
2_large0 2 ms 768 KB
2_large1 30 ms 2560 KB
2_large2 26 ms 2176 KB
2_large3 18 ms 1664 KB
2_large4 28 ms 2176 KB
2_large5 4 ms 768 KB
2_large6 16 ms 1408 KB
2_large7 14 ms 1280 KB
2_large8 1 ms 640 KB
2_large9 9 ms 1024 KB
3_max0 40 ms 7296 KB
3_max1 31 ms 2560 KB
3_max2 32 ms 2304 KB
3_max3 20 ms 1536 KB
3_max4 18 ms 1536 KB
3_max5 18 ms 1536 KB
3_max6 35 ms 2944 KB
3_max7 35 ms 2944 KB
sample_01 1 ms 640 KB
sample_02 1 ms 640 KB
sample_03 1 ms 640 KB