Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // settings
- #define FILE "modern-art"
- #define USE_FREOPEN 1
- #define USE_LONG 0
- #define USE_IOSOPT 0
- // system
- #if USE_LONG
- typedef long long ll;
- #else
- typedef int ll;
- #endif
- #if USE_LONG
- typedef unsigned long long ull;
- #else
- typedef unsigned int ull;
- #endif
- typedef short sym;
- #define pb push_back
- #define mp make_pair
- #define p(a, b) pair < a, b >
- #define sq(x) (x * x)
- #define fi first
- #define se second
- #define rm erase
- #define ins insert
- #define rev(a) reverse(a.begin(), a.end())
- #define rs resize
- #define sz size
- #define stlprint(a) \
- for(auto __LEVEL_1_STL_ITERATOR = a.begin(); __LEVEL_1_STL_ITERATOR != a.end(); __LEVEL_1_STL_ITERATOR++) \
- { \
- cout << (*__LEVEL_1_STL_ITERATOR) << ' '; \
- }
- #define stlfor(a) for(auto it = a.begin(); it != a.end(); it++)
- using namespace std;
- ll n, k, ans;
- vector < ll > a;
- map < ll, bool > us;
- void rec(const ll &msk = 0, const ll &cmul = 1)
- {
- if(us[msk])
- return;
- us[msk] = 1;
- // cout << msk << endl;
- ans = max((cmul % k), ans);
- // if(ans >= (k - 1))
- // return;
- for(int i = 0; i < n; i++)
- {
- if(((msk >> i) & 1))
- continue;
- rec((msk | (1 << i)), (cmul % k) * (a[i] % k));
- }
- return;
- }
- int main()
- {
- // ios{
- #if USE_IOSOPT
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- #endif
- #if USE_FREOPEN
- freopen(FILE".in", "r", stdin);
- freopen(FILE".out", "w", stdout);
- #endif
- cin >> n >> k;
- for(int i = 0; i < n; i++)
- {
- ll d;
- cin >> d;
- a.pb(d);
- }
- rec();
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment