結果

問題 No.1034 テスターのふっぴーさん
ユーザー ccppjsrbccppjsrb
提出日時 2020-05-12 23:56:13
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,072 bytes
コンパイル時間 16,330 ms
コンパイル使用メモリ 200,524 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-12 03:45:52
合計ジャッジ時間 14,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"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 = 0
	}
	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) {
	q := getNextInt(scanner)
	for i := 0; i < q; i++ {
		n := getNextInt(scanner)
		y := getNextInt(scanner)
		x := getNextInt(scanner)
		dd := make([]int, 4)
		dd[0] = y
		dd[1] = n - 1 - x
		dd[2] = n - 1 - y
		dd[3] = x
		m := 3
		for j := 4 - 1; j >= 0; j-- {
			if dd[j] <= dd[m] {
				m = j
			}
		}
		ans := around(dd[m], n)
		l := line(dd[m], n)
		switch m {
		case 0:
			ans += int64(x - dd[m])
		case 1:
			ans += int64(y-dd[m]) + (l - 1)
		case 2:
			ans += int64(n-(x+1+dd[m])) + (l-1)*2
		case 3:
			ans += int64(n-(y+1+dd[m])) + (l-1)*3
		}
		fmt.Fprintln(writer, ans)
	}
}

func line(x, n int) int64 {
	return int64(n - x*2)
}
func around(x, n int) int64 {
	return int64(n-1+(n-1-(x-1)*2)) * int64(x) * 2
}
0