# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
894624 | Andrey | Beautiful row (IZhO12_beauty) | C++14 | 767 ms | 164540 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;
long long dp[(1 << 20)][20];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,a;
cin >> n;
vector<int> haha(n);
for(int i = 0; i < n; i++) {
cin >> haha[i];
}
vector<int> br2(n);
vector<int> br3(n);
for(int i = 0; i < n; i++) {
a = haha[i];
while(a > 0) {
br2[i]+=a%2;
a/=2;
}
a = haha[i];
while(a > 0) {
if(a%3 == 1) {
br3[i]+=1;
}
a/=3;
}
}
long long ans = 0;
for(int i = 1; i < (1 << n); i++) {
for(int j = 0; j < n; j++) {
if((1 << j)&i) {
int c = i-(1 << j);
dp[i][j] = 0;
if(c == 0) {
dp[i][j] = 1;
}
else {
for(int k = 0; k < n; k++) {
if(((1 << k)&c) && (br2[k] == br2[j] || br3[k] == br3[j])) {
if(dp[c][k] != -1) {
dp[i][j]+=dp[c][k];
}
}
}
}
}
else {
dp[i][j] = 0;
}
}
}
for(int i = 0; i < n; i++) {
ans+=dp[(1 << n)-1][i];
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |