結果

問題 No.1017 Reiwa Sequence
ユーザー aru aruaru aru
提出日時 2020-10-31 21:11:50
言語 Go
(1.22.1)
結果
AC  
実行時間 1,825 ms / 2,000 ms
コード長 1,966 bytes
コンパイル時間 10,578 ms
コンパイル使用メモリ 209,764 KB
実行使用メモリ 205,868 KB
最終ジャッジ日時 2023-09-29 10:41:16
合計ジャッジ時間 49,816 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 5 ms
4,384 KB
testcase_10 AC 243 ms
41,760 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 1,774 ms
200,316 KB
testcase_13 AC 1,825 ms
205,868 KB
testcase_14 AC 12 ms
4,500 KB
testcase_15 AC 16 ms
4,380 KB
testcase_16 AC 19 ms
4,380 KB
testcase_17 AC 31 ms
4,576 KB
testcase_18 AC 17 ms
4,376 KB
testcase_19 AC 529 ms
78,000 KB
testcase_20 AC 503 ms
77,976 KB
testcase_21 AC 538 ms
77,988 KB
testcase_22 AC 525 ms
78,012 KB
testcase_23 AC 543 ms
77,996 KB
testcase_24 AC 534 ms
77,992 KB
testcase_25 AC 526 ms
77,464 KB
testcase_26 AC 522 ms
77,996 KB
testcase_27 AC 389 ms
77,992 KB
testcase_28 AC 384 ms
77,964 KB
testcase_29 AC 371 ms
77,932 KB
testcase_30 AC 365 ms
77,916 KB
testcase_31 AC 364 ms
77,756 KB
testcase_32 AC 365 ms
77,608 KB
testcase_33 AC 259 ms
41,756 KB
testcase_34 AC 249 ms
41,236 KB
testcase_35 AC 224 ms
41,760 KB
testcase_36 AC 239 ms
41,748 KB
testcase_37 AC 342 ms
77,556 KB
testcase_38 AC 344 ms
77,052 KB
testcase_39 AC 355 ms
77,524 KB
testcase_40 AC 1,786 ms
191,320 KB
testcase_41 AC 1,754 ms
190,908 KB
testcase_42 AC 1,790 ms
194,124 KB
testcase_43 AC 1,764 ms
191,176 KB
testcase_44 AC 578 ms
66,984 KB
testcase_45 AC 1,721 ms
190,664 KB
testcase_46 AC 1,740 ms
188,464 KB
testcase_47 AC 1,658 ms
187,816 KB
testcase_48 AC 1,578 ms
141,484 KB
testcase_49 AC 560 ms
68,788 KB
testcase_50 AC 559 ms
76,992 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 423 ms
77,984 KB
testcase_53 AC 416 ms
78,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	N := getI()
	a := getInts(N)

	n := min(N, 22)
	m := make(map[int][]int)
	ma := 0
	for i := 0; i < 1<<n; i++ {
		tot := 0
		for k := 0; k < n; k++ {
			if (i>>k)&1 == 1 {
				tot += a[k]
			}
		}
		m[tot] = append(m[tot], i)
		ma = max(ma, tot)
	}

	for i := 0; i <= ma; i++ {
		if len(m[i]) > 1 {
			plus := m[i][0]
			minus := m[i][1]
			out("Yes")
			for k := 0; k < n; k++ {
				if (plus>>k)&1 == 1 {
					fmt.Fprint(wr, a[k], " ")
					continue
				}
				if (minus>>k)&1 == 1 {
					fmt.Fprint(wr, -a[k], " ")
					continue
				}
				fmt.Fprint(wr, 0, " ")
			}
			for k := n; k < N; k++ {
				fmt.Fprint(wr, 0, " ")
			}
			out()
			return
		}
	}
	out("No")
}
0