# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90263 | Aydarov03 | Beautiful row (IZhO12_beauty) | C++14 | 2 ms | 860 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 <stdio.h>
#include <map>
using namespace std;
int a[30];
long long dp[ (1 << 20) ][30];
bool can[30][30];
map<int,int> bin;
map<int,int> ter;
main()
{
int n;
scanf("%d" , &n);
for(int i = 0; i < n; i++)
{
scanf("%d" , &a[i]);
int b = a[i] , t = a[i];
while( b > 0 )
{
bin[ a[i] ] += ( b % 2 == 1);
b /= 2;
}
while( t > 0 )
{
ter[ a[i] ] += ( t % 3 == 1);
t /= 3;
}
}
for(int i = 0; i < n; i++)
{
for(int j = i + 1; j < n; j++)
{
if( bin[a[i]] == bin[a[j]] || ter[a[i]] == ter[a[j]] )
{
can[i][j] = can[j][i] = 1;
}
}
}
for(int j = 0; j < n; j++)
dp[1 << j][j] = 1;
for(int mask = 1; mask < ( 1 << n ); mask++)
{
for(int last = 0; last < n; last++)
{
if( (mask & (1 << last) ) == 0 )continue;
for(int nxt = 0; nxt < n; nxt++)
{
if( mask & ( 1 << (nxt) ) || can[last][nxt] == 0)continue;
dp[ mask + (1 << nxt)][nxt] += dp[ mask ][last];
}
}
}
long long ans = 0;
for(int i = 0; i < n; i++)
{
ans += dp[ (1 << n) - 1 ][i];
}
printf("%lld" , ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |