# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1111843 | Tsagana | Beautiful row (IZhO12_beauty) | C++14 | 1250 ms | 205640 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>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
int l[25];
int s[25][5];
int dp[2000000][25];
int to2(int x) {
int ans = 0;
while (x) {if (x%2 == 1) ans++; x /= 2;}
return ans;
}
int to3(int x) {
int ans = 0;
while (x) {if (x%3 == 1) ans++; x /= 3;}
return ans;
}
void solve () {
l[0] = 1; for (int i = 1; i <= 20; i++) l[i] = l[i-1]*2;
int n; cin >> n;
for (int i = 0; i < n; i++) {
int x; cin >> x;
s[i][2] = to2(x);
s[i][3] = to3(x);
}
for (int i = 0; i < n; i++) dp[l[i]][i] = 1;
for (int i = 0; i < l[n]; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++) {
if (i & l[k]) continue ;
if (s[j][2] == s[k][2] || s[j][3] == s[k][3]) {
dp[i|l[k]][k] += dp[i][j];
}
}
int ans = 0;
for (int i = 0; i < n; i++) ans += dp[l[n]-1][i];
cout << ans;
}
signed main() {IOS solve(); return 0;}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |