結果

問題 No.397 NO MORE KADOMATSU
コンテスト
ユーザー tookunn_1213
提出日時 2016-07-15 23:30:02
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 443 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 607 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 34,316 KB
平均クエリ数 661.56
最終ジャッジ日時 2026-03-31 14:39:53
合計ジャッジ時間 3,476 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
N = int(input())
A = [int(i) for i in input().split()]
sys.stdout.flush()
def isKadomatsu(a):
	for i in range(1,len(a) - 1):
		if a[i - 1] < a[i] > a[i + 1] or a[i - 1] > a[i] < a[i + 1]:
			return True
	return False
ans = []
while isKadomatsu(A):
	i = 1
	while i < len(A):
		if A[i - 1] > A[i]:
			ans.append((i - 1,i))
			A[i - 1],A[i] = A[i],A[i - 1]
		i += 1
print(len(ans))
for i in ans:
	u,v = i
	print(u,v)
sys.stdout.flush()
0