結果

問題 No.1 道のショートカット
ユーザー MiyamonYMiyamonY
提出日時 2019-09-09 18:25:00
言語 Scheme
(Gauche-0.9.14)
結果
WA  
実行時間 -
コード長 1,449 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 5,328 KB
実行使用メモリ 23,120 KB
最終ジャッジ日時 2023-09-22 13:36:48
合計ジャッジ時間 12,880 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
17,428 KB
testcase_01 AC 53 ms
17,416 KB
testcase_02 AC 53 ms
17,476 KB
testcase_03 AC 53 ms
17,376 KB
testcase_04 AC 54 ms
17,344 KB
testcase_05 AC 55 ms
17,304 KB
testcase_06 AC 54 ms
17,192 KB
testcase_07 AC 56 ms
17,304 KB
testcase_08 AC 796 ms
23,072 KB
testcase_09 AC 335 ms
22,980 KB
testcase_10 AC 265 ms
22,964 KB
testcase_11 AC 393 ms
22,940 KB
testcase_12 AC 1,034 ms
22,924 KB
testcase_13 AC 1,035 ms
23,036 KB
testcase_14 AC 108 ms
20,220 KB
testcase_15 AC 53 ms
17,264 KB
testcase_16 AC 142 ms
23,120 KB
testcase_17 AC 56 ms
17,680 KB
testcase_18 WA -
testcase_19 AC 103 ms
20,180 KB
testcase_20 AC 175 ms
23,060 KB
testcase_21 AC 149 ms
22,980 KB
testcase_22 AC 90 ms
20,168 KB
testcase_23 AC 855 ms
22,980 KB
testcase_24 AC 1,000 ms
23,096 KB
testcase_25 AC 286 ms
23,048 KB
testcase_26 AC 236 ms
23,028 KB
testcase_27 AC 742 ms
23,012 KB
testcase_28 AC 56 ms
17,692 KB
testcase_29 AC 170 ms
23,028 KB
testcase_30 AC 74 ms
20,092 KB
testcase_31 AC 151 ms
23,120 KB
testcase_32 WA -
testcase_33 AC 364 ms
23,120 KB
testcase_34 WA -
testcase_35 AC 66 ms
19,644 KB
testcase_36 WA -
testcase_37 AC 69 ms
19,924 KB
testcase_38 AC 60 ms
18,112 KB
testcase_39 AC 120 ms
21,712 KB
testcase_40 AC 68 ms
19,504 KB
testcase_41 AC 60 ms
18,136 KB
testcase_42 AC 53 ms
17,236 KB
testcase_43 AC 54 ms
19,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

(use gauche.array)
(use data.queue)

(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 q (make-queue))

  (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)
  (queue-push! q 1)
  (let loop ()
    (unless (queue-empty? q)
      (let1 from (dequeue! q)
	    (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)))
					(if (<= t (array-ref times to i))
					    (array-set! times to i t)))))
			    (iota (+ c 1)))
		  (unless (vector-ref visited to)
		    (enqueue! q to)
		    (vector-set! visited to #t)))
		(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