結果

問題 No.1298 OR XOR
ユーザー ccppjsrbccppjsrb
提出日時 2020-11-27 21:28:51
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,768 bytes
コンパイル時間 15,859 ms
コンパイル使用メモリ 215,892 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-01 04:44:29
合計ジャッジ時間 17,108 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 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,376 KB
testcase_13 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func getNextString(scanner *bufio.Scanner) string {
	if !scanner.Scan() {
		panic("scan failed")
	}
	return scanner.Text()
}
func atoi(s string) int                             { x, _ := strconv.Atoi(s); return x }
func getNextInt(scanner *bufio.Scanner) int         { return atoi(getNextString(scanner)) }
func atoi64(s string) int64                         { x, _ := strconv.ParseInt(s, 10, 64); return x }
func getNextInt64(scanner *bufio.Scanner) int64     { return atoi64(getNextString(scanner)) }
func atof64(s string) float64                       { x, _ := strconv.ParseFloat(s, 64); return x }
func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	if bits.OnesCount(uint(n)) < 2 {
		fmt.Fprintln(writer, "-1 -1 -1")
		return
	}
	var (
		a, b, c int
	)
	x := 0
	for i := 0; i < 30; i++ {
		if n>>uint(i)&1 == 0 {
			continue
		}
		if x == 0 {
			a |= (1 << uint(i))
			b |= (1 << uint(i))
		} else {
			b |= (1 << uint(i))
			c |= (1 << uint(i))
		}
		x++
	}
	fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", a, b, c))
}
0