結果
| 問題 | 
                            No.1645 AB's abs
                             | 
                    
| コンテスト | |
| ユーザー | 
                             n_get
                         | 
                    
| 提出日時 | 2021-08-13 22:20:46 | 
| 言語 | Scheme  (Gauche-0.9.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 135 ms / 2,000 ms | 
| コード長 | 912 bytes | 
| コンパイル時間 | 298 ms | 
| コンパイル使用メモリ | 6,820 KB | 
| 実行使用メモリ | 21,120 KB | 
| 最終ジャッジ日時 | 2024-10-03 19:49:59 | 
| 合計ジャッジ時間 | 4,580 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 36 | 
ソースコード
(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))]))
            
            
            
        
            
n_get