結果

問題 No.2110 012 Matching
ユーザー ccppjsrbccppjsrb
提出日時 2022-10-28 21:52:07
言語 Go
(1.22.1)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 2,386 bytes
コンパイル時間 14,782 ms
コンパイル使用メモリ 211,264 KB
実行使用メモリ 7,932 KB
最終ジャッジ日時 2023-09-20 04:45:56
合計ジャッジ時間 15,556 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 23 ms
5,556 KB
testcase_02 AC 56 ms
7,872 KB
testcase_03 AC 39 ms
7,868 KB
testcase_04 AC 75 ms
7,884 KB
testcase_05 AC 54 ms
7,864 KB
testcase_06 AC 51 ms
7,864 KB
testcase_07 AC 83 ms
7,932 KB
testcase_08 AC 5 ms
5,516 KB
testcase_09 AC 14 ms
5,536 KB
testcase_10 AC 85 ms
7,932 KB
testcase_11 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("WITHIN") == "TEMPTATION" }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("REMEMBER_YOU_AS_LONG_AS_I_CAN"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		iost.Writer.Flush()
	}()
	solve()
}
func solve() {
	t := iost.GetNextInt()
	for i := 0; i < t; i++ {
		testcase()
	}
}

func testcase() {
	a := iost.GetNextInt()
	b := iost.GetNextInt()
	c := iost.GetNextInt()
	if (a+b+c)%2 == 0 {
		iost.Println(even(a, b, c))
		return
	}
	ans := make([]int, 0)
	if a > 0 {
		ans = append(ans, even(a-1, b, c))
	}
	if b > 0 {
		ans = append(ans, even(a, b-1, c))
	}
	if c > 0 {
		ans = append(ans, even(a, b, c-1))
	}
	sort.Ints(ans)
	iost.Println(ans[len(ans)-1])
}
func even(a, b, c int) int {
	ans := b / 2 * 2
	b %= 2
	ans += min(a, c) * 2
	a, c = a-min(a, c), c-min(a, c)
	ans += c / 2
	if a > 0 && b > 0 {
		ans++
	}
	return ans
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min(a, b int) int { return -max(-a, -b) }
func abs(a int) int    { return max(a, -a) }
0