結果

問題 No.1231 Make a Multiple of Ten
ユーザー msm1993msm1993
提出日時 2020-10-06 11:42:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 664 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 166,612 KB
実行使用メモリ 11,748 KB
最終ジャッジ日時 2023-09-27 06:30:02
合計ジャッジ時間 3,774 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 42 ms
7,468 KB
testcase_05 AC 37 ms
7,472 KB
testcase_06 AC 16 ms
4,716 KB
testcase_07 AC 45 ms
7,484 KB
testcase_08 AC 17 ms
7,432 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 39 ms
7,584 KB
testcase_11 AC 46 ms
7,728 KB
testcase_12 AC 84 ms
11,032 KB
testcase_13 AC 90 ms
11,748 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 89 ms
11,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define N (1000000000+7)
//#define N (998244353)
#define INF 1e16
typedef long long ll;

int dp[200010][10];

int main(void){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i] = (a[i]%10);
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<10;j++){
            dp[i][j]=-1;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
            if(dp[i][j]!=-1)
                dp[i+1][(j+a[i])%10] = max(dp[i+1][(j+a[i])%10],dp[i][j]+1);
        }
    }
    cout<<dp[n][0]<<endl;
}
0