KarleFKremen

SIS-E40

Apr 20th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. // settings
  4.     #define FILE "modern-art"
  5.     #define USE_FREOPEN 1
  6.     #define USE_LONG 0
  7.     #define USE_IOSOPT 0
  8.  
  9. // system
  10.     #if USE_LONG
  11.         typedef long long ll;
  12.     #else
  13.         typedef int ll;
  14.     #endif
  15.     #if USE_LONG
  16.         typedef unsigned long long ull;
  17.     #else
  18.         typedef unsigned int ull;
  19.     #endif
  20.     typedef short sym;
  21.     #define pb push_back
  22.     #define mp make_pair
  23.     #define p(a, b) pair < a, b >
  24.     #define sq(x) (x * x)
  25.     #define fi first
  26.     #define se second
  27.     #define rm erase
  28.     #define ins insert
  29.     #define rev(a) reverse(a.begin(), a.end())
  30.     #define rs resize
  31.     #define sz size
  32.     #define stlprint(a) \
  33.         for(auto __LEVEL_1_STL_ITERATOR = a.begin(); __LEVEL_1_STL_ITERATOR != a.end(); __LEVEL_1_STL_ITERATOR++) \
  34.         { \
  35.             cout << (*__LEVEL_1_STL_ITERATOR) << ' '; \
  36.         }
  37.     #define stlfor(a) for(auto it = a.begin(); it != a.end(); it++)
  38.  
  39. using namespace std;
  40.  
  41. ll n, k, ans;
  42. vector < ll > a;
  43.  
  44. map < ll, bool > us;
  45.  
  46. void rec(const ll &msk = 0, const ll &cmul = 1)
  47. {
  48.     if(us[msk])
  49.         return;
  50.     us[msk] = 1;
  51.     // cout << msk << endl;
  52.     ans = max((cmul % k), ans);
  53.     // if(ans >= (k - 1))
  54.     //  return;
  55.     for(int i = 0; i < n; i++)
  56.     {
  57.         if(((msk >> i) & 1))
  58.             continue;
  59.         rec((msk | (1 << i)), (cmul % k) * (a[i] % k));
  60.     }
  61.     return;
  62. }
  63.  
  64. int main()
  65. {
  66.     // ios{
  67.         #if USE_IOSOPT
  68.             ios_base::sync_with_stdio(false);
  69.             cin.tie(0);
  70.         #endif
  71.         #if USE_FREOPEN
  72.             freopen(FILE".in", "r", stdin);
  73.             freopen(FILE".out", "w", stdout);
  74.         #endif
  75.     cin >> n >> k;
  76.     for(int i = 0; i < n; i++)
  77.     {
  78.         ll d;
  79.         cin >> d;
  80.         a.pb(d);
  81.     }
  82.     rec();
  83.     cout << ans;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment