結果

問題 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  
実行時間 197 ms / 2,000 ms
+ 3µs
コード長 443 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 291 ms
コンパイル使用メモリ 21,280 KB
実行使用メモリ 15,740 KB
平均クエリ数 661.56
最終ジャッジ日時 2026-08-14 19:52:57
合計ジャッジ時間 3,661 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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