JOI2014/2015予選 不参加記
予選前日まで登録できるだろうと思ってたら終わってました.なので,ゆるふわに深夜からやってました.
練習のためにそれぞれ
で解こうと思ってましたがダメでした.
以下,残念なコード群です.
1問目 (Factor)
1時間ぐらいかかりました.
"ファイル名" utf8 file-lines [ string>number ] map set-datastack swapd 2dup <= [ dup -rot swap - swapd * swapd + ] [ 2nip swap ] if -rot * min
2問目 (Common Lisp)
もろ写しの関数は消しています.
(defun repeat (x y) (if (zerop x) nil (cons y (repeat (1- x) y)))) (defun read-ints () (mapcar #'parse-integer (split-by-one-space (read-line)))) (defun zip-with-3 (xs ys zs f) (if (or (null xs) (null ys) (null zs)) nil (cons (funcall f (car xs) (car ys) (car zs)) (zip-with-3 (cdr xs) (cdr ys) (cdr zs) f)))) (defun iota (n m) (labels ((f (k) (if (> k m) nil (cons k (f (1+ k)))))) (f n)) ) (let ((n (parse-integer (read-line))) (m (parse-integer (read-line))) (as (read-ints))) (labels ((f (time ps) (if (< time m) (let ((bs (read-ints)) (target (nth time as))) (labels ((g (x y z) (if (= x target) (+ z 1 (length (remove-if (lambda (e) (= e target)) bs))) (+ z (if (= y target) 1 0))))) ; (print time) ; (print target) ; (print (zip-with-3 (iota 1 n) bs ps #'g)) (f (1+ time) (zip-with-3 (iota 1 n) bs ps #'g)))) ps))) (mapcar #'print (f 0 (repeat n 0))))))
3問目 (Haskell)
割と書きやすかったです.
import Control.Applicative import Control.Monad readInts :: IO [Int] readInts = map read . words <$> getLine toInts :: Char -> Int toInts c | c == 'c' = 1 | otherwise = 0 main = do [h, w] <- readInts m <- replicateM h $ do s <- getLine return $ map toInts s let f xs ys t | t > 100 = xs | otherwise = f (zipWith (zipWith g) xs ys) (map ((0:) . take (w-1)) ys) (t+1) where g x 1 = min x t g x 0 = x in mapM (putStrLn . unwords . map show) $ map (map (\x -> if x == 1001001001 then (-1) else x)) $ f (replicate h (replicate w 1001001001)) m 0
4問目
これで4番かあ.
import java.util.Scanner; import java.util.Arrays; class Main{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(), M = sc.nextInt(); int[] D = new int[1000], C = new int[1000]; for(int i=0;i<N;i++){ D[i] = sc.nextInt(); } for(int i=0;i<M;i++){ C[i] = sc.nextInt(); } int[][] dp = new int[1001][1001]; for(int i=0;i<1001;i++){ for(int j=0;j<1001;j++){ dp[i][j] = 1001001001; } } dp[0][0] = 0; for(int i=0;i<M;i++){ for(int j=0;j<=N;j++){ if(j+1 <= N){ dp[i+1][j+1] = Math.min(dp[i+1][j+1], dp[i][j] + D[j] * C[i]); } dp[i+1][j] = Math.min(dp[i+1][j], dp[i][j]); } } System.out.println(dp[M][N]); } }