結果

問題 No.397 NO MORE KADOMATSU
ユーザー fmhrfmhr
提出日時 2016-07-16 00:00:49
言語 Go
(1.22.1)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,354 bytes
コンパイル時間 10,360 ms
コンパイル使用メモリ 207,380 KB
実行使用メモリ 24,360 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 00:18:21
合計ジャッジ時間 12,044 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,460 KB
testcase_01 AC 22 ms
23,664 KB
testcase_02 AC 21 ms
24,348 KB
testcase_03 AC 23 ms
24,048 KB
testcase_04 AC 22 ms
23,592 KB
testcase_05 AC 24 ms
24,324 KB
testcase_06 AC 25 ms
24,360 KB
testcase_07 AC 26 ms
23,352 KB
testcase_08 AC 27 ms
23,892 KB
testcase_09 AC 25 ms
23,880 KB
testcase_10 AC 58 ms
23,364 KB
testcase_11 AC 23 ms
24,096 KB
testcase_12 AC 29 ms
23,784 KB
testcase_13 AC 35 ms
24,036 KB
testcase_14 AC 37 ms
23,436 KB
testcase_15 AC 35 ms
23,868 KB
testcase_16 AC 21 ms
24,060 KB
testcase_17 AC 21 ms
23,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"sort"
)

func bubble() {
	ans := make([]int, 0, 10000)
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i := 0; i < n; i++ {
		for j := 1; j < n-i; j++ {
			//fmt.Println(i, j)
			if a[j] < a[j-1] {
				sort.IntSlice(a).Swap(j, j-1)
				ans = append(ans, j)
				ans = append(ans, j-1)
			}
		}
	}
	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 main() {
	bubble()
	//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, 10000)
	//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