結果

問題 No.1231 Make a Multiple of Ten
ユーザー mmn15277198mmn15277198
提出日時 2020-09-27 18:55:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 95,460 KB
実行使用メモリ 17,976 KB
最終ジャッジ日時 2023-09-13 02:11:31
合計ジャッジ時間 2,317 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 25 ms
9,840 KB
testcase_05 AC 22 ms
9,060 KB
testcase_06 AC 10 ms
5,412 KB
testcase_07 AC 25 ms
10,040 KB
testcase_08 AC 13 ms
7,264 KB
testcase_09 AC 7 ms
4,388 KB
testcase_10 AC 23 ms
9,380 KB
testcase_11 AC 28 ms
10,816 KB
testcase_12 AC 50 ms
17,176 KB
testcase_13 AC 51 ms
17,780 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 51 ms
17,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;

ll mod = 1e9 + 7;

int main(){	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		ll x;
		cin >> x;
		a[i] = x % 10;
	}
	
	vector<vector<int>> dp(n , vector<int> (10 , -1));
	
	dp[0][0] = 0;
	dp[0][a[0]] = 1;
	
	for(int i = 1; i < n; i++){
		for(int j = 0; j < 10; j++){
			dp[i][j] = dp[i - 1][j];
		}
		for(int j = 0; j < 10; j++){
			if(dp[i - 1][j] == -1)continue;
			dp[i][(a[i] + j) % 10] = max(dp[i][(a[i] + j) % 10] , dp[i - 1][j] + 1);
		}
	}
	cout << dp[n - 1][0] << endl;
	return 0;
}
 
0