結果
問題 | No.1231 Make a Multiple of Ten |
ユーザー |
![]() |
提出日時 | 2020-11-06 21:16:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 662 bytes |
コンパイル時間 | 1,805 ms |
コンパイル使用メモリ | 171,372 KB |
実行使用メモリ | 18,084 KB |
最終ジャッジ日時 | 2024-07-22 11:59:02 |
合計ジャッジ時間 | 2,676 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#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; }