結果

問題 No.1231 Make a Multiple of Ten
ユーザー naribownaribow
提出日時 2020-09-24 23:27:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 2,842 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 205,104 KB
実行使用メモリ 27,268 KB
最終ジャッジ日時 2023-09-10 14:10:05
合計ジャッジ時間 4,195 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 49 ms
14,184 KB
testcase_05 AC 43 ms
12,800 KB
testcase_06 AC 18 ms
6,720 KB
testcase_07 AC 52 ms
14,900 KB
testcase_08 AC 20 ms
9,772 KB
testcase_09 AC 12 ms
5,532 KB
testcase_10 AC 45 ms
13,292 KB
testcase_11 AC 55 ms
15,412 KB
testcase_12 AC 98 ms
25,992 KB
testcase_13 AC 104 ms
27,244 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 104 ms
27,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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; }

template <int mod>
struct ModInt {
    int val;
    ModInt() : val(0) {}
    ModInt(long long x) : val(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    int getmod() { return mod; }
    ModInt &operator+=(const ModInt &p) {
        if ((val += p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((val += mod - p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        val = (int)(1LL * val * p.val % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-val); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return val == p.val; }
    bool operator!=(const ModInt &p) const { return val != p.val; }
    ModInt inverse() const {
        int a = val, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(long long n) const {
        ModInt ret(1), mul(val);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.val; }
    friend istream &operator>>(istream &is, ModInt &a) {
        long long t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
    static int get_mod() { return mod; }
};
const int MOD = 10;  // if inv is needed, this shold be prime.
using modint = ModInt<MOD>;

int main(){
    int n;
    modint count = 0;
    cin >> n;
    vector<int> a(n);
    vector<vector<ll> > dp(n+1, vector<ll> (10, -1*INF));
    rep(i, n) {
        cin >> a[i];
        a[i] %= 10;
    }
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, 10) {
            dp[i+1][j] = max(dp[i][j], dp[i][(j-a[i]+100)%10] + 1);
        }
    }
    cout << dp[n][0] << endl;
}
0