結果

問題 No.397 NO MORE KADOMATSU
ユーザー fmhrfmhr
提出日時 2016-07-15 23:50:53
言語 Go
(1.22.1)
結果
MLE  
実行時間 -
コード長 800 bytes
コンパイル時間 10,655 ms
コンパイル使用メモリ 215,972 KB
実行使用メモリ 822,072 KB
平均クエリ数 0.28
最終ジャッジ日時 2023-09-23 11:07:32
合計ジャッジ時間 15,180 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,604 KB
testcase_01 AC 24 ms
23,388 KB
testcase_02 AC 24 ms
24,396 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(32423)
	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)
		for b==c{
			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])
	}
	var dummy string
	fmt.Scan(&dummy)
}

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