結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー simansiman
提出日時 2021-03-18 05:52:53
言語 Ruby
(3.3.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 375 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 11,500 KB
実行使用メモリ 34,648 KB
最終ジャッジ日時 2023-08-10 00:56:38
合計ジャッジ時間 9,288 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,108 KB
testcase_01 AC 80 ms
15,232 KB
testcase_02 AC 80 ms
15,304 KB
testcase_03 AC 78 ms
15,232 KB
testcase_04 AC 78 ms
15,080 KB
testcase_05 AC 78 ms
15,208 KB
testcase_06 AC 79 ms
15,232 KB
testcase_07 AC 78 ms
15,156 KB
testcase_08 AC 78 ms
15,244 KB
testcase_09 AC 80 ms
15,104 KB
testcase_10 AC 80 ms
15,132 KB
testcase_11 AC 79 ms
15,228 KB
testcase_12 AC 78 ms
15,128 KB
testcase_13 AC 78 ms
15,264 KB
testcase_14 AC 80 ms
15,296 KB
testcase_15 AC 79 ms
15,164 KB
testcase_16 AC 79 ms
15,004 KB
testcase_17 AC 79 ms
15,160 KB
testcase_18 AC 79 ms
15,136 KB
testcase_19 AC 79 ms
15,336 KB
testcase_20 AC 80 ms
15,112 KB
testcase_21 AC 79 ms
15,280 KB
testcase_22 AC 189 ms
32,596 KB
testcase_23 AC 108 ms
19,596 KB
testcase_24 AC 106 ms
18,176 KB
testcase_25 AC 192 ms
33,120 KB
testcase_26 AC 210 ms
34,188 KB
testcase_27 AC 206 ms
33,204 KB
testcase_28 AC 231 ms
34,320 KB
testcase_29 AC 124 ms
21,096 KB
testcase_30 AC 113 ms
19,656 KB
testcase_31 AC 230 ms
34,212 KB
testcase_32 AC 124 ms
21,020 KB
testcase_33 AC 84 ms
15,644 KB
testcase_34 AC 128 ms
21,112 KB
testcase_35 AC 227 ms
33,796 KB
testcase_36 AC 211 ms
30,032 KB
testcase_37 AC 106 ms
17,988 KB
testcase_38 AC 264 ms
34,272 KB
testcase_39 AC 87 ms
15,276 KB
testcase_40 AC 230 ms
32,788 KB
testcase_41 AC 131 ms
20,984 KB
testcase_42 AC 149 ms
21,728 KB
testcase_43 AC 87 ms
15,588 KB
testcase_44 AC 103 ms
17,920 KB
testcase_45 AC 264 ms
34,648 KB
testcase_46 AC 264 ms
34,456 KB
testcase_47 AC 264 ms
34,560 KB
testcase_48 AC 263 ms
34,568 KB
testcase_49 AC 264 ms
34,604 KB
testcase_50 AC 78 ms
15,132 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