fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long
  4. #define out(a) copy(a.begin(),a.end(),ostream_iterator<int>(cout," "))
  5. const ll N = 88888888888888;
  6. struct node {
  7. int indx;ll sum;
  8. bool mod;
  9. bool f, p;
  10. node(int indx, ll sum, bool mod, bool f, bool p) :
  11. indx(indx), sum(sum), mod(mod), f(f), p(p) {
  12. }
  13. };
  14. class LuckySum {
  15. public:
  16. long long construct(string note) {
  17. if(note.find_first_not_of("?") == string::npos){
  18. if(note.size() == 1)return 8;
  19. ll x = 11;
  20. int st = note.size() - 2;
  21. while(st > 0){
  22. x*=10;
  23. x+=8;
  24. --st;
  25. }
  26. return x;
  27. }
  28. ll ans = 1e15;
  29. ll val[16];
  30. val[0] = 1;
  31. for (int i = 1; i <= 15; ++i)
  32. val[i] = val[i - 1] * 10;
  33. queue<node> que;
  34. que.push(node(0, 0, 0, 0, 0));
  35. while (que.size()) {
  36. node tmp = que.front();
  37. que.pop();
  38. if (tmp.sum > val[note.size()])
  39. continue;
  40. if (tmp.indx + tmp.mod == (int) note.size()) {
  41. ll x = tmp.sum;
  42. int st = note.size();
  43. while (x && st >= 0) {
  44. --st;
  45. int y = x % 10;
  46. x /= 10;
  47. if (note[st] == '?' || (note[st] - '0' == y))
  48. continue;
  49. x = tmp.sum;
  50. tmp.sum = -1;
  51. break;
  52. }
  53. if (tmp.sum != -1)
  54. ans = min(ans, tmp.sum);
  55. tmp.sum = x;
  56. }
  57. if (tmp.indx == 0) {
  58. que.push(node(tmp.indx + 1, 8, 0, 0, 0));
  59. que.push(node(tmp.indx + 1, 11, 1, 0, 0));
  60. que.push(node(tmp.indx + 1, 14, 1, 0, 0));
  61. continue;
  62. }
  63. if (!tmp.f) {
  64. que.push(
  65. node(tmp.indx + 1, tmp.sum + 4 * val[tmp.indx], 0, 0,
  66. 1));
  67. que.push(
  68. node(tmp.indx + 1, tmp.sum + 7 * val[tmp.indx], 0, 0,
  69. 1));
  70. if (!tmp.p) {
  71. que.push(
  72. node(tmp.indx + 1, tmp.sum + 8 * val[tmp.indx], 0,
  73. 0, 0));
  74. que.push(
  75. node(tmp.indx + 1, tmp.sum + 11 * val[tmp.indx], 1,
  76. 0, 0));
  77. que.push(
  78. node(tmp.indx + 1, tmp.sum + 14 * val[tmp.indx], 1,
  79. 0, 0));
  80. }
  81. }
  82. }
  83. if (ans == 1e15)
  84. ans = -1;
  85. return ans;
  86. }
  87. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:14: warning: overflow in implicit constant conversion [-Woverflow]
 const ll N = 88888888888888;
              ^
prog.cpp: In member function 'long long int LuckySum::construct(std::string)':
prog.cpp:28:12: warning: overflow in implicit constant conversion [-Woverflow]
   ll ans = 1e15;
            ^
/usr/lib/gcc/i586-linux-gnu/5/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty