結果

問題 No.1231 Make a Multiple of Ten
ユーザー tentententen
提出日時 2022-08-04 16:28:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,262 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 75,024 KB
実行使用メモリ 76,624 KB
最終ジャッジ日時 2023-10-12 14:14:34
合計ジャッジ時間 7,469 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,560 KB
testcase_01 AC 41 ms
49,336 KB
testcase_02 AC 42 ms
49,088 KB
testcase_03 AC 43 ms
49,236 KB
testcase_04 AC 222 ms
63,252 KB
testcase_05 AC 228 ms
63,148 KB
testcase_06 AC 152 ms
57,496 KB
testcase_07 AC 225 ms
63,200 KB
testcase_08 AC 166 ms
58,580 KB
testcase_09 AC 125 ms
55,068 KB
testcase_10 AC 222 ms
63,284 KB
testcase_11 AC 238 ms
63,424 KB
testcase_12 AC 314 ms
76,624 KB
testcase_13 AC 313 ms
76,232 KB
testcase_14 AC 43 ms
49,264 KB
testcase_15 AC 319 ms
75,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[][] dp = new int[n + 1][10];
        Arrays.fill(dp[0], Integer.MIN_VALUE);
        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] = Math.max(dp[i - 1][j], dp[i - 1][(j + 10 - x) % 10] + 1);
            }
        }
        System.out.println(dp[n][0]);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0