結果

問題 No.4 おもりと天秤
ユーザー ccppjsrbccppjsrb
提出日時 2020-06-03 17:50:57
言語 Go
(1.21.3)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,332 bytes
コンパイル時間 14,923 ms
コンパイル使用メモリ 205,464 KB
実行使用メモリ 5,480 KB
最終ジャッジ日時 2023-08-16 15:56:00
合計ジャッジ時間 15,131 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	geta := 10000
	b := newBint(0)
	b.x.SetBit(b.x, geta, 1)
	for i := 0; i < n; i++ {
		w := getNextInt(scanner)
		b = b.lsh(w).or(b.rsh(w))
	}
	if b.x.Bit(geta) == 1 {
		fmt.Fprintln(writer, "possible")
		return
	}
	fmt.Fprintln(writer, "impossible")
}

type bint struct {
	x *big.Int
}

func newBint(x int64) *bint {
	return &bint{x: big.NewInt(x)}
}
func (x *bint) add(y *bint) *bint {
	z := newBint(0)
	z.x.Add(x.x, y.x)
	return z
}
func (x *bint) sub(y *bint) *bint {
	z := newBint(0)
	z.x.Sub(x.x, y.x)
	return z
}
func (x *bint) mul(y *bint) *bint {
	z := newBint(0)
	z.x.Mul(x.x, y.x)
	return z
}
func (x *bint) div(y *bint) *bint {
	z := newBint(0)
	z.x.Div(x.x, y.x)
	return z
}
func (x *bint) lsh(n int) *bint {
	z := newBint(0)
	z.x.Lsh(x.x, uint(n))
	return z
}
func (x *bint) rsh(n int) *bint {
	z := newBint(0)
	z.x.Rsh(x.x, uint(n))
	return z
}
func (x *bint) or(y *bint) *bint {
	z := newBint(0)
	z.x.Or(x.x, y.x)
	return z
}
0