結果

問題 No.1645 AB's abs
ユーザー n_getn_get
提出日時 2021-08-13 22:20:46
言語 Scheme
(Gauche-0.9.14)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 6,940 KB
実行使用メモリ 21,120 KB
最終ジャッジ日時 2024-04-14 18:32:17
合計ジャッジ時間 5,426 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
16,256 KB
testcase_01 AC 26 ms
16,256 KB
testcase_02 AC 31 ms
16,896 KB
testcase_03 AC 27 ms
16,256 KB
testcase_04 AC 27 ms
16,128 KB
testcase_05 AC 26 ms
16,384 KB
testcase_06 AC 27 ms
16,384 KB
testcase_07 AC 27 ms
16,256 KB
testcase_08 AC 35 ms
17,152 KB
testcase_09 AC 36 ms
17,280 KB
testcase_10 AC 34 ms
16,768 KB
testcase_11 AC 36 ms
16,896 KB
testcase_12 AC 35 ms
17,024 KB
testcase_13 AC 104 ms
21,120 KB
testcase_14 AC 83 ms
20,352 KB
testcase_15 AC 110 ms
20,992 KB
testcase_16 AC 104 ms
21,120 KB
testcase_17 AC 111 ms
20,992 KB
testcase_18 AC 99 ms
21,120 KB
testcase_19 AC 110 ms
20,992 KB
testcase_20 AC 84 ms
20,352 KB
testcase_21 AC 87 ms
20,864 KB
testcase_22 AC 110 ms
21,120 KB
testcase_23 AC 106 ms
21,120 KB
testcase_24 AC 106 ms
20,992 KB
testcase_25 AC 110 ms
21,120 KB
testcase_26 AC 107 ms
20,992 KB
testcase_27 AC 111 ms
20,992 KB
testcase_28 AC 111 ms
20,864 KB
testcase_29 AC 104 ms
20,992 KB
testcase_30 AC 115 ms
20,992 KB
testcase_31 AC 105 ms
20,992 KB
testcase_32 AC 108 ms
20,864 KB
testcase_33 AC 154 ms
20,992 KB
testcase_34 AC 153 ms
21,120 KB
testcase_35 AC 152 ms
20,992 KB
testcase_36 AC 154 ms
21,120 KB
testcase_37 AC 153 ms
20,992 KB
testcase_38 AC 28 ms
16,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

(use srfi-1)
(define N (read))
(define A (list-tabulate N (^_ (read))))


(define (memorize f)
  (let ([cache (make-hash-table equal-comparator)])
    (lambda x
      (or (hash-table-get cache x #f)
          (let ([result (apply f x)])
            (hash-table-put! cache x result)
            result)))))

(let loop ([A A] [ht (hash-table-r7 'eqv? 0 1)])
  (cond
   [(null? A) (print (hash-table-fold ht (^(k v s) (remainder (+ s (*  k v)) 998244353)) 0))]
   [else
    (let ([nxt (make-hash-table)])
      (hash-table-for-each ht (^(k v)
                                (let ([a (remainder (+ k (car A)) 998244353)]
                                      [b (remainder (abs (- k (car A))) 998244353)])
                                  (hash-table-put! nxt a (+ v (hash-table-get nxt a 0)))
                                  (hash-table-put! nxt b (+ v (hash-table-get nxt b 0))))))
      (loop (cdr A) nxt))]))
0