AtCoder Beginner Contest 008

Submission #6905279

Source codeソースコード

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}
	p := 1
	for i := 1; i <= n; i++ {
		p *= i
	}

	l := len(c)
	cnt := 0
	for i := 0; i < p; i++ {
		c = nextPermutation(c)
		b := make([]bool, len(c))
		for j := 0; j < l-1; j++ {
			for k := j + 1; k < l; k++ {
				if c[k]%c[j] == 0 {
					b[k] = toggle(b[k])
				}
			}
		}
		cnt += count(b)
	}
	fmt.Println(float64(cnt) / float64(p))
}

func toggle(b bool) bool {
	if b {
		return false
	}
	return true
}

func count(bs []bool) int {
	cnt := 0
	for _, v := range bs {
		if !v {
			cnt++
		}
	}
	return cnt
}

func nextPermutation(ints []int) []int {
	var j int
	k := -1
	for i := len(ints) - 1; i >= 1; i-- {
		if ints[i] > ints[i-1] {
			k = i - 1
			break
		}
	}
	if k == -1 {
		for i := 0; i < len(ints)/2; i++ {
			ints[i], ints[len(ints)-i-1] = ints[len(ints)-i-1], ints[i]
		}
		return ints
	}
	for i := len(ints) - 1; i > k; i-- {
		if ints[i] > ints[k] {
			j = i
			break
		}
	}
	ints[k], ints[j] = ints[j], ints[k]
	for i := 1; i <= (len(ints)-k)/2; i++ {
		ints[k+i], ints[len(ints)-i] = ints[len(ints)-i], ints[k+i]
	}
	return ints
}

Submission

Task問題 C - コイン
User nameユーザ名 kozzy
Created time投稿日時
Language言語 Go (1.6)
Status状態 WA
Score得点 99
Source lengthソースコード長 1267 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt
Subtask1 99 / 99 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt,subtask1_20.txt
Subtask2 0 / 1 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt,subtask1_20.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt,subtask2_11.txt,subtask2_12.txt,subtask2_13.txt,subtask2_14.txt,subtask2_15.txt,subtask2_16.txt,subtask2_17.txt,subtask2_18.txt,subtask2_19.txt,subtask2_20.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 512 KB
sample_02.txt AC 1 ms 512 KB
sample_03.txt AC 1 ms 512 KB
subtask1_01.txt AC 1 ms 512 KB
subtask1_02.txt AC 1 ms 512 KB
subtask1_03.txt AC 1 ms 512 KB
subtask1_04.txt AC 20 ms 768 KB
subtask1_05.txt AC 21 ms 896 KB
subtask1_06.txt AC 4 ms 512 KB
subtask1_07.txt AC 18 ms 768 KB
subtask1_08.txt AC 1 ms 512 KB
subtask1_09.txt AC 1 ms 512 KB
subtask1_10.txt AC 21 ms 768 KB
subtask1_11.txt AC 1 ms 512 KB
subtask1_12.txt AC 18 ms 896 KB
subtask1_13.txt AC 1 ms 512 KB
subtask1_14.txt AC 3 ms 512 KB
subtask1_15.txt AC 23 ms 896 KB
subtask1_16.txt AC 18 ms 768 KB
subtask1_17.txt AC 25 ms 896 KB
subtask1_18.txt AC 25 ms 896 KB
subtask1_19.txt AC 22 ms 768 KB
subtask1_20.txt AC 22 ms 896 KB
subtask2_01.txt TLE
subtask2_02.txt TLE
subtask2_03.txt TLE
subtask2_04.txt WA
subtask2_05.txt AC 1 ms 512 KB
subtask2_06.txt AC 2 ms 512 KB
subtask2_07.txt AC 2 ms 512 KB
subtask2_08.txt AC 2 ms 512 KB
subtask2_09.txt AC 2 ms 512 KB
subtask2_10.txt AC 2 ms 512 KB
subtask2_11.txt AC 2 ms 512 KB
subtask2_12.txt AC 1 ms 512 KB
subtask2_13.txt WA
subtask2_14.txt AC 2 ms 512 KB
subtask2_15.txt AC 2 ms 512 KB
subtask2_16.txt AC 2 ms 512 KB
subtask2_17.txt AC 1 ms 512 KB
subtask2_18.txt WA
subtask2_19.txt AC 2 ms 512 KB
subtask2_20.txt AC 2 ms 512 KB