fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #ifdef LOCAL
  6. #include "algo/debug.h"
  7. #else
  8. #define debug(...) 42
  9. #endif
  10.  
  11. int main() {
  12. ios::sync_with_stdio(false);
  13. cin.tie(nullptr);
  14. int tt;
  15. cin >> tt;
  16. while (tt--) {
  17. string s;
  18. cin >> s;
  19. vector<bool> dp(9);
  20. dp[0] = true;
  21. for (char c : s) {
  22. vector<bool> new_dp(9);
  23. for (int x = 0; x < 9; x++) {
  24. if (dp[x]) {
  25. int d = int(c - '0');
  26. while (d <= 9) {
  27. new_dp[(x + d) % 9] = true;
  28. if (d <= 1) {
  29. break;
  30. }
  31. d = d * d;
  32. }
  33. }
  34. }
  35. for(int i: new_dp){
  36. cout << i << " ";
  37. }cout << endl;
  38. swap(dp, new_dp);
  39. }
  40. cout << (dp[0] ? "YES" : "NO") << '\n';
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5280KB
stdin
1
123

stdout
0 1 0 0 0 0 0 0 0 
0 0 0 1 0 1 0 0 0 
0 0 0 1 0 1 1 0 1 
NO