結果

問題 No.1231 Make a Multiple of Ten
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-10-01 11:04:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 664 bytes
コンパイル時間 1,480 ms
コンパイル使用メモリ 166,680 KB
実行使用メモリ 11,628 KB
最終ジャッジ日時 2023-09-21 06:47:29
合計ジャッジ時間 4,245 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 42 ms
7,564 KB
testcase_05 AC 37 ms
7,484 KB
testcase_06 AC 16 ms
4,776 KB
testcase_07 AC 44 ms
7,388 KB
testcase_08 AC 17 ms
7,384 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 39 ms
7,540 KB
testcase_11 AC 47 ms
7,420 KB
testcase_12 AC 84 ms
11,096 KB
testcase_13 AC 89 ms
11,520 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 88 ms
11,628 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