結果

問題 No.1017 Reiwa Sequence
ユーザー aru aruaru aru
提出日時 2020-10-31 21:15:39
言語 Go
(1.22.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,010 bytes
コンパイル時間 10,646 ms
コンパイル使用メモリ 214,056 KB
実行使用メモリ 246,220 KB
最終ジャッジ日時 2023-09-29 10:45:29
合計ジャッジ時間 53,900 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 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 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 299 ms
54,132 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1,993 ms
233,660 KB
testcase_13 TLE -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 11 ms
5,112 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 528 ms
90,228 KB
testcase_20 AC 508 ms
90,236 KB
testcase_21 AC 518 ms
90,228 KB
testcase_22 AC 515 ms
90,220 KB
testcase_23 AC 512 ms
90,240 KB
testcase_24 AC 509 ms
88,180 KB
testcase_25 AC 516 ms
90,220 KB
testcase_26 AC 514 ms
88,168 KB
testcase_27 AC 475 ms
88,168 KB
testcase_28 AC 472 ms
90,212 KB
testcase_29 AC 469 ms
88,140 KB
testcase_30 AC 460 ms
90,136 KB
testcase_31 AC 458 ms
89,996 KB
testcase_32 AC 455 ms
89,856 KB
testcase_33 AC 341 ms
56,228 KB
testcase_34 AC 328 ms
58,288 KB
testcase_35 AC 308 ms
58,296 KB
testcase_36 AC 315 ms
56,220 KB
testcase_37 AC 465 ms
89,788 KB
testcase_38 AC 466 ms
89,788 KB
testcase_39 AC 481 ms
87,744 KB
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 AC 572 ms
67,008 KB
testcase_45 TLE -
testcase_46 TLE -
testcase_47 AC 1,985 ms
229,476 KB
testcase_48 AC 1,856 ms
160,256 KB
testcase_49 AC 568 ms
66,736 KB
testcase_50 AC 554 ms
74,904 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 505 ms
90,232 KB
testcase_53 AC 481 ms
90,224 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)
	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)
	}

	v := make([]int, 0)
	for i := range m {
		v = append(v, i)
	}
	sort.Ints(v)

	for _, i := range v {
		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