結果

問題 No.1231 Make a Multiple of Ten
ユーザー tentententen
提出日時 2020-09-24 22:05:45
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,005 ms / 2,000 ms
コード長 638 bytes
コンパイル時間 2,079 ms
コンパイル使用メモリ 75,248 KB
実行使用メモリ 70,424 KB
最終ジャッジ日時 2024-06-28 05:26:51
合計ジャッジ時間 11,531 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int[][] dp = new int[n + 1][10];
    	Arrays.fill(dp[0], -1);
    	dp[0][0] = 0;
    	for (int i = 1; i <= n; i++) {
    	    int x = sc.nextInt() % 10;
    	    for (int j = 0; j < 10; j++) {
    	        dp[i][j] = dp[i - 1][j];
    	    }
    	    for (int j = 0; j < 10; j++) {
    	        if (dp[i - 1][j] >= 0) {
    	            dp[i][(j + x) % 10] = Math.max(dp[i][(j + x) % 10], dp[i - 1][j] + 1);
    	        }
    	    }
    	}
    	System.out.println(dp[n][0]);
	}
}
0