Guest User

Untitled

a guest
May 12th, 2016
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.06 KB | None | 0 0
  1. // Smile please :)
  2.  
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <cassert>
  9. #include <cctype>
  10. #include <sstream>
  11. #include <iostream>
  12. #include <algorithm>
  13. #include <string>
  14. #include <iomanip>
  15. #include <numeric>
  16. #include <vector>
  17. #include <queue>
  18. #include <stack>
  19. #include <deque>
  20. #include <set>
  21. #include <map>
  22. #include <list>
  23. #include <bitset>
  24. #include <climits>
  25. #include <unordered_map>
  26. #include <unordered_set>
  27. using namespace std;
  28.  
  29. //#undef KVARK_DEBUG
  30.  
  31. #ifdef KVARK
  32. #define dbg(x) cout << #x << " = " << (x) << endl;
  33. #define dbg2(a, b) cout << #a << " = " << (a) << "; " \
  34.                         << #b << " = " << (b) << endl;
  35. #define dbg3(a, b, c) cout << #a << " = " << (a) << "; " \
  36.                            << #b << " = " << (b) << "; " \
  37.                            << #c << " = " << (c) << endl;
  38. #define dbg4(a, b, c, d) cout << #a << " = " << (a) << "; " \
  39.                               << #b << " = " << (b) << "; " \
  40.                               << #c << " = " << (c) << "; " \
  41.                               << #d << " = " << (d) << endl;
  42. #define dbg5(a, b, c, d, e) cout << #a << " = " << (a) << "; " \
  43.                                  << #b << " = " << (b) << "; " \
  44.                                  << #c << " = " << (c) << "; " \
  45.                                  << #d << " = " << (d) << "; " \
  46.                                  << #e << " = " << (e) << endl;
  47. #define dbgp(a) cout << #a << " = {" << (a).first << ", " << (a).second << "}" << endl;
  48. #else
  49. #define dbg(...) (void(1));
  50. #define dbg2(...) (void(1));
  51. #define dbg3(...) (void(1));
  52. #define dbg4(...) (void(1));
  53. #define dbg5(...) (void(1));
  54. #define dbgp(...) (void(1));
  55. #endif
  56.  
  57. typedef pair<int, int> pii;
  58. typedef pair<long long, long long> pll;
  59. typedef pair<double, int> pdi;
  60. typedef vector<int> vi;
  61. typedef vector<pii> vpii;
  62. typedef vector<pll> vpll;
  63. typedef vector<vector<int> > vvi;
  64. typedef vector<vector<pii> > vvpii;
  65. typedef vector<vector<long long> > vvl;
  66. typedef vector<long long> vl;
  67. typedef long long int llint;
  68. #define ALL(v) (v.begin()), (v.end())
  69. #define SZ(v) ((int)((v).size()))
  70. #define endl "\n"
  71. class LCMGCD {
  72. public:
  73.     string isPossible(vector <int> x, int t);
  74. };
  75.  
  76. const int INF = 0x3f3f3f3f;
  77. const int N = 3e5+10;
  78. const int M = 3e5+10;
  79.  
  80.  
  81.  
  82. string LCMGCD::isPossible(vector <int> x, int t) {
  83.     srand(time(0));
  84.     auto s = clock();
  85.     vpii v;
  86.    
  87.     while ((double)( clock() - s) / CLOCKS_PER_SEC < 1.5) {
  88.         random_shuffle(ALL(x));
  89.         set<llint> st[2];
  90.         st[1].insert(x[0]);
  91.         for (int i = 1; i < x.size(); ++i) {
  92.             int cur = i % 2;
  93.             int next = (i + 1) % 2;
  94.             st[next].clear();
  95.             for (llint p: st[cur]) {
  96.                 if ((double)( clock() - s) / CLOCKS_PER_SEC > 1.8)
  97.                     return "Impossible";
  98.                 st[next].insert(__gcd((llint)x[i], p));
  99.                 if ((double)( clock() - s) / CLOCKS_PER_SEC > 1.8)
  100.                     return "Impossible";
  101.                 st[next].insert(x[i] / __gcd((llint)x[i], p) * p);
  102.                 if ((double)( clock() - s) / CLOCKS_PER_SEC > 1.8)
  103.                     return "Impossible";
  104.             }
  105.         }
  106.         int last = x.size() % 2;
  107.         if (st[last].count(t))
  108.             return "Possible";
  109.     }  
  110.     return "Impossible";
  111. }
  112.  
  113. <%:testing-code%>
  114. //Powered by KawigiEdit-pf 2.3.0!
Advertisement
Add Comment
Please, Sign In to add comment