結果

問題 No.443 GCD of Permutation
ユーザー 💕💖💞💕💖💞
提出日時 2016-11-19 22:32:49
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 1,322 bytes
コンパイル時間 13,602 ms
コンパイル使用メモリ 206,228 KB
実行使用メモリ 68,236 KB
最終ジャッジ日時 2023-08-18 03:48:14
合計ジャッジ時間 16,149 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,764 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 24 ms
10,048 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
)

func Iter(p []rune) func() int {
	f := pf(len(p))
	return func() int {
		return f(p)
	}
}

// Recursive function used by perm, returns a chain of closures that
// implement a loopless recursive SJT.
func pf(n int) func([]rune) int {
	sign := 1
	switch n {
	case 0, 1:
		return func([]rune) (s int) {
			s = sign
			sign = 0
			return
		}
	default:
		p0 := pf(n - 1)
		i := n
		var d int
		return func(p []rune) int {
			switch {
			case sign == 0:
			case i == n:
				i--
				sign = p0(p[:i])
				d = -1
			case i == 0:
				i++
				sign *= p0(p[1:])
				d = 1
				if sign == 0 {
					p[0], p[1] = p[1], p[0]
				}
			default:
				p[i], p[i-1] = p[i-1], p[i]
				sign = -sign
				i += d
			}
			return sign
		}
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	th := 0
	lines := []string{}
	for scanner.Scan() {
		th += 1
		text := scanner.Text()
		lines = append(lines, text)
		if th == 1 {
			break
		}
	}
	target := lines[0]
	runes := []rune(target)
	i := Iter(runes)
	ns := []big.Int{}
	for sign := i(); sign != 0; sign = i() {
		//fmt.Println(string(runes))
		n := *big.NewInt(0)
		n.SetString(string(runes), 10)
		ns = append(ns, n)
	}
	n_tmp := ns[0]
	for _, n_adhoc := range ns {
		n_tmp.GCD(nil, nil, &n_tmp, &n_adhoc)
	}
	fmt.Println(&n_tmp)
}
0