結果
問題 | No.653 E869120 and Lucky Numbers |
ユーザー |
|
提出日時 | 2020-08-18 11:14:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 1,189 bytes |
コンパイル時間 | 1,266 ms |
コンパイル使用メモリ | 85,128 KB |
最終ジャッジ日時 | 2025-01-13 02:57:37 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>#include <string>template <class T>std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }std::vector<std::vector<int>> xss{{0}, {6, 7}, {12, 13, 14}};void solve() {std::string n;std::cin >> n;std::reverse(n.begin(), n.end());// carry, remainauto dp = vec(2, vec(3, false));dp[0][2] = true;for (char cc : n) {int d = cc - '0';auto ndp = vec(2, vec(3, false));for (int c = 0; c <= 1; ++c) {for (int t = 0; t <= 2; ++t) {if (!dp[c][t]) continue;for (auto x : xss[t]) {int s = x + c;if (s % 10 != d) continue;ndp[s / 10][t] = true;}}}std::swap(dp, ndp);for (int c = 0; c <= 1; ++c) {for (int t = 1; t >= 0; --t) {if (dp[c][t + 1]) dp[c][t] = true;}}}std::cout << (dp[0][0] ? "Yes" : "No") << "\n";}int main() {std::cin.tie(nullptr);std::ios::sync_with_stdio(false);solve();return 0;}