結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー simansiman
提出日時 2021-03-18 05:52:53
言語 Ruby
(3.3.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 375 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 33,408 KB
最終ジャッジ日時 2024-04-27 18:52:49
合計ジャッジ時間 7,757 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
12,288 KB
testcase_01 AC 73 ms
12,288 KB
testcase_02 AC 74 ms
12,032 KB
testcase_03 AC 70 ms
12,288 KB
testcase_04 AC 70 ms
12,032 KB
testcase_05 AC 70 ms
12,032 KB
testcase_06 AC 70 ms
12,032 KB
testcase_07 AC 71 ms
12,160 KB
testcase_08 AC 72 ms
12,160 KB
testcase_09 AC 71 ms
12,032 KB
testcase_10 AC 71 ms
12,288 KB
testcase_11 AC 70 ms
12,288 KB
testcase_12 AC 69 ms
12,288 KB
testcase_13 AC 70 ms
12,288 KB
testcase_14 AC 72 ms
12,032 KB
testcase_15 AC 72 ms
12,288 KB
testcase_16 AC 72 ms
12,160 KB
testcase_17 AC 69 ms
12,032 KB
testcase_18 AC 70 ms
12,288 KB
testcase_19 AC 70 ms
12,032 KB
testcase_20 AC 70 ms
12,032 KB
testcase_21 AC 70 ms
12,032 KB
testcase_22 AC 173 ms
30,080 KB
testcase_23 AC 97 ms
16,256 KB
testcase_24 AC 91 ms
15,616 KB
testcase_25 AC 174 ms
30,976 KB
testcase_26 AC 189 ms
33,024 KB
testcase_27 AC 185 ms
31,488 KB
testcase_28 AC 208 ms
33,408 KB
testcase_29 AC 115 ms
19,072 KB
testcase_30 AC 101 ms
16,256 KB
testcase_31 AC 207 ms
33,024 KB
testcase_32 AC 108 ms
16,512 KB
testcase_33 AC 77 ms
12,672 KB
testcase_34 AC 117 ms
18,944 KB
testcase_35 AC 199 ms
32,640 KB
testcase_36 AC 184 ms
25,600 KB
testcase_37 AC 98 ms
14,848 KB
testcase_38 AC 251 ms
33,152 KB
testcase_39 AC 79 ms
12,672 KB
testcase_40 AC 211 ms
30,208 KB
testcase_41 AC 130 ms
18,944 KB
testcase_42 AC 138 ms
19,328 KB
testcase_43 AC 84 ms
12,672 KB
testcase_44 AC 92 ms
14,464 KB
testcase_45 AC 242 ms
33,152 KB
testcase_46 AC 237 ms
33,152 KB
testcase_47 AC 240 ms
33,152 KB
testcase_48 AC 239 ms
33,280 KB
testcase_49 AC 244 ms
33,152 KB
testcase_50 AC 72 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)
B = A.sort

if A.each_cons(2).count { |a, b| a > b } == 0
  puts 0
  exit
end

i = N - 1
while A[i] == B[i] && i >= 0
  i -= 1
end

C = A[0..i]
D = C.size
cnt = 0

D.times do |j|
  a = C[j]
  b = C[(j + 1) % D]
  cnt += 1 if a > b
end

m = (i == N - 1) ? A.max : A[i + 1..-1].max

if cnt == 1 && C.max <= m
  puts 1
else
  puts 2
end
0