結果

問題 No.1231 Make a Multiple of Ten
ユーザー misora192misora192
提出日時 2020-11-06 21:16:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 1,416 ms
コンパイル使用メモリ 168,880 KB
実行使用メモリ 17,820 KB
最終ジャッジ日時 2023-09-29 18:00:36
合計ジャッジ時間 2,767 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,376 KB
testcase_04 AC 24 ms
9,812 KB
testcase_05 AC 21 ms
9,040 KB
testcase_06 AC 10 ms
5,316 KB
testcase_07 AC 24 ms
10,128 KB
testcase_08 AC 12 ms
7,236 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 22 ms
9,268 KB
testcase_11 AC 26 ms
10,588 KB
testcase_12 AC 48 ms
17,220 KB
testcase_13 AC 50 ms
17,720 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 51 ms
17,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	vector<int> a(n);
	rep(i, n){
		cin >> a[i];
		a[i] %= 10;
	}

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

	cout << dp[n][0] << endl;
}
0