結果

問題 No.1231 Make a Multiple of Ten
ユーザー tentententen
提出日時 2020-09-24 22:05:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 885 ms / 2,000 ms
コード長 638 bytes
コンパイル時間 2,916 ms
コンパイル使用メモリ 71,292 KB
実行使用メモリ 83,272 KB
最終ジャッジ日時 2023-09-10 13:59:40
合計ジャッジ時間 10,810 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
53,824 KB
testcase_01 AC 123 ms
55,656 KB
testcase_02 AC 125 ms
56,152 KB
testcase_03 AC 124 ms
56,064 KB
testcase_04 AC 578 ms
66,096 KB
testcase_05 AC 594 ms
66,416 KB
testcase_06 AC 407 ms
62,292 KB
testcase_07 AC 666 ms
68,380 KB
testcase_08 AC 431 ms
63,864 KB
testcase_09 AC 332 ms
60,320 KB
testcase_10 AC 635 ms
66,852 KB
testcase_11 AC 623 ms
68,904 KB
testcase_12 AC 786 ms
80,152 KB
testcase_13 AC 877 ms
82,340 KB
testcase_14 AC 126 ms
53,932 KB
testcase_15 AC 885 ms
83,272 KB
権限があれば一括ダウンロードができます

ソースコード

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