結果
| 問題 |
No.152 貯金箱の消失
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-07-07 05:29:21 |
| 言語 | Scheme (Gauche-0.9.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 4,426 bytes |
| コンパイル時間 | 416 ms |
| コンパイル使用メモリ | 8,352 KB |
| 実行使用メモリ | 52,668 KB |
| 最終ジャッジ日時 | 2025-07-07 05:29:37 |
| 合計ジャッジ時間 | 15,795 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 TLE * 1 -- * 5 |
ソースコード
(use util.match)
(use srfi.13) ; string
(use srfi.42) ; list-ec
(use srfi.197) ; chain
(use gauche.collection)
(use gauche.dictionary)
(use gauche.generator)
(use gauche.sequence)
(use scheme.list)
(use scheme.set)
(define input read-line)
(define (ii)
(string->number (read-line)))
(define (li)
(let ((s (read-line)))
(map string->number (string-split s " "))))
(define (prn . args)
(for-each-with-index (lambda (i x)
(when (> i 0)
(display " "))
(display x))
args)
(newline))
(define prn* (pa$ apply prn))
(define int string->number)
(define str x->string)
(define-method min ((xs <sequence>))
(fold min (~ xs 0) xs))
(define-method max ((xs <sequence>))
(fold max (~ xs 0) xs))
(define (minmax . xs)
(values->list (apply min&max xs)))
(define-method minmax ((xs <sequence>))
(values->list (apply min&max xs)))
(define (sum xs)
(fold + 0 xs))
(define (divmod a b)
(values->list (div-and-mod a b)))
(define (1+ n) (+ n 1))
(define (1- n) (- n 1))
(define (!= a b) (not (= a b)))
(define pow
(case-lambda
((a b) (expt a b))
((a b m) (expt-mod a b m))))
(define gcd* (apply$ gcd))
(define isqrt exact-integer-sqrt)
(define ++ string-append)
(define zip (map$ list))
(define (pairwise xs)
(zip xs (cdr xs)))
(define (comb n k)
(if (or (< k 0) (> k n))
0
(let loop ((i 0)
(x 1))
(if (= i k)
x
(loop (1+ i) (div (* x (- n i)) (1+ i)))))))
(define-method frequencies ((xs <sequence>))
(rlet1 ht (make-hash-table eqv-comparator)
(for-each (^x (hash-table-update! ht x 1+ 0))
xs)))
(define (yn b)
(prn (if b "Yes" "No")))
(define-macro (input! bindings . body)
(let loop ((bs (reverse bindings))
(res '()))
(if (null? bs)
`(let*-values ,res
,@body)
(cond
((symbol? (car bs))
(loop (cdr bs)
(cons `((,(car bs)) (values (ii)))
res)))
((list? (car bs))
(loop (cdr bs)
(cons `(,(car bs) (apply values (li)))
res)))
(else
'error)))))
(define mlet1 match-let1)
(define-macro (mfn pat . body)
(let ((arg (gensym)))
`(lambda (,arg)
(mlet1 ,pat ,arg
,@body))))
(define-syntax count-ec
(syntax-rules ()
((_ qualifiers ...)
(sum-ec qualifiers ... 1))))
(define (len obj)
(cond
((list? obj) (length obj))
((string? obj) (string-length obj))
(else
(assume #f))))
(define (accum xs)
(define (proc a b)
(let1 t (+ a b)
(values t t)))
(map-accum proc 0 xs))
(define (digits n)
(map digit->integer (str n)))
(define (-> x . fns)
(call-with-values (^() (values x))
(apply compose (reverse fns))))
(define (rep n thunk)
(list-tabulate n (^i (thunk))))
(define (zip-longest . args)
(let* ((n (apply max (map length args)))
(xxs (map (^(xs)
(append xs (make-list (- n (length xs)) #f)))
args)))
(map (pa$ delete #f)
(apply zip xxs))))
(define (set-from xs)
(apply set eqv-comparator xs))
(define (difference xs ys)
(let ((excludes (set-from ys)))
(filter (^x (not (set-contains? excludes x))) xs)))
(use data.heap)
(use data.queue)
(use gauche.array)
(define ma (array (shape 0 3 0 3)
1 -2 2
2 -1 2
2 -2 3))
(define mb (array (shape 0 3 0 3)
1 2 2
2 1 2
2 2 3))
(define mc (array (shape 0 3 0 3)
-1 2 2
-2 1 2
-2 2 3))
(define (pythagorean-triples limit)
(generate
(^(yield)
(let ((q (make-queue)))
(enqueue! q (array (shape 0 3 0 1) 3 4 5))
(while (not (queue-empty? q))
(let ((a (dequeue! q)))
(yield (array->list a))
(dolist (m (list ma mb mc))
(let ((b (array-mul m a)))
(when (<= (+ (array-ref b 0 0)
(array-ref b 1 0)
(array-ref b 2 0))
limit)
(enqueue! q b))))))))))
(input! (L)
(let ((g (pythagorean-triples L)))
(->
(count-ec (:generator a g)
(if (<= (* 4 (sum a)) L)))
prn)))
norioc