結果

問題 No.225 文字列変更(medium)
コンテスト
ユーザー Common Lisp
提出日時 2024-11-06 10:14:02
言語 Common Lisp
(sbcl 2.6.7)
コンパイル:
sbclc _filename_
実行:
sbcl --script Main.fasl
結果
AC  
実行時間 19 ms / 5,000 ms
+ 611µs
コード長 739 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,135 ms
コンパイル使用メモリ 41,908 KB
実行使用メモリ 44,656 KB
最終ジャッジ日時 2026-09-19 15:53:31
合計ジャッジ時間 2,992 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 19 SEP 2026 03:53:28 PM):

; wrote /home/judge/data/code/Main.fasl
; compilation finished in 0:00:00.109

ソースコード

diff #
raw source code

(defun LevenshteinDistance (s1 s2)
  (let ((dp (make-array '(2048 2048)))
        (n (length s1))
        (m (length s2)))
    (dotimes (i (1+ n)) (setf (aref dp i 0) i))
    (dotimes (i (1+ m)) (setf (aref dp 0 i) i))
    (dotimes (i n)
      (dotimes (j m)
        (setf (aref dp (1+ i) (1+ j)) (1+ (min (aref dp i (1+ j)) (aref dp (1+ i) j)))
              (aref dp (1+ i) (1+ j)) (min (aref dp (1+ i) (1+ j)) (+ (aref dp i j) (if (char= (char s1 i) (char s2 j)) 0 1))))))
    (aref dp n m)))

(defun main (&rest argv)
  (declare (ignorable argv))
  (let* ((n (read))
         (m (read))
         (s1 (read-line))
         (s2 (read-line)))
    (declare (ignore n) (ignore m))
    (format t "~d~%" (LevenshteinDistance s1 s2))))

(main)
0