結果

問題 No.2374 ASKT Subsequences
ユーザー KowerKoint2010KowerKoint2010
提出日時 2023-06-28 17:39:24
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,585 ms / 2,000 ms
コード長 407 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 11,472 KB
実行使用メモリ 70,488 KB
最終ジャッジ日時 2023-09-18 21:42:01
合計ジャッジ時間 13,725 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,020 KB
testcase_01 AC 81 ms
15,108 KB
testcase_02 AC 82 ms
15,296 KB
testcase_03 AC 81 ms
15,364 KB
testcase_04 AC 81 ms
15,416 KB
testcase_05 AC 79 ms
15,456 KB
testcase_06 AC 80 ms
15,356 KB
testcase_07 AC 93 ms
21,880 KB
testcase_08 AC 91 ms
22,628 KB
testcase_09 AC 92 ms
22,676 KB
testcase_10 AC 136 ms
38,828 KB
testcase_11 AC 135 ms
23,116 KB
testcase_12 AC 116 ms
22,744 KB
testcase_13 AC 112 ms
23,196 KB
testcase_14 AC 151 ms
23,224 KB
testcase_15 AC 167 ms
23,040 KB
testcase_16 AC 141 ms
23,028 KB
testcase_17 AC 307 ms
34,364 KB
testcase_18 AC 415 ms
31,856 KB
testcase_19 AC 393 ms
32,412 KB
testcase_20 AC 1,008 ms
70,388 KB
testcase_21 AC 1,103 ms
70,420 KB
testcase_22 AC 859 ms
70,488 KB
testcase_23 AC 428 ms
31,896 KB
testcase_24 AC 416 ms
31,748 KB
testcase_25 AC 87 ms
15,316 KB
testcase_26 AC 1,429 ms
70,284 KB
testcase_27 AC 1,585 ms
70,484 KB
testcase_28 AC 101 ms
15,024 KB
testcase_29 AC 1,377 ms
70,256 KB
testcase_30 AC 449 ms
29,104 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
a = gets.split.map(&:to_i)
ans = 0
max_a = a.max
1.upto(max_a) do |k|
  dp = Array.new(4) { Array.new(max_a+1, 0) }
  n.times do |i|
    if a[i]-k-1 >= 0 
      dp[3][a[i]] += dp[2][a[i]-k-1]
    end
    if a[i]+k <= max_a
      dp[2][a[i]] += dp[1][a[i]+k]
    end
    if a[i]-k-10 >= 0
      dp[1][a[i]] += dp[0][a[i]-k-10]
    end
    dp[0][a[i]] += 1
  end
  ans += dp[3].sum
end
puts ans
0