結果

問題 No.1438 Broken Drawers
ユーザー masashi0217masashi0217
提出日時 2021-04-04 06:19:53
言語 Ruby
(3.2.2)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 982 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 11,524 KB
実行使用メモリ 33,844 KB
最終ジャッジ日時 2023-08-27 01:32:22
合計ジャッジ時間 6,503 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,092 KB
testcase_01 AC 84 ms
15,216 KB
testcase_02 AC 83 ms
15,124 KB
testcase_03 AC 84 ms
15,216 KB
testcase_04 AC 85 ms
14,984 KB
testcase_05 AC 85 ms
15,268 KB
testcase_06 AC 210 ms
33,844 KB
testcase_07 AC 221 ms
32,992 KB
testcase_08 AC 84 ms
15,124 KB
testcase_09 AC 83 ms
15,160 KB
testcase_10 AC 83 ms
15,284 KB
testcase_11 AC 89 ms
15,288 KB
testcase_12 AC 138 ms
21,000 KB
testcase_13 AC 170 ms
26,024 KB
testcase_14 AC 122 ms
20,320 KB
testcase_15 AC 216 ms
32,448 KB
testcase_16 AC 210 ms
32,324 KB
testcase_17 AC 219 ms
32,916 KB
testcase_18 AC 217 ms
32,868 KB
testcase_19 AC 218 ms
32,916 KB
testcase_20 AC 217 ms
32,988 KB
testcase_21 AC 216 ms
32,800 KB
testcase_22 AC 220 ms
33,200 KB
testcase_23 AC 221 ms
33,256 KB
testcase_24 AC 223 ms
33,128 KB
testcase_25 AC 223 ms
33,112 KB
testcase_26 AC 227 ms
33,076 KB
testcase_27 AC 222 ms
33,304 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
tmp = []
if n == 1
    puts "1"
    exit
end
0.upto(n-2) do |j|
    if a[j] < a[j+1]
        if tmp == []
            tmp << j
            tmp << j + 1
        elsif a[j-1] < a[j]
             tmp << j + 1
        elsif a[j-1] > a[j]
            if tmp[-1] == j-1
                tmp << j + 1
            elsif tmp[-1] == j
                tmp << j + 1
            else
                tmp << j
                tmp << j + 1
            end
        end
    else
        if tmp == []
            tmp << j
        elsif a[j-1] < a[j]
            if tmp[-1] == j - 1
                tmp << j + 1
            elsif tmp[-1] != j
                tmp << j
            end
        elsif a[j-1] > a[j]
            if tmp[-1] == j - 1
                tmp << j + 1
            elsif tmp[-1] != j
                tmp << j
            end
        end
    end
end
puts tmp.count
# arr = []
# tmp.each do |k|
#     arr << a[k]
# end
# p arr
0