結果

問題 No.1 道のショートカット
ユーザー MiyamonYMiyamonY
提出日時 2019-09-10 13:06:08
言語 Scheme
(Gauche-0.9.14)
結果
TLE  
実行時間 -
コード長 1,574 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 29,556 KB
最終ジャッジ日時 2023-09-22 13:36:05
合計ジャッジ時間 7,228 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
19,644 KB
testcase_01 AC 69 ms
19,676 KB
testcase_02 AC 73 ms
19,624 KB
testcase_03 AC 70 ms
19,692 KB
testcase_04 AC 67 ms
19,556 KB
testcase_05 AC 68 ms
19,768 KB
testcase_06 AC 67 ms
19,716 KB
testcase_07 AC 71 ms
19,884 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

(use gauche.array)
(use data.heap)

(define (read-number)
  (string->number (read-line)))

(define (read-numbers)
  (map string->number (string-split (read-line) #\space)))

(let* ((n (read-number))
       (c (read-number))
       (v (read-number))
       (s (read-numbers))
       (t (read-numbers))
       (y (read-numbers))
       (m (read-numbers)))

  (define graph (make-vector (+ n 1) '()))
  (define visited (make-vector (+ n 1) #f))
  (define times (make-array (shape 0 (+ n 1) 0 (+ c 1)) (ash 1 30)))
  (define heap (make-binary-heap :key cdr))

  (for-each
   (lambda (x y z w)
     (vector-set! graph x (cons (cons y (cons z w)) (vector-ref graph x  '()))))
   s t y m)

  (array-set! times 1 0 0)
  (binary-heap-push! heap (cons 1 0))

  (let loop ()
    (unless (binary-heap-empty? heap)
      (let* ((h (binary-heap-pop-min! heap))
	     (from (car h))
	     (weight (cdr h)))
	(vector-set! visited from #t)
	(let inner ((nodes (vector-ref graph from)))
	  (unless (null? nodes)
	    (let* ((node (car nodes))
		   (to (car node))
		   (cost (cadr node))
		   (time (cddr node)))
	      (for-each (lambda (i)
			  (if (>= (- i cost) 0)
			      (let1 t (+ time (array-ref times from (- i cost)))
				    (when (<= t (array-ref times to i))
				      (array-set! times to i t)))))
			(iota (+ c 1)))
	      (unless (vector-ref visited to)
		(binary-heap-push! heap (cons to (+ weight time)))))
	    (inner (cdr nodes)))))
      (loop)))

  (let1 val (apply min (map (lambda (i) (array-ref times n i)) (iota (+ c 1))))
	(print (if (= val (ash 1 30)) -1 val))))
0