結果

問題 No.1231 Make a Multiple of Ten
ユーザー SAAD AHMADSAAD AHMAD
提出日時 2022-08-01 04:49:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 815 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 94,876 KB
実行使用メモリ 17,968 KB
最終ジャッジ日時 2023-09-28 17:41:49
合計ジャッジ時間 2,285 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 26 ms
9,912 KB
testcase_05 AC 22 ms
9,196 KB
testcase_06 AC 10 ms
5,352 KB
testcase_07 AC 27 ms
10,244 KB
testcase_08 AC 14 ms
7,208 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 24 ms
9,452 KB
testcase_11 AC 28 ms
10,772 KB
testcase_12 AC 50 ms
17,392 KB
testcase_13 AC 53 ms
17,704 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 53 ms
17,968 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