# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
673983 | Cutebol | Beautiful row (IZhO12_beauty) | C++17 | 2347 ms | 205512 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define Scaramouche ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
#define int long long
#define itn int
#define endl "\n"
#define ff first
#define ss second
const int N = 25 + 5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e9 ;
int n ;
int a[N] , b[N] , dp[(1<<20)+5][25] ;
int func(int x){
int res = 0 ;
while ( x ){
res += ( x % 3 == 1 ) ;
x /= 3 ;
}
return res ;
}
int rec ( int mask , int last ){
if ( __builtin_popcount(mask) == n ) return 1 ;
if ( last != -1 && dp[mask][last] != -1 ) return dp[mask][last] ;
int ans = 0 ;
for ( int i = 0 ; i < n ; i ++ ){
if ( mask&(1<<i) ) continue ;
if ( last == -1 || a[i] == a[last] || b[i] == b[last] ) ans += rec( mask|(1<<i) , i ) ;
}
return dp[mask][last] = ans ;
}
void solve(){
cin >> n ;
for ( int i = 0 ; i < n ; i ++ ){
int x ;
cin >> x ;
a[i] = __builtin_popcount(x) ;
b[i] = func(x) ;
}
memset( dp , -1 , sizeof(dp) ) ;
cout << rec( 0 , -1 ) ;
}
signed main(){
// fopn("blocks") ;
Scaramouche ;
int t = 1 ;
// cin >> t ;
while ( t -- ) solve() ;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |