# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
89276 | Badral | Beautiful row (IZhO12_beauty) | C++17 | 1113 ms | 165124 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[55], n, b[55][55];
ll gurav(ll x) {ll s = 0; while (x) {s += (x % 3 == 1); x /= 3; } return s; }
ll hoyr(ll x) {ll s = 0; while (x) {s += (x % 2 == 1); x /= 2; } return s; }
ll c[1 << 20][20], ans;
int main() {
ll n;
cin >>n;
for(ll i = 0; i < n; i++) {
ll x;
cin >>x;
a[i] = x;
c[1 << i][i]++;
}
for(ll i = 0; i < n; i++)
for(ll j = 0; j < n; j++)
if(gurav(a[i]) == gurav(a[j]) || hoyr(a[i]) == hoyr(a[j]))
b[i][j] = 1;
for(ll i = 1; i < (1 << n); i++)
for(ll j = 0; j < n; j++) {
if((i >> j) & 1 ^ 1) continue;
for(ll k = 0; k < n; k++)
if(((i >> k) & 1 ^ 1) && b[j][k])
c[i | (1 << k)][k] += c[i][j];
}
for(ll i = 0; i < n; i++) ans += c[(1 << n) - 1][i];
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |