結果

問題 No.397 NO MORE KADOMATSU
ユーザー fmhrfmhr
提出日時 2016-07-15 23:46:29
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 701 bytes
コンパイル時間 11,022 ms
コンパイル使用メモリ 203,252 KB
実行使用メモリ 826,344 KB
平均クエリ数 1.06
最終ジャッジ日時 2023-09-23 11:07:58
合計ジャッジ時間 15,763 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 23 ms
24,000 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"math/rand"
	"sort"
)

func main() {
	rand.Seed(42)
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	ans := make([]int, 0)
	for !allNotKadomatsu(a) {
		b := rand.Int()%(n)
		c := rand.Int()%(n)
		sort.IntSlice(a).Swap(b, c)
		ans = append(ans, b)
		ans = append(ans, c)
	}
	fmt.Println(len(ans)/2)
	for i := 0; i < len(ans) / 2; i++ {
		fmt.Println(ans[i*2], ans[i*2+1])
	}
}

func allNotKadomatsu(a []int)bool{
	l := len(a)
	for i:=0;i<l-2;i++{
		if isKadomatsu(a[i],a[i+1],a[i+2]){
			return false
		}
	}
	return true
}

func isKadomatsu(a, b, c int)bool{
	if (b>a && b>c) || (b<a && b<c) {
		return true
	}
	return false
}
0