# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
524432 | EliteCallsYou | Beautiful row (IZhO12_beauty) | C++17 | 3067 ms | 296 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 read(a)/**/for(int i=0;i<int(sizeof(a)/sizeof(a[0]));i++){cin>>a[i];}
# define print(x)/**/for(auto zx:x){cout<<zx<<' ';}
const char* tochar(string a){return a.c_str();}
void files(){freopen("mootube.in","r",stdin);freopen("mootube.out","w",stdout);}
void speed(){ios_base::sync_with_stdio(false);cin.tie(0);}
int gcd(int a,int b){if(!b){return a;}a%=b;return gcd(b,a);}
int lcm(int a,int b){return a /gcd(a,b) * b;}
//###########################################################################
const int N = 2501 ;
const int MOD = 1e9+7 ;
//###########################################################################
void hack(){}
//###########################################################################
int ans, n, ar[21] ;
bool used[21] ;
void rec ( int pos, int last ){
if ( pos == n ){
ans ++ ;
return ;
}
for ( int i = 0 ; i < n ; i ++ ){
if ( used[i] ){continue;}
if ( last == -1 ){
used[i] = true ;
rec(pos+1,ar[i]) ;
used[i] = false ;
}
else{
int a = 0, b = 0 ;
int cur_a = ar[i], cur_b = last ;
while ( true ){
if ( !cur_a && !cur_b ){
break ;
}
if ( cur_a ){
if ( cur_a % 2 == 1 ){
a ++ ;
}
cur_a /= 2 ;
}
if ( cur_b ){
if ( cur_b % 2 == 1 ){
b ++ ;
}
cur_b /= 2 ;
}
}
if ( a == b ){
used[i] = true ;
rec(pos+1,ar[i]) ;
used[i] = false ;
continue ;
}
///////////////////////
a = b = 0 ;
cur_a = ar[i], cur_b = last ;
while ( true ){
if ( !cur_a && !cur_b ){
break ;
}
if ( cur_a ){
if ( cur_a % 3 == 1 ){
a ++ ;
}
cur_a /= 3 ;
}
if ( cur_b ){
if ( cur_b % 3 == 1 ){
b ++ ;
}
cur_b /= 3 ;
}
}
if ( a == b ){
used[i] = true ;
rec(pos+1,ar[i]) ;
used[i] = false ;
}
///////////////////////
}
}
}
int main(){
cin >> n ;
for ( int i = 0 ; i < n ; i ++ ){
cin >> ar[i] ;
}
rec(0,-1) ;
cout << ans << '\n' ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |