結果

問題 No.1231 Make a Multiple of Ten
ユーザー koi_kotyakoi_kotya
提出日時 2020-09-18 21:39:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,111 bytes
コンパイル時間 1,862 ms
コンパイル使用メモリ 170,168 KB
実行使用メモリ 17,896 KB
最終ジャッジ日時 2023-09-05 18:11:36
合計ジャッジ時間 3,094 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 47 ms
10,180 KB
testcase_05 AC 41 ms
8,808 KB
testcase_06 AC 18 ms
5,556 KB
testcase_07 AC 49 ms
10,400 KB
testcase_08 AC 19 ms
7,280 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 43 ms
9,332 KB
testcase_11 AC 51 ms
10,624 KB
testcase_12 AC 94 ms
17,284 KB
testcase_13 AC 99 ms
17,896 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 99 ms
17,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) a[i] %= 10;
    int sum = 0;
    for (int i = 0;i < n;++i) sum += a[i];
    sum %= 10;
    vector<vector<int>> dp(n+1,vector<int>(10,1e9));
    dp[0][0] = 0;
    for (int i = 0;i < n;++i) {
        dp[i+1] = dp[i];
        for (int j = 0;j < 10;++j) dp[i+1][(j+a[i])%10] = min(dp[i+1][(j+a[i])%10],dp[i][j]+1);
    }
    cout << n-dp[n][sum] << newl;
}
0