結果

問題 No.1231 Make a Multiple of Ten
ユーザー SAAD AHMAD
提出日時 2022-08-01 04:49:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 815 bytes
コンパイル時間 1,179 ms
コンパイル使用メモリ 97,912 KB
実行使用メモリ 18,048 KB
最終ジャッジ日時 2024-07-21 12:21:07
合計ジャッジ時間 2,226 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

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