daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define x first
  6. #define y second
  7. #define mp make_pair
  8. #define pb push_back
  9. #define sqr(a) ((a) * (a))
  10. #define sz(a) int(a.size())
  11. #define all(a) a.begin(), a.end()
  12. #define forn(i, n) for(int i = 0; i < int(n); i++)
  13. #define fore(i, l, r) for(int i = int(l); i < int(r); i++)
  14.  
  15. typedef long long li;
  16. typedef long double ld;
  17. typedef pair<int, int> pt;
  18.  
  19. template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
  20.     return out << "(" << a.x << ", " << a.y << ")";
  21. }
  22.  
  23. template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
  24.     out << "[";
  25.     forn(i, sz(v)) {
  26.         if(i) out << ", ";
  27.         out << v[i];
  28.     }
  29.     return out << "]";
  30. }
  31.  
  32. mt19937 rnd(time(NULL));
  33.  
  34. const int INF = int(1e9);
  35. const li INF64 = li(1e18);
  36. const int MOD = INF + 7;
  37. const ld EPS = 1e-9;
  38. const ld PI = acos(-1.0);
  39.  
  40. li x;
  41.  
  42. bool read () {
  43.     if (!(cin >> x))
  44.         return false;
  45.     return true;
  46. }
  47.  
  48. void solve() {
  49.     vector<int> nz, d;
  50.     while (x){
  51.         if (x % 10) nz.pb(x % 10);
  52.         d.pb(x % 10);
  53.         x /= 10;
  54.     }
  55.    
  56.     int cnt = 0;
  57.     while ((cnt & 1023) || (clock() < 240)){
  58.         ++cnt;
  59.         int f = nz[rnd() % sz(nz)];
  60.         li num = f;
  61.         d.erase(find(all(d), f));
  62.         shuffle(all(d), rnd);
  63.         forn(i, sz(d))
  64.             num = num * 10 + d[i];
  65.         if (num % 17 == 0){
  66.             printf("%lld\n", num);
  67.             return;
  68.         }
  69.         d.pb(f);
  70.     }  
  71.     puts("-1");
  72. }
  73.  
  74. int main() {
  75. #ifdef _DEBUG
  76.     freopen("input.txt", "r", stdin);
  77. //  freopen("output.txt", "w", stdout);
  78.    
  79.     int tt = clock();
  80.    
  81. #endif
  82.    
  83.     cerr.precision(15);
  84.     cout.precision(15);
  85.     cerr << fixed;
  86.     cout << fixed;
  87.  
  88.     while(read()) {
  89.         solve();
  90.        
  91. #ifdef _DEBUG
  92.     cerr << "TIME = " << clock() - tt << endl;
  93.     tt = clock();
  94. #endif
  95.  
  96.     }
  97. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top