結果

問題 No.1231 Make a Multiple of Ten
ユーザー 夜
提出日時 2020-09-18 21:43:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 90,792 KB
実行使用メモリ 12,104 KB
最終ジャッジ日時 2023-09-05 18:12:54
合計ジャッジ時間 2,233 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 39 ms
9,136 KB
testcase_05 AC 35 ms
6,996 KB
testcase_06 AC 15 ms
4,772 KB
testcase_07 AC 41 ms
9,156 KB
testcase_08 AC 16 ms
6,952 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 36 ms
7,056 KB
testcase_11 AC 44 ms
9,308 KB
testcase_12 AC 78 ms
11,696 KB
testcase_13 AC 83 ms
12,008 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 83 ms
12,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int dp[200020][10] = { 0 };
int a[200020];
int main() {
	int n;
	int co = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] %= 10;
		co += a[i];
		co %= 10;
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < 10; j++) {
			dp[i][j] = 1000000007;
		}
	}
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 10; j++) {
			dp[i][(j + a[i]) % 10] = min(dp[i - 1][(j + a[i]) % 10], dp[i - 1][j] + 1);
		}
	}
	cout << n - dp[n][co] << endl;
}
0