結果
問題 |
No.653 E869120 and Lucky Numbers
|
ユーザー |
|
提出日時 | 2021-02-21 12:28:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 2,262 bytes |
コンパイル時間 | 1,358 ms |
コンパイル使用メモリ | 138,596 KB |
最終ジャッジ日時 | 2025-01-19 02:58:50 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <map> #include <set> #include <stack> #include <tuple> #include <deque> #include <array> #include <numeric> #include <bitset> #include <iomanip> #include <cassert> #include <chrono> #include <random> #include <limits> #include <iterator> #include <functional> #include <sstream> #include <fstream> #include <complex> #include <cstring> #include <unordered_map> #include <unordered_set> using namespace std; using ll = long long; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template<class T> inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template<class T> inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = s.length(); if(n == 1 || (s.back() != '2' && s.back() != '3' && s.back() != '4')){ cout << "No\n"; return 0; } reverse(begin(s), end(s)); vector<vector<vector<bool>>> dp(n + 1, vector<vector<bool>>(2, vector<bool>(2))); dp[1][1][0] = true; for(int i = 1; i < n; ++i){ int num = s[i] - '0'; for(int j = 0; j < 2; ++j){ if(dp[i][j][0]){ for(int x = 6; x <= 7; ++x){ for(int y = 6; y <= 7; ++y){ if((x + y + j) % 10 == num){ dp[i + 1][(x + y + j) / 10][0] = true; } } if((x + j) % 10 == num){ dp[i + 1][(x + j) / 10][1] = true; } } } if(dp[i][j][1]){ for(int x = 6; x <= 7; ++x){ if((x + j) % 10 == num){ dp[i + 1][(x + j) / 10][1] = true; } } } } } if(s.back() == '1') cout << ((dp[n - 1][1][0] || dp[n - 1][1][1]) ? "Yes\n" : "No\n"); else cout << ((dp[n][0][0] || dp[n][0][1]) ? "Yes\n" : "No\n"); return 0; }