結果

問題 No.1231 Make a Multiple of Ten
ユーザー poohbearpoohbear
提出日時 2020-09-18 21:47:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 880 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 196,152 KB
最終ジャッジ日時 2025-01-14 16:55:33
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

ll dp[200020][10];

int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
        a[i]%=10;
    }
    rep(i,200020)rep(j,10)dp[i][j]=-1;
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        rep(j,10){
            chmax(dp[i][j],dp[i-1][j]);
            if(dp[i-1][(j+10-a[i-1])%10]==-1)continue;
            chmax(dp[i][j],dp[i-1][(j+10-a[i-1])%10]+1);
        }
    }
    cout << dp[n][0] << endl;

    return 0;
}
0